Skip to content

Commit a01799e

Browse files
committed
[DOP-23867] Implement model -> json converter for tests
1 parent 7fa0d2d commit a01799e

22 files changed

+843
-5710
lines changed

tests/test_server/test_datasets/test_get_datasets.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from data_rentgen.db.models import Dataset
88
from tests.fixtures.mocks import MockedUser
9+
from tests.test_server.utils.convert_to_json import datasets_to_json
910
from tests.test_server.utils.enrich import enrich_datasets
1011

1112
pytestmark = [pytest.mark.server, pytest.mark.asyncio]
@@ -35,22 +36,7 @@ async def test_get_datasets_no_filters(
3536
"next_page": None,
3637
"previous_page": None,
3738
},
38-
"items": [
39-
{
40-
"kind": "DATASET",
41-
"id": dataset.id,
42-
"format": dataset.format,
43-
"name": dataset.name,
44-
"location": {
45-
"id": dataset.location.id,
46-
"name": dataset.location.name,
47-
"type": dataset.location.type,
48-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
49-
"external_id": dataset.location.external_id,
50-
},
51-
}
52-
for dataset in sorted(datasets, key=lambda x: x.name)
53-
],
39+
"items": datasets_to_json(datasets, sort_key=lambda x: x.name),
5440
}
5541

5642

tests/test_server/test_datasets/test_get_datasets_by_id.py

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from data_rentgen.db.models import Dataset
88
from tests.fixtures.mocks import MockedUser
9+
from tests.test_server.utils.convert_to_json import datasets_to_json
910
from tests.test_server.utils.enrich import enrich_datasets
1011

1112
pytestmark = [pytest.mark.server, pytest.mark.asyncio]
@@ -65,21 +66,7 @@ async def test_get_datasets_by_one_id(
6566
"next_page": None,
6667
"previous_page": None,
6768
},
68-
"items": [
69-
{
70-
"kind": "DATASET",
71-
"id": dataset.id,
72-
"format": dataset.format,
73-
"name": dataset.name,
74-
"location": {
75-
"id": dataset.location.id,
76-
"name": dataset.location.name,
77-
"type": dataset.location.type,
78-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
79-
"external_id": dataset.location.external_id,
80-
},
81-
},
82-
],
69+
"items": datasets_to_json([dataset]),
8370
}
8471

8572

@@ -110,20 +97,5 @@ async def test_get_datasets_by_multiple_ids(
11097
"next_page": None,
11198
"previous_page": None,
11299
},
113-
"items": [
114-
{
115-
"kind": "DATASET",
116-
"id": dataset.id,
117-
"format": dataset.format,
118-
"name": dataset.name,
119-
"location": {
120-
"id": dataset.location.id,
121-
"name": dataset.location.name,
122-
"type": dataset.location.type,
123-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
124-
"external_id": dataset.location.external_id,
125-
},
126-
}
127-
for dataset in sorted(selected_datasets, key=lambda x: x.name)
128-
],
100+
"items": datasets_to_json(selected_datasets, sort_key=lambda x: x.name),
129101
}

tests/test_server/test_datasets/test_search_datasets.py

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from data_rentgen.db.models import Dataset
88
from tests.fixtures.mocks import MockedUser
9+
from tests.test_server.utils.convert_to_json import dataset_to_json
910
from tests.test_server.utils.enrich import enrich_datasets
1011

1112
pytestmark = [pytest.mark.server, pytest.mark.asyncio]
@@ -40,22 +41,7 @@ async def test_search_datasets_by_address_url(
4041
"previous_page": None,
4142
"total_count": 1,
4243
},
43-
"items": [
44-
{
45-
"kind": "DATASET",
46-
"id": dataset.id,
47-
"format": dataset.format,
48-
"name": dataset.name,
49-
"location": {
50-
"id": dataset.location.id,
51-
"name": dataset.location.name,
52-
"type": dataset.location.type,
53-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
54-
"external_id": dataset.location.external_id,
55-
},
56-
}
57-
for dataset in datasets
58-
],
44+
"items": [dataset_to_json(dataset) for dataset in datasets],
5945
}
6046

