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