Skip to content

Commit aaf82f7

Browse files
author
Logan
committed
Update m:n tests. Split test descriptors.
1 parent 32066ba commit aaf82f7

File tree

3 files changed

+219
-51
lines changed

3 files changed

+219
-51
lines changed

tests/conftest.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Pytest Fixtures"""
1+
"""Pytest Fixtusres"""
22

33
import os
44
import pytest
@@ -8,7 +8,8 @@
88
from data_resource_api.app.data_model_manager import DataModelManagerSync
99
from pathlib import Path
1010
from time import sleep
11-
from tests.schemas import custom_descriptor
11+
from tests.schemas import frameworks_descriptor, skills_descriptor
12+
1213

1314
class PostgreSQLContainer(object):
1415
"""A PostgreSQL Container Object.
@@ -19,9 +20,10 @@ class PostgreSQLContainer(object):
1920
Class Attributes:
2021
config (object): A Configuration Factory object.
2122
container (object): The Docker container object.
22-
docker_client (object): Docker client.
23-
db_environment (list): Database environment configuration variables.
24-
db_ports (dict): Dictionary of database port mappings.
23+
for schema_dict in schema_dicts:
24+
docker_client (object): Docker client.
25+
db_environment (list): Database environment configuration variables.
26+
db_ports (dict): Dictionary of database port mappings.
2527
2628
"""
2729

@@ -165,21 +167,21 @@ def regular_client():
165167
166168
Returns:
167169
client (object): The Flask test client for the application.
168-
169170
"""
170171
client = Client()
171172
yield client.run_and_return_test_client()
172173
client.stop_container()
173174

174175

175176
@pytest.fixture(scope='module')
176-
def custom_client():
177-
"""Setup the PostgreSQL database instance and run migrations.
178-
179-
Returns:
180-
client (object): The Flask test client for the application.
181-
182-
"""
183-
client = Client(custom_descriptor)
177+
def frameworks_skills_client():
178+
client = Client([frameworks_descriptor, skills_descriptor])
184179
yield client.run_and_return_test_client()
185180
client.stop_container()
181+
182+
183+
# @pytest.fixture(scope='module')
184+
# def test_client():
185+
# client = Client(custom_descriptor)
186+
# yield client.run_and_return_test_client()
187+
# client.stop_container()

tests/schemas.py

