Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
59 changes: 59 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import pytest
import datetime
from functions.four_bank_parser import SmsMessage, Expense, BankCard
from decimal import Decimal


@pytest.fixture
def long_string():
return ''.join('s' for n in range(100))


@pytest.fixture
def sms_text():
return '1020 руб, 4400430255123326 20.02.23 16:20 7/11 authcode 3034'


@pytest.fixture
def sms_message(sms_text):
return SmsMessage(
text=sms_text,
author="Sberbank",
sent_at=datetime.datetime(2023, 2, 20, 16, 20, 20),
)


@pytest.fixture
def bank_cards(bank_card):
return [
bank_card,
BankCard(last_digits='1815', owner='Olga N.'),
BankCard(last_digits='1855', owner='Roman G.'),
]

@pytest.fixture
def bank_card():
return BankCard(
last_digits='3326',
owner='Nikita T.',
)


@pytest.fixture
def expense(bank_card):
return Expense(
amount=Decimal('1020'),
card=bank_card,
spent_in='7/11',
spent_at=datetime.datetime(2023, 2, 20, 16, 20),
)


@pytest.fixture
def today():
return datetime.date.today()


@pytest.fixture
def yesterday(today):
return today + datetime.timedelta(days=1)
16 changes: 14 additions & 2 deletions tests/test_five_title.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
from functions.five_title import change_copy_item
import pytest


def test_change_copy_item():
pass
@pytest.mark.parametrize(
'title, max_main_item_title_length, expected_result',
[
(pytest.lazy_fixture('long_string'), 100, pytest.lazy_fixture('long_string')),
('string', 100, 'Copy of string'),
('Copy of string (2)', 100, 'Copy of string (3)'),
('Copy of string', 100,'Copy of string (2)'),
('Copy of string (2+)', 100, 'Copy of string (2+) (2)'),
('(2)', 100, 'Copy of (2)'),
]
)
def test_change_copy_item(title, max_main_item_title_length, expected_result):
assert change_copy_item(title, max_main_item_title_length) == expected_result
4 changes: 2 additions & 2 deletions tests/test_four_bank_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functions.four_bank_parser import BankCard, SmsMessage, Expense, parse_ineco_expense


def test_parse_ineco_expense():
pass
def test_parse_ineco_expense(sms_message, bank_cards, expense):
assert parse_ineco_expense(sms_message, bank_cards) == expense
12 changes: 10 additions & 2 deletions tests/test_one_gender.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from functions.one_gender import genderalize
import pytest


def test_genderalize():
pass
@pytest.mark.parametrize(
'gender, expected_result',
[
('male', 'male_verb'),
('female', 'female_verb'),
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут есть лишние параметры: первый, например, всегда одинаковый, второй тоже. Убери их из параметрайза.

И фикстуры я бы эти тоже удалил: они завязаны на этот тест и не очень универсальные, поэтому просто захардкодь слова тут и будет нормас.

)
def test_genderalize(gender, expected_result):
assert genderalize('male_verb', 'female_verb', gender) == expected_result
17 changes: 15 additions & 2 deletions tests/test_three_url_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
from functions.three_url_builder import build_url
import pytest


def test_build_url():
pass
@pytest.mark.parametrize(
'host_name, relative_url, get_params, expected_result',
[
(
'hh.ru', 'applicant/negotiations',
{'hhtmFrom': 'employer', 'hhtmFromLabel': 'header'},
'hh.ru/applicant/negotiations?hhtmFrom=employer&hhtmFromLabel=header'
),
('hh.ru', 'applicant/negotiations', {}, 'hh.ru/applicant/negotiations'),
('hh.ru', 'applicant/negotiations', None, 'hh.ru/applicant/negotiations')
]
)
def test_build_url(host_name, relative_url, get_params, expected_result):
assert build_url(host_name, relative_url, get_params) == expected_result
9 changes: 7 additions & 2 deletions tests/test_two_date_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import datetime
from functions.two_date_parser import compose_datetime_from


def test_compose_datetime_from():
pass
def test_compose_datetime_from_today(today):
assert compose_datetime_from('today', '16 : 48') == datetime.datetime(today.year, today.month, today.day, 16, 48)


def test_compose_datetime_from(yesterday):
assert compose_datetime_from('tomorrow', '16 : 48') == datetime.datetime(yesterday.year, yesterday.month, yesterday.day, 16, 48)