|
1 | 1 | import pytest |
| 2 | +import json |
| 3 | +import pytest |
| 4 | +import shutil |
| 5 | +from faker import Faker |
2 | 6 |
|
3 | 7 | import time_tracker.activities._domain as domain |
4 | 8 | import time_tracker.activities._infrastructure as infrastructure |
5 | 9 | from time_tracker._infrastructure import DB |
6 | | -from faker import Faker |
| 10 | +from time_tracker.time_entries._domain import TimeEntry |
7 | 11 |
|
8 | 12 |
|
9 | | -@pytest.fixture(name='activity_factory') |
| 13 | +@pytest.fixture(name="activity_factory") |
10 | 14 | def _activity_factory() -> domain.Activity: |
11 | 15 | def _make_activity( |
12 | | - name: str = Faker().name(), description: str = Faker().sentence(), deleted: bool = False, status: int = 1 |
| 16 | + name: str = Faker().name(), |
| 17 | + description: str = Faker().sentence(), |
| 18 | + deleted: bool = False, |
| 19 | + status: int = 1, |
13 | 20 | ): |
14 | 21 | activity = domain.Activity( |
15 | | - id=None, |
16 | | - name=name, |
17 | | - description=description, |
18 | | - deleted=deleted, |
19 | | - status=status |
20 | | - ) |
| 22 | + id=None, name=name, description=description, deleted=deleted, status=status |
| 23 | + ) |
21 | 24 | return activity |
| 25 | + |
22 | 26 | return _make_activity |
23 | 27 |
|
24 | 28 |
|
25 | | -@pytest.fixture(name='create_fake_dao') |
| 29 | +@pytest.fixture(name="create_fake_dao") |
26 | 30 | def _create_fake_dao() -> domain.ActivitiesDao: |
27 | | - db_fake = DB('sqlite:///:memory:') |
| 31 | + db_fake = DB("sqlite:///:memory:") |
28 | 32 | dao = infrastructure.ActivitiesSQLDao(db_fake) |
29 | 33 | return dao |
30 | 34 |
|
31 | 35 |
|
32 | | -@pytest.fixture(name='create_fake_database') |
| 36 | +@pytest.fixture(name="create_fake_database") |
33 | 37 | def _create_fake_database() -> domain.ActivitiesDao: |
34 | | - db_fake = DB('sqlite:///:memory:') |
| 38 | + db_fake = DB("sqlite:///:memory:") |
35 | 39 | return db_fake |
| 40 | + |
| 41 | + |
| 42 | +@pytest.fixture |
| 43 | +def create_temp_activities(tmpdir_factory): |
| 44 | + temporary_directory = tmpdir_factory.mktemp("tmp") |
| 45 | + json_file = temporary_directory.join("activities.json") |
| 46 | + activities = [ |
| 47 | + { |
| 48 | + "id": "c61a4a49-3364-49a3-a7f7-0c5f2d15072b", |
| 49 | + "name": "Development", |
| 50 | + "description": "Development", |
| 51 | + "deleted": "b4327ba6-9f96-49ee-a9ac-3c1edf525172", |
| 52 | + "status": "active", |
| 53 | + "tenant_id": "cc925a5d-9644-4a4f-8d99-0bee49aadd05", |
| 54 | + }, |
| 55 | + { |
| 56 | + "id": "94ec92e2-a500-4700-a9f6-e41eb7b5507c", |
| 57 | + "name": "Management", |
| 58 | + "description": "Description of management", |
| 59 | + "deleted": "7cf6efe5-a221-4fe4-b94f-8945127a489a", |
| 60 | + "status": "active", |
| 61 | + "tenant_id": "cc925a5d-9644-4a4f-8d99-0bee49aadd05", |
| 62 | + }, |
| 63 | + { |
| 64 | + "id": "d45c770a-b1a0-4bd8-a713-22c01a23e41b", |
| 65 | + "name": "Operations", |
| 66 | + "description": "Operation activities performed.", |
| 67 | + "deleted": "7cf6efe5-a221-4fe4-b94f-8945127a489a", |
| 68 | + "status": "active", |
| 69 | + "tenant_id": "cc925a5d-9644-4a4f-8d99-0bee49aadd05", |
| 70 | + }, |
| 71 | + ] |
| 72 | + |
| 73 | + with open(json_file, "w") as outfile: |
| 74 | + json.dump(activities, outfile) |
| 75 | + |
| 76 | + yield activities, json_file |
| 77 | + shutil.rmtree(temporary_directory) |
| 78 | + |
| 79 | + |
| 80 | +@pytest.fixture |
| 81 | +def create_temp_time_entries(tmpdir_factory): |
| 82 | + temporary_directory = tmpdir_factory.mktemp("tmp") |
| 83 | + json_file = temporary_directory.join("time_entries.json") |
| 84 | + time_entries = [ |
| 85 | + { |
| 86 | + "id": Faker().random_int(), |
| 87 | + "start_date": Faker().date(), |
| 88 | + "owner_id": Faker().random_int(), |
| 89 | + "description": Faker().sentence(), |
| 90 | + "activity_id": Faker().random_int(), |
| 91 | + "uri": "http://time-tracker.com", |
| 92 | + "technologies": ["jira", "git"], |
| 93 | + "end_date": Faker().date(), |
| 94 | + "deleted": Faker().random_int(), |
| 95 | + "timezone_offset": "300", |
| 96 | + "project_id": Faker().random_int(), |
| 97 | + }, |
| 98 | + { |
| 99 | + "id": Faker().random_int(), |
| 100 | + "start_date": Faker().date(), |
| 101 | + "owner_id": Faker().random_int(), |
| 102 | + "description": Faker().sentence(), |
| 103 | + "activity_id": Faker().random_int(), |
| 104 | + "uri": "http://time-tracker.com", |
| 105 | + "technologies": ["jira", "git"], |
| 106 | + "end_date": Faker().date(), |
| 107 | + "deleted": Faker().random_int(), |
| 108 | + "timezone_offset": "300", |
| 109 | + "project_id": Faker().random_int(), |
| 110 | + }, |
| 111 | + ] |
| 112 | + |
| 113 | + with open(json_file, "w") as outfile: |
| 114 | + json.dump(time_entries, outfile) |
| 115 | + |
| 116 | + yield time_entries, json_file |
| 117 | + shutil.rmtree(temporary_directory) |
| 118 | + |
| 119 | + |
| 120 | +@pytest.fixture(name="time_entry_factory") |
| 121 | +def _time_entry_factory() -> TimeEntry: |
| 122 | + def _make_time_entry( |
| 123 | + id=Faker().random_int(), |
| 124 | + start_date=Faker().date(), |
| 125 | + owner_id=Faker().random_int(), |
| 126 | + description=Faker().sentence(), |
| 127 | + activity_id=Faker().random_int(), |
| 128 | + uri="http://time-tracker.com", |
| 129 | + technologies=["jira", "git"], |
| 130 | + end_date=Faker().date(), |
| 131 | + deleted=Faker().random_int(), |
| 132 | + timezone_offset="300", |
| 133 | + project_id=Faker().random_int(), |
| 134 | + ): |
| 135 | + time_entry = TimeEntry( |
| 136 | + id=id, |
| 137 | + start_date=start_date, |
| 138 | + owner_id=owner_id, |
| 139 | + description=description, |
| 140 | + activity_id=activity_id, |
| 141 | + uri=uri, |
| 142 | + technologies=technologies, |
| 143 | + end_date=end_date, |
| 144 | + deleted=deleted, |
| 145 | + timezone_offset=timezone_offset, |
| 146 | + project_id=project_id, |
| 147 | + ) |
| 148 | + return time_entry |
| 149 | + |
| 150 | + return _make_time_entry |
0 commit comments