Skip to content

Commit 124a89c

Browse files
committed
[DOP-23867] Implement model -> json converter for tests
1 parent 5cd8f02 commit 124a89c

22 files changed

+831
-5651
lines changed

tests/test_server/test_datasets/test_get_datasets.py

Lines changed: 2 additions & 13 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]
@@ -37,19 +38,7 @@ async def test_get_datasets_no_filters(
3738
},
3839
"items": [
3940
{
40-
"data": {
41-
"kind": "DATASET",
42-
"id": dataset.id,
43-
"format": dataset.format,
44-
"name": dataset.name,
45-
"location": {
46-
"id": dataset.location.id,
47-
"name": dataset.location.name,
48-
"type": dataset.location.type,
49-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
50-
"external_id": dataset.location.external_id,
51-
},
52-
},
41+
"data": dataset_to_json(dataset),
5342
}
5443
for dataset in sorted(datasets, key=lambda x: x.name)
5544
],

tests/test_server/test_datasets/test_get_datasets_by_id.py

Lines changed: 3 additions & 26 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]
@@ -67,19 +68,7 @@ async def test_get_datasets_by_one_id(
6768
},
6869
"items": [
6970
{
70-
"data": {
71-
"kind": "DATASET",
72-
"id": dataset.id,
73-
"format": dataset.format,
74-
"name": dataset.name,
75-
"location": {
76-
"id": dataset.location.id,
77-
"name": dataset.location.name,
78-
"type": dataset.location.type,
79-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
80-
"external_id": dataset.location.external_id,
81-
},
82-
},
71+
"data": dataset_to_json(dataset),
8372
},
8473
],
8574
}
@@ -114,19 +103,7 @@ async def test_get_datasets_by_multiple_ids(
114103
},
115104
"items": [
116105
{
117-
"data": {
118-
"kind": "DATASET",
119-
"id": dataset.id,
120-
"format": dataset.format,
121-
"name": dataset.name,
122-
"location": {
123-
"id": dataset.location.id,
124-
"name": dataset.location.name,
125-
"type": dataset.location.type,
126-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
127-
"external_id": dataset.location.external_id,
128-
},
129-
},
106+
"data": dataset_to_json(dataset),
130107
}
131108
for dataset in sorted(selected_datasets, key=lambda x: x.name)
132109
],

tests/test_server/test_datasets/test_search_datasets.py

Lines changed: 5 additions & 52 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]
@@ -42,19 +43,7 @@ async def test_search_datasets_by_address_url(
4243
},
4344
"items": [
4445
{
45-
"data": {
46-
"kind": "DATASET",
47-
"id": dataset.id,
48-
"format": dataset.format,
49-
"name": dataset.name,
50-
"location": {
51-
"id": dataset.location.id,
52-
"name": dataset.location.name,
53-
"type": dataset.location.type,
54-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
55-
"external_id": dataset.location.external_id,
56-
},
57-
},
46+
"data": dataset_to_json(dataset),
5847
}
5948
for dataset in datasets
6049
],
@@ -102,19 +91,7 @@ async def test_search_datasets_by_location_name(
10291
},
10392
"items": [
10493
{
105-
"data": {
106-
"kind": "DATASET",
107-
"id": dataset.id,
108-
"format": dataset.format,
109-
"name": dataset.name,
110-
"location": {
111-
"id": dataset.location.id,
112-
"name": dataset.location.name,
113-
"type": dataset.location.type,
114-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
115-
"external_id": dataset.location.external_id,
116-
},
117-
},
94+
"data": dataset_to_json(dataset),
11895
}
11996
for dataset in datasets
12097
],
@@ -151,19 +128,7 @@ async def test_search_datasets_by_dataset_name(
151128
},
152129
"items": [
153130
{
154-
"data": {
155-
"kind": "DATASET",
156-
"id": dataset.id,
157-
"format": dataset.format,
158-
"name": dataset.name,
159-
"location": {
160-
"id": dataset.location.id,
161-
"name": dataset.location.name,
162-
"type": dataset.location.type,
163-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
164-
"external_id": dataset.location.external_id,
165-
},
166-
},
131+
"data": dataset_to_json(dataset),
167132
}
168133
for dataset in datasets
169134
],
@@ -207,19 +172,7 @@ async def test_search_datasets_by_location_name_and_address_url(
207172
},
208173
"items": [
209174
{
210-
"data": {
211-
"kind": "DATASET",
212-
"id": dataset.id,
213-
"format": dataset.format,
214-
"name": dataset.name,
215-
"location": {
216-
"id": dataset.location.id,
217-
"name": dataset.location.name,
218-
"type": dataset.location.type,
219-
"addresses": [{"url": address.url} for address in dataset.location.addresses],
220-
"external_id": dataset.location.external_id,
221-
},
222-
},
175+
"data": dataset_to_json(dataset),
223176
}
224177
for dataset in datasets
225178
],

