|
5 | 5 | CustomerCosmosDBModel, |
6 | 6 | CustomerCosmosDBDao, |
7 | 7 | ) |
| 8 | +from time_tracker_api.project_types.project_types_model import ( |
| 9 | + ProjectTypeCosmosDBModel, |
| 10 | + ProjectTypeCosmosDBDao, |
| 11 | +) |
8 | 12 | from time_tracker_api.projects.projects_model import ( |
9 | 13 | ProjectCosmosDBRepository, |
10 | 14 | ProjectCosmosDBModel, |
11 | 15 | create_dao, |
12 | 16 | ) |
| 17 | +from faker import Faker |
| 18 | + |
| 19 | +fake = Faker() |
13 | 20 |
|
14 | 21 |
|
15 | 22 | @patch( |
@@ -77,3 +84,57 @@ def test_get_project_with_their_customer( |
77 | 84 |
|
78 | 85 | assert isinstance(project, ProjectCosmosDBModel) |
79 | 86 | assert project.__dict__['customer_name'] == customer_data['name'] |
| 87 | + |
| 88 | + |
| 89 | +def test_get_all_projects_with_customers( |
| 90 | + mocker, |
| 91 | +): |
| 92 | + customer_id = fake.uuid4() |
| 93 | + project_type_id = fake.uuid4() |
| 94 | + |
| 95 | + customer_data = { |
| 96 | + 'id': customer_id, |
| 97 | + 'name': fake.company(), |
| 98 | + 'description': fake.paragraph(), |
| 99 | + 'tenant_id': fake.uuid4(), |
| 100 | + } |
| 101 | + |
| 102 | + project_data = { |
| 103 | + 'customer_id': customer_id, |
| 104 | + 'id': fake.uuid4(), |
| 105 | + 'name': fake.company(), |
| 106 | + 'description': fake.paragraph(), |
| 107 | + 'project_type_id': project_type_id, |
| 108 | + 'tenant_id': fake.uuid4(), |
| 109 | + } |
| 110 | + |
| 111 | + project_type_dao = { |
| 112 | + 'id': project_type_id, |
| 113 | + 'name': fake.name(), |
| 114 | + 'description': fake.paragraph(), |
| 115 | + 'tenant_id': fake.uuid4(), |
| 116 | + } |
| 117 | + |
| 118 | + expected_customer = CustomerCosmosDBModel(customer_data) |
| 119 | + expected_project = ProjectCosmosDBModel(project_data) |
| 120 | + expected_project_type = ProjectTypeCosmosDBModel(project_type_dao) |
| 121 | + |
| 122 | + customer_dao_get_all_mock = mocker.patch.object( |
| 123 | + CustomerCosmosDBDao, 'get_all' |
| 124 | + ) |
| 125 | + customer_dao_get_all_mock.return_value = [expected_customer] |
| 126 | + |
| 127 | + projects_repository_find_all_mock = mocker.patch.object( |
| 128 | + ProjectCosmosDBRepository, 'find_all' |
| 129 | + ) |
| 130 | + projects_repository_find_all_mock.return_value = [expected_project] |
| 131 | + |
| 132 | + project_type_dao_get_all_mock = mocker.patch.object( |
| 133 | + ProjectTypeCosmosDBDao, 'get_all' |
| 134 | + ) |
| 135 | + project_type_dao_get_all_mock.return_value = [expected_project_type] |
| 136 | + projects = create_dao().get_all() |
| 137 | + |
| 138 | + assert isinstance(projects[0], ProjectCosmosDBModel) |
| 139 | + assert projects[0].__dict__['customer_name'] == customer_data['name'] |
| 140 | + assert len(projects) == 1 |
0 commit comments