Lines changed: 135 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,142 @@
1-
custom_descriptor = {
2-
"api": {
3-
"resource": "tests",
4-
"methods": [
5-
{
6-
"get": {
7-
"enabled": True,
8-
"secured": False,
9-
"grants": []
1+
custom_descriptor = [{
2+
"api": {
3+
"resource": "tests",
4+
"methods": [
5+
{
6+
"get": {
7+
"enabled": True,
8+
"secured": False,
9+
"grants": []
10+
}
1011
}
12+
]
13+
},
14+
"datastore": {
15+
"tablename": "tests",
16+
"restricted_fields": [],
17+
"schema": {
18+
"fields": [
19+
{
20+
"name": "id",
21+
"title": "Test ID",
22+
"description": "Test Desc",
23+
"type": "integer",
24+
"required": True
25+
},
26+
{
27+
"name": "name",
28+
"title": "namename",
29+
"description": "test name",
30+
"type": "string",
31+
"required": True
32+
}
33+
],
34+
"primaryKey": "id"
1135
}
12-
]
13-
},
14-
"datastore": {
15-
"tablename": "tests",
16-
"restricted_fields": [],
17-
"schema": {
18-
"fields": [
36+
}
37+
}
38+
]
39+
40+
frameworks_descriptor = {
41+
"api": {
42+
"resource": "frameworks",
43+
"methods": [
1944
{
20-
"name": "id",
21-
"title": "Test ID",
22-
"description": "Test Desc",
23-
"type": "integer",
24-
"required": True
25-
},
45+
"get": {
46+
"enabled": True,
47+
"secured": False,
48+
"grants": []
49+
},
50+
"post": {
51+
"enabled": True,
52+
"secured": False,
53+
"grants": []
54+
},
55+
"custom": [
56+
{
57+
"resource": "/frameworks/skills",
58+
"methods": [
59+
{
60+
"get": {
61+
"enabled": True,
62+
"secured": False,
63+
"grants": []
64+
}
65+
# "post": {
66+
# "enabled": True,
67+
# "secured": False,
68+
# "grants": []
69+
# },
70+
}
71+
]
72+
}
73+
]
74+
}
75+
]
76+
},
77+
"datastore": {
78+
"tablename": "frameworks",
79+
"restricted_fields": [],
80+
"schema": {
81+
"fields": [
82+
{
83+
"name": "id",
84+
"title": "framework ID",
85+
"description": "framework Desc",
86+
"type": "integer",
87+
"required": False
88+
},
89+
{
90+
"name": "name",
91+
"title": "framework name",
92+
"description": "framework name",
93+
"type": "string",
94+
"required": True
95+
}
96+
],
97+
"primaryKey": "id"
98+
}
99+
}
100+
}
101+
skills_descriptor= {
102+
"api": {
103+
"resource": "skills",
104+
"methods": [
26105
{
27-
"name": "name",
28-
"title": "namename",
29-
"description": "test name",
30-
"type": "string",
31-
"required": True
106+
"get": {
107+
"enabled": True,
108+
"secured": False,
109+
"grants": []
110+
},
111+
"post": {
112+
"enabled": True,
113+
"secured": False,
114+
"grants": []
115+
}
32116
}
33-
],
34-
"primaryKey": "id"
117+
]
118+
},
119+
"datastore": {
120+
"tablename": "skills",
121+
"restricted_fields": [],
122+
"schema": {
123+
"fields": [
124+
{
125+
"name": "id",
126+
"title": "skill ID",
127+
"description": "skill Desc",
128+
"type": "integer",
129+
"required": True
130+
},
131+
{
132+
"name": "text",
133+
"title": "skill text",
134+
"description": "skill text",
135+
"type": "string",
136+
"required": True
137+
}
138+
],
139+
"primaryKey": "id"
140+
}
35141
}
36142
}
37-
}

tests/test_custom_descriptor.py

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,73 @@
44

55

66
class TestStartup(object):
7-
def test_load_descriptor(self, custom_client):
7+
def test_load_descriptor(self, frameworks_skills_client):
88
## Get
9-
route = '/tests'
10-
response = custom_client.get(route)
11-
body = json.loads(response.data)
9+
def get_all_frameworks():
10+
route = '/frameworks'
11+
response = frameworks_skills_client.get(route)
12+
body = json.loads(response.data)
1213

13-
expect(response.status_code).to(equal(200))
14-
expect(body['tests']).to(be_empty)
15-
14+
expect(response.status_code).to(equal(200))
15+
expect(body['frameworks']).to(be_empty)
16+
17+
18+
## Put a framework
19+
def post_a_framework():
20+
route = '/frameworks'
21+
post_body = {
22+
"name": "test framework"
23+
}
24+
response = frameworks_skills_client.post(route, json=post_body)
25+
expect(response.status_code).to(equal(201))
26+
27+
28+
## Check for one item
29+
def check_for_one_framework():
30+
route = '/frameworks'
31+
response = frameworks_skills_client.get(route)
32+
body = json.loads(response.data)
33+
34+
expect(response.status_code).to(equal(200))
35+
expect(len(body['frameworks'])).to(equal(1))
36+
37+
38+
## Get m:n
39+
def get_many_route():
40+
route = '/frameworks/1/skills'
41+
response = frameworks_skills_client.get(route)
42+
body = json.loads(response.data)
43+
44+
expect(response.status_code).to(equal(200))
45+
print(body)
46+
expect(body['skills']).to(be_empty)
47+
48+
49+
## Put skills on the framework
50+
def post_two_skills_to_framework():
51+
route = '/frameworks/1/skills'
52+
post_body = [
53+
{"skills_text": "skill 1"},
54+
{"skills_text": "skill 2"}
55+
]
56+
response = frameworks_skills_client.post(route, json=post_body)
57+
expect(response.status_code).to(equal(201))
58+
59+
60+
# def post_one_skill_to_framework(): return
61+
62+
## Verify they are there
63+
def verify_skills_count():
64+
route = '/framework/1/skills'
65+
response = frameworks_skills_client.get(route)
66+
body = json.loads(response.data)
67+
68+
expect(response.status_code).to(equal(200))
69+
expect(len(body['skills'])).to(equal(2))
70+
71+
get_all_frameworks()
72+
post_a_framework()
73+
check_for_one_framework()
74+
get_many_route()
75+
post_two_skills_to_framework()
76+
verify_skills_count()

0 commit comments

Comments
 (0)