tests/test_server/test_jobs/test_get_jobs.py

Lines changed: 2 additions & 13 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]
@@ -37,19 +38,7 @@ async def test_get_jobs_no_filters(
3738
},
3839
"items": [
3940
{
40-
"data": {
41-
"kind": "JOB",
42-
"id": job.id,
43-
"name": job.name,
44-
"type": job.type,
45-
"location": {
46-
"id": job.location.id,
47-
"type": job.location.type,
48-
"name": job.location.name,
49-
"addresses": [{"url": address.url} for address in job.location.addresses],
50-
"external_id": job.location.external_id,
51-
},
52-
},
41+
"data": job_to_json(job),
5342
}
5443
for job in sorted(jobs, key=lambda x: x.name)
5544
],

tests/test_server/test_jobs/test_get_jobs_by_id.py

Lines changed: 3 additions & 26 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]
@@ -67,19 +68,7 @@ async def test_get_jobs_by_one_id(
6768
},
6869
"items": [
6970
{
70-
"data": {
71-
"kind": "JOB",
72-
"id": job.id,
73-
"name": job.name,
74-
"type": job.type,
75-
"location": {
76-
"id": job.location.id,
77-
"type": job.location.type,
78-
"name": job.location.name,
79-
"addresses": [{"url": address.url} for address in job.location.addresses],
80-
"external_id": job.location.external_id,
81-
},
82-
},
71+
"data": job_to_json(job),
8372
},
8473
],
8574
}
@@ -114,19 +103,7 @@ async def test_get_jobs_by_multiple_ids(
114103
},
115104
"items": [
116105
{
117-
"data": {
118-
"kind": "JOB",
119-
"id": job.id,
120-
"name": job.name,
121-
"type": job.type,
122-
"location": {
123-
"id": job.location.id,
124-
"type": job.location.type,
125-
"name": job.location.name,
126-
"addresses": [{"url": address.url} for address in job.location.addresses],
127-
"external_id": job.location.external_id,
128-
},
129-
},
106+
"data": job_to_json(job),
130107
}
131108
for job in sorted(selected_jobs, key=lambda x: x.name)
132109
],

tests/test_server/test_jobs/test_search_jobs.py

Lines changed: 5 additions & 52 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]
@@ -41,19 +42,7 @@ async def test_search_jobs_by_address_url(
4142
},
4243
"items": [
4344
{
44-
"data": {
45-
"kind": "JOB",
46-
"id": job.id,
47-
"name": job.name,
48-
"type": job.type,
49-
"location": {
50-
"id": job.location.id,
51-
"type": job.location.type,
52-
"name": job.location.name,
53-
"addresses": [{"url": address.url} for address in job.location.addresses],
54-
"external_id": job.location.external_id,
55-
},
56-
},
45+
"data": job_to_json(job),
5746
}
5847
for job in jobs
5948
],
@@ -90,19 +79,7 @@ async def test_search_jobs_by_location_name(
9079
},
9180
"items": [
9281
{
93-
"data": {
94-
"kind": "JOB",
95-
"id": job.id,
96-
"name": job.name,
97-
"type": job.type,
98-
"location": {
99-
"id": job.location.id,
100-
"type": job.location.type,
101-
"name": job.location.name,
102-
"addresses": [{"url": address.url} for address in job.location.addresses],
103-
"external_id": job.location.external_id,
104-
},
105-
},
82+
"data": job_to_json(job),
10683
}
10784
for job in jobs
10885
],
@@ -150,19 +127,7 @@ async def test_search_jobs_by_job_name(
150127
},
151128
"items": [
152129
{
153-
"data": {
154-
"kind": "JOB",
155-
"id": job.id,
156-
"name": job.name,
157-
"type": job.type,
158-
"location": {
159-
"id": job.location.id,
160-
"type": job.location.type,
161-
"name": job.location.name,
162-
"addresses": [{"url": address.url} for address in job.location.addresses],
163-
"external_id": job.location.external_id,
164-
},
165-
},
130+
"data": job_to_json(job),
166131
}
167132
for job in jobs
168133
],
@@ -200,19 +165,7 @@ async def test_search_jobs_by_location_name_and_address_url(
200165
},
201166
"items": [
202167
{
203-
"data": {
204-
"kind": "JOB",
205-
"id": job.id,
206-
"name": job.name,
207-
"type": job.type,
208-
"location": {
209-
"id": job.location.id,
210-
"type": job.location.type,
211-
"name": job.location.name,
212-
"addresses": [{"url": address.url} for address in job.location.addresses],
213-
"external_id": job.location.external_id,
214-
},
215-
},
168+
"data": job_to_json(job),
216169
}
217170
for job in jobs
218171
],

0 commit comments

Comments
 (0)