77from time_tracker .projects ._application import _projects as azure_projects
88from time_tracker .projects import _domain as domain
99from time_tracker .projects import _infrastructure as infrastructure
10- from time_tracker ._infrastructure import DB
1110
1211PROJECT_URL = '/api/projects/'
1312
1413
1514@pytest .fixture (name = 'insert_project' )
16- def _insert_project () -> domain .Project :
17- def _new_project (project : domain .Project , database : DB ):
18- dao = infrastructure .ProjectsSQLDao (database )
19- new_project = dao .create (project )
20- return new_project
15+ def insert_project (test_db , insert_customer , project_factory , customer_factory ) -> domain .Project :
16+ inserted_customer = insert_customer (customer_factory (), test_db )
17+
18+ def _new_project ():
19+ project_to_insert = project_factory (customer_id = inserted_customer .id )
20+ dao = infrastructure .ProjectsSQLDao (test_db )
21+ inserted_project = dao .create (project_to_insert )
22+ return inserted_project
2123 return _new_project
2224
2325
2426def test__project_azure_endpoint__returns_all_projects (
25- test_db , project_factory , insert_project , insert_customer , customer_factory
27+ insert_project
2628):
27- inserted_customer = insert_customer (customer_factory (), test_db )
28- project_to_insert = [project_factory (customer_id = inserted_customer .id ),
29- project_factory (customer_id = inserted_customer .id )]
3029 inserted_projects = [
31- insert_project (project_to_insert [ 0 ], test_db ).__dict__ ,
32- insert_project (project_to_insert [ 1 ], test_db ).__dict__
30+ insert_project ().__dict__ ,
31+ insert_project ().__dict__
3332 ]
3433
3534 req = func .HttpRequest (method = 'GET' , body = None , url = PROJECT_URL )
@@ -41,11 +40,9 @@ def test__project_azure_endpoint__returns_all_projects(
4140
4241
4342def test__project_azure_endpoint__returns_an_project__when_project_matches_its_id (
44- test_db , project_factory , insert_project , insert_customer , customer_factory
43+ insert_project
4544):
46- inserted_customer = insert_customer (customer_factory (), test_db )
47- project_to_insert = project_factory (customer_id = inserted_customer .id )
48- inserted_project = insert_project (project_to_insert , test_db ).__dict__
45+ inserted_project = insert_project ().__dict__
4946
5047 req = func .HttpRequest (
5148 method = 'GET' ,
@@ -77,11 +74,9 @@ def test__projects_azure_endpoint__returns_a_status_code_400__when_project_reciv
7774
7875
7976def test__project_azure_endpoint__returns_an_project_with_inactive_status__when_an_project_matching_its_id_is_found (
80- test_db , project_factory , insert_project , insert_customer , customer_factory
77+ insert_project
8178):
82- inserted_customer = insert_customer (customer_factory (), test_db )
83- project_to_insert = project_factory (customer_id = inserted_customer .id )
84- inserted_project = insert_project (project_to_insert , test_db ).__dict__
79+ inserted_project = insert_project ().__dict__
8580
8681 req = func .HttpRequest (
8782 method = 'DELETE' ,
@@ -114,11 +109,9 @@ def test__delete_projects_azure_endpoint__returns_a_status_code_400__when_projec
114109
115110
116111def test__update_project_azure_endpoint__returns_an_project__when_found_an_project_to_update (
117- test_db , project_factory , insert_project , insert_customer , customer_factory
112+ insert_project
118113):
119- inserted_customer = insert_customer (customer_factory (), test_db )
120- project_to_insert = project_factory (customer_id = inserted_customer .id )
121- inserted_project = insert_project (project_to_insert , test_db ).__dict__
114+ inserted_project = insert_project ().__dict__
122115
123116 project_body = {"description" : Faker ().sentence ()}
124117 req = func .HttpRequest (
0 commit comments