Skip to content

Commit

Permalink
add test to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
da-maltsev committed Jul 6, 2023
1 parent a4d32e9 commit 01449c6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
39 changes: 38 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,46 @@ jobs:
. venv/bin/activate
make lint
build-docker-image:
test:
needs: build
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13.9-alpine
env:
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
id: setup-python
with:
python-version-file: '.python-version'

- uses: actions/cache@v3
with:
path: |
venv
key: ${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/*requirements.txt') }}

- name: Run the tests
env:
DATABASE_URL: postgres://postgres@localhost:5432/postgres
run: |
. venv/bin/activate
make test
build-docker-image:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
29 changes: 13 additions & 16 deletions tests/tests_filters/test_has_no_valid_previous_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@
CHAT_ID = 1


@pytest.fixture
def user():
class FakeUser:
def __init__(self, id: int):
self.id = id

return FakeUser(4815162342)


@pytest.fixture
def create_log_message():
return lambda user_id, chat_id=CHAT_ID, action='', message_id=random.randint(1, 9999): LogEntry.create(
def create_log_message(user_id: int, chat_id: int = CHAT_ID, action: str = '', message_id: int = random.randint(1, 9999)):
return LogEntry.create(
user_id=user_id,
chat_id=chat_id,
message_id=message_id,
text='meh',
meta={
'tags': ["ou"],
},
meta={'tags': ["ou"]},
raw={'text': 'meh'},
action=action,
)


@pytest.fixture
def user():
class FakeUser:
def __init__(self, id: int):
self.id = id

return FakeUser(4815162342)


@pytest.fixture
def message(mock_message, user):
mock_message.from_user = user
Expand All @@ -44,7 +41,7 @@ def filter_obg():


@pytest.fixture
def valid_messages(user, create_log_message, filter_obg):
def valid_messages(user, filter_obg):
message_id = 1
for _ in range(filter_obg.MIN_PREVIOUS_MESSAGES_COUNT):
create_log_message(user_id=user.id, message_id=message_id)
Expand Down

0 comments on commit 01449c6

Please sign in to comment.