Skip to content

Commit b7625c6

Browse files
committed
[#3688] Add docker compose for Objecttypes API and VCR tests
Cleanup test code
1 parent fa52ca5 commit b7625c6

8 files changed

+424
-6
lines changed

docker/docker-compose.objecttypes.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '3'
2+
3+
services:
4+
db:
5+
image: postgres
6+
environment:
7+
- POSTGRES_USER=${DB_USER:-objecttypes}
8+
- POSTGRES_PASSWORD=${DB_PASSWORD:-objecttypes}
9+
10+
web:
11+
image: maykinmedia/objecttypes-api
12+
environment:
13+
- DJANGO_SETTINGS_MODULE=objecttypes.conf.docker
14+
- SECRET_KEY=${SECRET_KEY:-fgv=c0hz&tl*8*3m3893@m+1pstrvidc9e^5@fpspmg%cy$15d}
15+
- ALLOWED_HOSTS=*
16+
- UWSGI_PORT=8001
17+
ports:
18+
- 8001:8001
19+
depends_on:
20+
- db

docker/objecttypes/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Objecttypes fixtures
2+
3+
Open Forms supports OpenID Connect as an authentication protocol. Keycloak is
4+
an example of an Identity Provider that supports OIDC.
5+
6+
We include a compose stack for development and CI purposes. This is **NOT** suitable
7+
for production usage.
8+
9+
## docker compose
10+
11+
Start a Objecttypes instance in your local environment from the parent directory:
12+
13+
```bash
14+
docker compose -f docker-compose.objecttypes.yml up -d
15+
```
16+
17+
Create a super user:
18+
19+
```bash
20+
docker compose -f docker-compose.objecttypes.yml exec web src/manage.py createsuperuser
21+
```
22+
23+
This brings up Objecttypes, the admin interface is accessible at http://localhost:8001/.
24+
25+
## Load fixtures
26+
27+
Before running the related VCR tests, you must load some fixtures:
28+
29+
```bash
30+
cat objecttypes/fixtures/test_fixtures.json | docker compose -f docker-compose.objecttypes.yml exec -T web src/manage.py loaddata --format=json -
31+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
[
2+
{
3+
"model": "core.objecttype",
4+
"pk": 1,
5+
"fields": {
6+
"uuid": "8e46e0a5-b1b4-449b-b9e9-fa3cea655f48",
7+
"name": "Person",
8+
"name_plural": "Persons",
9+
"description": "",
10+
"data_classification": "open",
11+
"maintainer_organization": "",
12+
"maintainer_department": "",
13+
"contact_person": "",
14+
"contact_email": "",
15+
"source": "",
16+
"update_frequency": "unknown",
17+
"provider_organization": "",
18+
"documentation_url": "",
19+
"labels": {},
20+
"created_at": "2023-10-24",
21+
"modified_at": "2024-02-08",
22+
"allow_geometry": true
23+
}
24+
},
25+
{
26+
"model": "core.objecttype",
27+
"pk": 2,
28+
"fields": {
29+
"uuid": "3edfdaf7-f469-470b-a391-bb7ea015bd6f",
30+
"name": "Tree",
31+
"name_plural": "Trees",
32+
"description": "",
33+
"data_classification": "confidential",
34+
"maintainer_organization": "",
35+
"maintainer_department": "",
36+
"contact_person": "",
37+
"contact_email": "",
38+
"source": "",
39+
"update_frequency": "unknown",
40+
"provider_organization": "",
41+
"documentation_url": "",
42+
"labels": {},
43+
"created_at": "2024-02-08",
44+
"modified_at": "2024-02-08",
45+
"allow_geometry": true
46+
}
47+
},
48+
{
49+
"model": "core.objectversion",
50+
"pk": 1,
51+
"fields": {
52+
"object_type": 1,
53+
"version": 1,
54+
"created_at": "2023-10-24",
55+
"modified_at": "2024-02-08",
56+
"published_at": "2024-02-08",
57+
"json_schema": {
58+
"$id": "https://example.com/person.schema.json",
59+
"type": "object",
60+
"title": "Person",
61+
"$schema": "https://json-schema.org/draft/2020-12/schema",
62+
"properties": {
63+
"age": {
64+
"type": "integer",
65+
"minimum": 0,
66+
"description": "Age in years which must be equal to or greater than zero."
67+
},
68+
"lastName": {
69+
"type": "string",
70+
"description": "The person's last name."
71+
},
72+
"firstName": {
73+
"type": "string",
74+
"description": "The person's first name."
75+
}
76+
}
77+
},
78+
"status": "published"
79+
}
80+
},
81+
{
82+
"model": "core.objectversion",
83+
"pk": 2,
84+
"fields": {
85+
"object_type": 1,
86+
"version": 2,
87+
"created_at": "2024-02-08",
88+
"modified_at": "2024-02-08",
89+
"published_at": "2024-02-08",
90+
"json_schema": {
91+
"$id": "https://example.com/person.schema.json",
92+
"type": "object",
93+
"title": "Person",
94+
"$schema": "https://json-schema.org/draft/2020-12/schema",
95+
"properties": {
96+
"age": {
97+
"type": "integer",
98+
"minimum": 18,
99+
"description": "Age in years which must be equal to or greater than 18."
100+
},
101+
"lastName": {
102+
"type": "string",
103+
"description": "The person's last name."
104+
},
105+
"firstName": {
106+
"type": "string",
107+
"description": "The person's first name."
108+
}
109+
}
110+
},
111+
"status": "published"
112+
}
113+
},
114+
{
115+
"model": "core.objectversion",
116+
"pk": 3,
117+
"fields": {
118+
"object_type": 1,
119+
"version": 3,
120+
"created_at": "2024-02-08",
121+
"modified_at": "2024-02-08",
122+
"published_at": "2024-02-08",
123+
"json_schema": {
124+
"$id": "https://example.com/person.schema.json",
125+
"type": "object",
126+
"title": "Person",
127+
"$schema": "https://json-schema.org/draft/2020-12/schema",
128+
"properties": {
129+
"age": {
130+
"type": "integer",
131+
"minimum": 18,
132+
"description": "Age in years which must be equal to or greater than 18."
133+
},
134+
"country": {
135+
"type": "string",
136+
"description": "The person's current country."
137+
},
138+
"lastName": {
139+
"type": "string",
140+
"description": "The person's last name."
141+
},
142+
"firstName": {
143+
"type": "string",
144+
"description": "The person's first name."
145+
}
146+
}
147+
},
148+
"status": "draft"
149+
}
150+
},
151+
{
152+
"model": "core.objectversion",
153+
"pk": 4,
154+
"fields": {
155+
"object_type": 2,
156+
"version": 1,
157+
"created_at": "2024-02-08",
158+
"modified_at": "2024-02-08",
159+
"published_at": "2024-02-08",
160+
"json_schema": {
161+
"$id": "https://example.com/tree.schema.json",
162+
"type": "object",
163+
"title": "Tree",
164+
"$schema": "https://json-schema.org/draft/2020-12/schema",
165+
"properties": {
166+
"height": {
167+
"type": "integer",
168+
"description": "The height of the tree."
169+
}
170+
}
171+
},
172+
"status": "published"
173+
}
174+
},
175+
{
176+
"model": "token.tokenauth",
177+
"pk": "171be5abaf41e7856b423ad513df1ef8f867ff48",
178+
"fields": {
179+
"contact_person": "Admin",
180+
"email": "admin@example.com",
181+
"organization": "",
182+
"last_modified": "2023-10-24T08:56:26.955Z",
183+
"created": "2023-10-24T08:56:26.955Z",
184+
"application": "",
185+
"administration": ""
186+
}
187+
}
188+
]

src/openforms/registrations/contrib/objects_api/api/views.py

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from typing import Any
22

3-
from django.utils.translation import gettext_lazy as _
4-
53
from drf_spectacular.utils import extend_schema, extend_schema_view
64
from rest_framework import authentication, permissions, views
75

@@ -26,10 +24,6 @@ class ObjecttypesListView(ListMixin, views.APIView):
2624
serializer_class = ObjecttypeSerializer
2725

2826
def get_objects(self) -> list[dict[str, Any]]:
29-
import time
30-
31-
time.sleep(1)
32-
raise Exception()
3327
with get_objecttypes_client() as client:
3428
return client.list_objecttypes()
3529

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate, br
9+
Authorization:
10+
- Token 171be5abaf41e7856b423ad513df1ef8f867ff48
11+
Connection:
12+
- keep-alive
13+
User-Agent:
14+
- python-requests/2.31.0
15+
method: GET
16+
uri: http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48/versions
17+
response:
18+
body:
19+
string: '{"count":3,"next":null,"previous":null,"results":[{"url":"http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48/versions/3","version":3,"objectType":"http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48","status":"draft","jsonSchema":{"$id":"https://example.com/person.schema.json","type":"object","title":"Person","$schema":"https://json-schema.org/draft/2020-12/schema","properties":{"age":{"type":"integer","minimum":18,"description":"Age
20+
in years which must be equal to or greater than 18."},"country":{"type":"string","description":"The
21+
person''s current country."},"lastName":{"type":"string","description":"The
22+
person''s last name."},"firstName":{"type":"string","description":"The person''s
23+
first name."}}},"createdAt":"2024-02-08","modifiedAt":"2024-02-08","publishedAt":"2024-02-08"},{"url":"http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48/versions/2","version":2,"objectType":"http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48","status":"published","jsonSchema":{"$id":"https://example.com/person.schema.json","type":"object","title":"Person","$schema":"https://json-schema.org/draft/2020-12/schema","properties":{"age":{"type":"integer","minimum":18,"description":"Age
24+
in years which must be equal to or greater than 18."},"lastName":{"type":"string","description":"The
25+
person''s last name."},"firstName":{"type":"string","description":"The person''s
26+
first name."}}},"createdAt":"2024-02-08","modifiedAt":"2024-02-08","publishedAt":"2024-02-08"},{"url":"http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48/versions/1","version":1,"objectType":"http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48","status":"published","jsonSchema":{"$id":"https://example.com/person.schema.json","type":"object","title":"Person","$schema":"https://json-schema.org/draft/2020-12/schema","properties":{"age":{"type":"integer","minimum":0,"description":"Age
27+
in years which must be equal to or greater than zero."},"lastName":{"type":"string","description":"The
28+
person''s last name."},"firstName":{"type":"string","description":"The person''s
29+
first name."}}},"createdAt":"2023-10-24","modifiedAt":"2024-02-08","publishedAt":"2024-02-08"}]}'
30+
headers:
31+
Allow:
32+
- GET, POST, HEAD, OPTIONS
33+
Content-Length:
34+
- '2282'
35+
Content-Type:
36+
- application/json
37+
Referrer-Policy:
38+
- same-origin
39+
X-Content-Type-Options:
40+
- nosniff
41+
X-Frame-Options:
42+
- DENY
43+
status:
44+
code: 200
45+
message: OK
46+
version: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate, br
9+
Authorization:
10+
- Token 171be5abaf41e7856b423ad513df1ef8f867ff48
11+
Connection:
12+
- keep-alive
13+
User-Agent:
14+
- python-requests/2.31.0
15+
method: GET
16+
uri: http://localhost:8001/api/v2/objecttypes
17+
response:
18+
body:
19+
string: '{"count":2,"next":null,"previous":null,"results":[{"url":"http://localhost:8001/api/v2/objecttypes/3edfdaf7-f469-470b-a391-bb7ea015bd6f","uuid":"3edfdaf7-f469-470b-a391-bb7ea015bd6f","name":"Tree","namePlural":"Trees","description":"","dataClassification":"confidential","maintainerOrganization":"","maintainerDepartment":"","contactPerson":"","contactEmail":"","source":"","updateFrequency":"unknown","providerOrganization":"","documentationUrl":"","labels":{},"createdAt":"2024-02-08","modifiedAt":"2024-02-08","allowGeometry":true,"versions":["http://localhost:8001/api/v2/objecttypes/3edfdaf7-f469-470b-a391-bb7ea015bd6f/versions/1"]},{"url":"http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48","uuid":"8e46e0a5-b1b4-449b-b9e9-fa3cea655f48","name":"Person","namePlural":"Persons","description":"","dataClassification":"open","maintainerOrganization":"","maintainerDepartment":"","contactPerson":"","contactEmail":"","source":"","updateFrequency":"unknown","providerOrganization":"","documentationUrl":"","labels":{},"createdAt":"2023-10-24","modifiedAt":"2024-02-08","allowGeometry":true,"versions":["http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48/versions/1","http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48/versions/2","http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48/versions/3"]}]}'
20+
headers:
21+
Allow:
22+
- GET, POST, HEAD, OPTIONS
23+
Content-Length:
24+
- '1407'
25+
Content-Type:
26+
- application/json
27+
Referrer-Policy:
28+
- same-origin
29+
X-Content-Type-Options:
30+
- nosniff
31+
X-Frame-Options:
32+
- DENY
33+
status:
34+
code: 200
35+
message: OK
36+
version: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate, br
9+
Authorization:
10+
- Token 171be5abaf41e7856b423ad513df1ef8f867ff48
11+
Connection:
12+
- keep-alive
13+
User-Agent:
14+
- python-requests/2.31.0
15+
method: GET
16+
uri: http://localhost:8001/api/v2/objecttypes?dataClassification=confidential
17+
response:
18+
body:
19+
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8001/api/v2/objecttypes/3edfdaf7-f469-470b-a391-bb7ea015bd6f","uuid":"3edfdaf7-f469-470b-a391-bb7ea015bd6f","name":"Tree","namePlural":"Trees","description":"","dataClassification":"confidential","maintainerOrganization":"","maintainerDepartment":"","contactPerson":"","contactEmail":"","source":"","updateFrequency":"unknown","providerOrganization":"","documentationUrl":"","labels":{},"createdAt":"2024-02-08","modifiedAt":"2024-02-08","allowGeometry":true,"versions":["http://localhost:8001/api/v2/objecttypes/3edfdaf7-f469-470b-a391-bb7ea015bd6f/versions/1"]}]}'
20+
headers:
21+
Allow:
22+
- GET, POST, HEAD, OPTIONS
23+
Content-Length:
24+
- '640'
25+
Content-Type:
26+
- application/json
27+
Referrer-Policy:
28+
- same-origin
29+
X-Content-Type-Options:
30+
- nosniff
31+
X-Frame-Options:
32+
- DENY
33+
status:
34+
code: 200
35+
message: OK
36+
version: 1

0 commit comments

Comments
 (0)