6147

@@ -98,22 +84,7 @@ async def test_search_datasets_by_location_name(
9884
"previous_page": None,
9985
"total_count": 3,
10086
},
101-
"items": [
102-
{
103-
"kind": "DATASET",
104-
"id": dataset.id,
105-
"format": dataset.format,
106-
"name": dataset.name,
107-
"location": {
108-
"id": dataset.location.id,
109-
"name": dataset.location.name,
110-
"type": dataset.location.type,
111-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
112-
"external_id": dataset.location.external_id,
113-
},
114-
}
115-
for dataset in datasets
116-
],
87+
"items": [dataset_to_json(dataset) for dataset in datasets],
11788
}
11889

11990

@@ -145,22 +116,7 @@ async def test_search_datasets_by_dataset_name(
145116
"previous_page": None,
146117
"total_count": 1,
147118
},
148-
"items": [
149-
{
150-
"kind": "DATASET",
151-
"id": dataset.id,
152-
"format": dataset.format,
153-
"name": dataset.name,
154-
"location": {
155-
"id": dataset.location.id,
156-
"name": dataset.location.name,
157-
"type": dataset.location.type,
158-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
159-
"external_id": dataset.location.external_id,
160-
},
161-
}
162-
for dataset in datasets
163-
],
119+
"items": [dataset_to_json(dataset) for dataset in datasets],
164120
}
165121

166122

@@ -199,22 +155,7 @@ async def test_search_datasets_by_location_name_and_address_url(
199155
"previous_page": None,
200156
"total_count": 2,
201157
},
202-
"items": [
203-
{
204-
"kind": "DATASET",
205-
"id": dataset.id,
206-
"format": dataset.format,
207-
"name": dataset.name,
208-
"location": {
209-
"id": dataset.location.id,
210-
"name": dataset.location.name,
211-
"type": dataset.location.type,
212-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
213-
"external_id": dataset.location.external_id,
214-
},
215-
}
216-
for dataset in datasets
217-
],
158+
"items": [dataset_to_json(dataset) for dataset in datasets],
218159
}
219160

220161

tests/test_server/test_jobs/test_get_jobs.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from data_rentgen.db.models import Job
88
from tests.fixtures.mocks import MockedUser
9+
from tests.test_server.utils.convert_to_json import jobs_to_json
910
from tests.test_server.utils.enrich import enrich_jobs
1011

1112
pytestmark = [pytest.mark.server, pytest.mark.asyncio]
@@ -35,22 +36,7 @@ async def test_get_jobs_no_filters(
3536
"next_page": None,
3637
"previous_page": None,
3738
},
38-
"items": [
39-
{
40-
"kind": "JOB",
41-
"id": job.id,
42-
"name": job.name,
43-
"type": job.type,
44-
"location": {
45-
"id": job.location.id,
46-
"type": job.location.type,
47-
"name": job.location.name,
48-
"addresses": [{"url": address.url} for address in job.location.addresses],
49-
"external_id": job.location.external_id,
50-
},
51-
}
52-
for job in sorted(jobs, key=lambda x: x.name)
53-
],
39+
"items": jobs_to_json(jobs, sort_key=lambda x: x.name),
5440
}
5541

5642

tests/test_server/test_jobs/test_get_jobs_by_id.py

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from data_rentgen.db.models import Job
88
from tests.fixtures.mocks import MockedUser
9+
from tests.test_server.utils.convert_to_json import jobs_to_json
910
from tests.test_server.utils.enrich import enrich_jobs
1011

1112
pytestmark = [pytest.mark.server, pytest.mark.asyncio]
@@ -65,21 +66,7 @@ async def test_get_jobs_by_one_id(
6566
"next_page": None,
6667
"previous_page": None,
6768
},
68-
"items": [
69-
{
70-
"kind": "JOB",
71-
"id": job.id,
72-
"name": job.name,
73-
"type": job.type,
74-
"location": {
75-
"id": job.location.id,
76-
"type": job.location.type,
77-
"name": job.location.name,
78-
"addresses": [{"url": address.url} for address in job.location.addresses],
79-
"external_id": job.location.external_id,
80-
},
81-
},
82-
],
69+
"items": jobs_to_json([job]),
8370
}
8471

