Skip to content

Commit

Permalink
Update m:n tests. Split test descriptors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan committed Oct 22, 2019
1 parent 32066ba commit aaf82f7
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 51 deletions.
30 changes: 16 additions & 14 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Pytest Fixtures"""
"""Pytest Fixtusres"""

import os
import pytest
Expand All @@ -8,7 +8,8 @@
from data_resource_api.app.data_model_manager import DataModelManagerSync
from pathlib import Path
from time import sleep
from tests.schemas import custom_descriptor
from tests.schemas import frameworks_descriptor, skills_descriptor


class PostgreSQLContainer(object):
"""A PostgreSQL Container Object.
Expand All @@ -19,9 +20,10 @@ class PostgreSQLContainer(object):
Class Attributes:
config (object): A Configuration Factory object.
container (object): The Docker container object.
docker_client (object): Docker client.
db_environment (list): Database environment configuration variables.
db_ports (dict): Dictionary of database port mappings.
for schema_dict in schema_dicts:
docker_client (object): Docker client.
db_environment (list): Database environment configuration variables.
db_ports (dict): Dictionary of database port mappings.
"""

Expand Down Expand Up @@ -165,21 +167,21 @@ def regular_client():
Returns:
client (object): The Flask test client for the application.
"""
client = Client()
yield client.run_and_return_test_client()
client.stop_container()


@pytest.fixture(scope='module')
def custom_client():
"""Setup the PostgreSQL database instance and run migrations.
Returns:
client (object): The Flask test client for the application.
"""
client = Client(custom_descriptor)
def frameworks_skills_client():
client = Client([frameworks_descriptor, skills_descriptor])
yield client.run_and_return_test_client()
client.stop_container()


# @pytest.fixture(scope='module')
# def test_client():
# client = Client(custom_descriptor)
# yield client.run_and_return_test_client()
# client.stop_container()
165 changes: 135 additions & 30 deletions tests/schemas.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,142 @@
custom_descriptor = {
"api": {
"resource": "tests",
"methods": [
{
"get": {
"enabled": True,
"secured": False,
"grants": []
custom_descriptor = [{
"api": {
"resource": "tests",
"methods": [
{
"get": {
"enabled": True,
"secured": False,
"grants": []
}
}
]
},
"datastore": {
"tablename": "tests",
"restricted_fields": [],
"schema": {
"fields": [
{
"name": "id",
"title": "Test ID",
"description": "Test Desc",
"type": "integer",
"required": True
},
{
"name": "name",
"title": "namename",
"description": "test name",
"type": "string",
"required": True
}
],
"primaryKey": "id"
}
]
},
"datastore": {
"tablename": "tests",
"restricted_fields": [],
"schema": {
"fields": [
}
}
]

frameworks_descriptor = {
"api": {
"resource": "frameworks",
"methods": [
{
"name": "id",
"title": "Test ID",
"description": "Test Desc",
"type": "integer",
"required": True
},
"get": {
"enabled": True,
"secured": False,
"grants": []
},
"post": {
"enabled": True,
"secured": False,
"grants": []
},
"custom": [
{
"resource": "/frameworks/skills",
"methods": [
{
"get": {
"enabled": True,
"secured": False,
"grants": []
}
# "post": {
# "enabled": True,
# "secured": False,
# "grants": []
# },
}
]
}
]
}
]
},
"datastore": {
"tablename": "frameworks",
"restricted_fields": [],
"schema": {
"fields": [
{
"name": "id",
"title": "framework ID",
"description": "framework Desc",
"type": "integer",
"required": False
},
{
"name": "name",
"title": "framework name",
"description": "framework name",
"type": "string",
"required": True
}
],
"primaryKey": "id"
}
}
}
skills_descriptor= {
"api": {
"resource": "skills",
"methods": [
{
"name": "name",
"title": "namename",
"description": "test name",
"type": "string",
"required": True
"get": {
"enabled": True,
"secured": False,
"grants": []
},
"post": {
"enabled": True,
"secured": False,
"grants": []
}
}
],
"primaryKey": "id"
]
},
"datastore": {
"tablename": "skills",
"restricted_fields": [],
"schema": {
"fields": [
{
"name": "id",
"title": "skill ID",
"description": "skill Desc",
"type": "integer",
"required": True
},
{
"name": "text",
"title": "skill text",
"description": "skill text",
"type": "string",
"required": True
}
],
"primaryKey": "id"
}
}
}
}
75 changes: 68 additions & 7 deletions tests/test_custom_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,73 @@


class TestStartup(object):
def test_load_descriptor(self, custom_client):
def test_load_descriptor(self, frameworks_skills_client):
## Get
route = '/tests'
response = custom_client.get(route)
body = json.loads(response.data)
def get_all_frameworks():
route = '/frameworks'
response = frameworks_skills_client.get(route)
body = json.loads(response.data)

expect(response.status_code).to(equal(200))
expect(body['tests']).to(be_empty)

expect(response.status_code).to(equal(200))
expect(body['frameworks']).to(be_empty)


## Put a framework
def post_a_framework():
route = '/frameworks'
post_body = {
"name": "test framework"
}
response = frameworks_skills_client.post(route, json=post_body)
expect(response.status_code).to(equal(201))


## Check for one item
def check_for_one_framework():
route = '/frameworks'
response = frameworks_skills_client.get(route)
body = json.loads(response.data)

expect(response.status_code).to(equal(200))
expect(len(body['frameworks'])).to(equal(1))


## Get m:n
def get_many_route():
route = '/frameworks/1/skills'
response = frameworks_skills_client.get(route)
body = json.loads(response.data)

expect(response.status_code).to(equal(200))
print(body)
expect(body['skills']).to(be_empty)


## Put skills on the framework
def post_two_skills_to_framework():
route = '/frameworks/1/skills'
post_body = [
{"skills_text": "skill 1"},
{"skills_text": "skill 2"}
]
response = frameworks_skills_client.post(route, json=post_body)
expect(response.status_code).to(equal(201))


# def post_one_skill_to_framework(): return

## Verify they are there
def verify_skills_count():
route = '/framework/1/skills'
response = frameworks_skills_client.get(route)
body = json.loads(response.data)

expect(response.status_code).to(equal(200))
expect(len(body['skills'])).to(equal(2))

get_all_frameworks()
post_a_framework()
check_for_one_framework()
get_many_route()
post_two_skills_to_framework()
verify_skills_count()

0 comments on commit aaf82f7

Please sign in to comment.