8572

@@ -110,20 +97,5 @@ async def test_get_jobs_by_multiple_ids(
11097
"next_page": None,
11198
"previous_page": None,
11299
},
113-
"items": [
114-
{
115-
"kind": "JOB",
116-
"id": job.id,
117-
"name": job.name,
118-
"type": job.type,
119-
"location": {
120-
"id": job.location.id,
121-
"type": job.location.type,
122-
"name": job.location.name,
123-
"addresses": [{"url": address.url} for address in job.location.addresses],
124-
"external_id": job.location.external_id,
125-
},
126-
}
127-
for job in sorted(selected_jobs, key=lambda x: x.name)
128-
],
100+
"items": jobs_to_json(selected_jobs, sort_key=lambda x: x.name),
129101
}

tests/test_server/test_jobs/test_search_jobs.py

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from data_rentgen.db.models import Job
88
from tests.fixtures.mocks import MockedUser
9+
from tests.test_server.utils.convert_to_json import job_to_json
910
from tests.test_server.utils.enrich import enrich_jobs
1011

1112
pytestmark = [pytest.mark.server, pytest.mark.asyncio]
@@ -39,22 +40,7 @@ async def test_search_jobs_by_address_url(
3940
"previous_page": None,
4041
"total_count": 1,
4142
},
42-
"items": [
43-
{
44-
"kind": "JOB",
45-
"id": job.id,
46-
"name": job.name,
47-
"type": job.type,
48-
"location": {
49-
"id": job.location.id,
50-
"name": job.location.name,
51-
"type": job.location.type,
52-
"addresses": [{"url": address.url} for address in job.location.addresses],
53-
"external_id": job.location.external_id,
54-
},
55-
}
56-
for job in jobs
57-
],
43+
"items": [job_to_json(job) for job in jobs],
5844
}
5945

6046

@@ -86,22 +72,7 @@ async def test_search_jobs_by_location_name(
8672
"previous_page": None,
8773
"total_count": 1,
8874
},
89-
"items": [
90-
{
91-
"kind": "JOB",
92-
"id": job.id,
93-
"name": job.name,
94-
"type": job.type,
95-
"location": {
96-
"id": job.location.id,
97-
"name": job.location.name,
98-
"type": job.location.type,
99-
"addresses": [{"url": address.url} for address in job.location.addresses],
100-
"external_id": job.location.external_id,
101-
},
102-
}
103-
for job in jobs
104-
],
75+
"items": [job_to_json(job) for job in jobs],
10576
}
10677

10778

@@ -144,22 +115,7 @@ async def test_search_jobs_by_job_name(
144115
"previous_page": None,
145116
"total_count": 3,
146117
},
147-
"items": [
148-
{
149-
"kind": "JOB",
150-
"id": job.id,
151-
"name": job.name,
152-
"type": job.type,
153-
"location": {
154-
"id": job.location.id,
155-
"name": job.location.name,
156-
"type": job.location.type,
157-
"addresses": [{"url": address.url} for address in job.location.addresses],
158-
"external_id": job.location.external_id,
159-
},
160-
}
161-
for job in jobs
162-
],
118+
"items": [job_to_json(job) for job in jobs],
163119
}
164120

165121

@@ -192,22 +148,7 @@ async def test_search_jobs_by_location_name_and_address_url(
192148
"previous_page": None,
193149
"total_count": 2,
194150
},
195-
"items": [
196-
{
197-
"kind": "JOB",
198-
"id": job.id,
199-
"name": job.name,
200-
"type": job.type,
201-
"location": {
202-
"id": job.location.id,
203-
"name": job.location.name,
204-
"type": job.location.type,
205-
"addresses": [{"url": address.url} for address in job.location.addresses],
206-
"external_id": job.location.external_id,
207-
},
208-
}
209-
for job in jobs
210-
],
151+
"items": [job_to_json(job) for job in jobs],
211152
}
212153

213154

0 commit comments

Comments
 (0)