2016-12-02 09:18:22 -05:00
|
|
|
"""
|
|
|
|
Functional tests for the managing sites.
|
|
|
|
|
2017-03-16 08:34:57 -04:00
|
|
|
:copyright: Copyright 2013-2017, Dorian Pula <dorian.pula@amber-penguin-software.ca>
|
2016-12-02 09:18:22 -05:00
|
|
|
:license: AGPL v3+
|
|
|
|
"""
|
|
|
|
|
2017-04-05 17:43:24 -04:00
|
|
|
import http
|
2017-10-19 09:00:53 -04:00
|
|
|
from unittest import mock
|
2017-04-05 17:43:24 -04:00
|
|
|
|
2016-12-02 09:18:22 -05:00
|
|
|
import pytest_bdd as bdd
|
|
|
|
import requests
|
2017-03-14 09:09:16 -04:00
|
|
|
from pytest_bdd import parsers
|
2016-12-02 09:18:22 -05:00
|
|
|
|
2017-03-14 08:46:54 -04:00
|
|
|
from tests import utils
|
2016-12-02 09:18:22 -05:00
|
|
|
|
|
|
|
|
2017-04-26 08:34:48 -04:00
|
|
|
# TODO: Rework site management and testing.
|
2017-05-02 08:35:12 -04:00
|
|
|
bdd.scenarios('site_access.feature')
|
|
|
|
# TODO: Rework modification to only allow changes to layout and children...
|
2017-10-18 18:03:09 -04:00
|
|
|
# bdd.scenarios('site_modification.feature')
|
2017-04-05 17:43:24 -04:00
|
|
|
|
2016-12-02 09:18:22 -05:00
|
|
|
|
2017-04-05 20:59:19 -04:00
|
|
|
@bdd.given(parsers.parse('I try to modify the site with a non-json request'), target_fixture='api_response')
|
|
|
|
def invalid_non_json_modify_site_response(api_response, auth_token_headers, api_base_uri):
|
2017-04-05 17:43:24 -04:00
|
|
|
return requests.put(
|
2017-05-02 08:35:12 -04:00
|
|
|
url=f'{api_base_uri}/api/site',
|
2017-04-05 17:43:24 -04:00
|
|
|
data='',
|
|
|
|
headers=auth_token_headers,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-10-18 18:03:09 -04:00
|
|
|
@bdd.given(parsers.parse('I try to modify the site with an empty retest_sitequest'), target_fixture='api_response')
|
2017-04-05 20:59:19 -04:00
|
|
|
def invalid_empty_modify_site_response(api_response, auth_token_headers, api_base_uri):
|
2017-04-05 17:43:24 -04:00
|
|
|
return requests.put(
|
2017-05-02 08:35:12 -04:00
|
|
|
url=f'{api_base_uri}/api/site',
|
2017-04-05 17:43:24 -04:00
|
|
|
json={},
|
|
|
|
headers=auth_token_headers,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-05-02 08:35:12 -04:00
|
|
|
@bdd.given(parsers.parse('I get the site'), target_fixture='api_response')
|
|
|
|
def get_site_request(test_site, auth_token_headers, api_base_uri):
|
2017-04-05 17:43:24 -04:00
|
|
|
response = requests.get(
|
2017-05-02 08:35:12 -04:00
|
|
|
url=f'{api_base_uri}/api/site',
|
2017-04-05 17:43:24 -04:00
|
|
|
headers=auth_token_headers,
|
|
|
|
)
|
2017-04-05 18:12:06 -04:00
|
|
|
return utils.ResponseSampleBundle(response, test_site)
|
2017-04-05 17:43:24 -04:00
|
|
|
|
|
|
|
|
2017-10-18 23:52:43 -04:00
|
|
|
@bdd.then(parsers.parse('I get a valid site with a menu and landing page'))
|
|
|
|
def assert_site_response(api_response):
|
2017-04-05 17:43:24 -04:00
|
|
|
|
2017-04-05 20:59:19 -04:00
|
|
|
actual_response = utils.extract_response(api_response)
|
2017-04-05 17:43:24 -04:00
|
|
|
assert actual_response.status_code == http.HTTPStatus.OK
|
|
|
|
|
|
|
|
expected_json = {
|
2017-10-18 23:52:43 -04:00
|
|
|
'name': 'Rookeries',
|
|
|
|
'urls': {'self': '/api/site'},
|
|
|
|
'config': mock.ANY,
|
|
|
|
# TODO: Make sure to test against a real test landing page.
|
|
|
|
'landingPage': mock.ANY,
|
|
|
|
'menu': []
|
2017-04-05 17:43:24 -04:00
|
|
|
}
|
|
|
|
assert expected_json == actual_response.json()
|
|
|
|
|
|
|
|
|
2017-04-05 20:59:19 -04:00
|
|
|
@bdd.given(parsers.parse('I try to modify the site'), target_fixture='api_response')
|
2017-05-02 08:35:12 -04:00
|
|
|
def modify_site_response(test_site, api_response, auth_token_headers, api_base_uri):
|
2017-04-05 20:59:19 -04:00
|
|
|
test_site = api_response.sample
|
2017-05-02 08:35:12 -04:00
|
|
|
site_modification_request = {}
|
2017-04-05 17:43:24 -04:00
|
|
|
|
|
|
|
response = requests.put(
|
2017-05-02 08:35:12 -04:00
|
|
|
url=f'{api_base_uri}/api/site',
|
2017-04-05 17:43:24 -04:00
|
|
|
json=site_modification_request,
|
|
|
|
headers=auth_token_headers,
|
|
|
|
)
|
2017-05-02 08:35:12 -04:00
|
|
|
return utils.ResponseSampleBundle(response, test_site)
|
2017-04-05 17:43:24 -04:00
|
|
|
|
|
|
|
|
2017-04-05 20:59:19 -04:00
|
|
|
@bdd.given(parsers.parse('I try to modify a site that does not exist'), target_fixture='api_response')
|
2017-05-02 08:35:12 -04:00
|
|
|
def modify_non_existent_site_request(test_site, auth_token_headers, api_base_uri):
|
2017-04-05 17:43:24 -04:00
|
|
|
site_modification_request = {
|
|
|
|
}
|
|
|
|
|
|
|
|
return requests.put(
|
2017-05-02 08:35:12 -04:00
|
|
|
url=f'{api_base_uri}/api/site',
|
2017-04-05 17:43:24 -04:00
|
|
|
json=site_modification_request,
|
|
|
|
headers=auth_token_headers,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@bdd.then(parsers.parse('my updates are reflected in the site'))
|
2017-04-05 20:59:19 -04:00
|
|
|
def assert_updated_site_response(api_response, api_base_uri):
|
|
|
|
actual_response = utils.extract_response(api_response)
|
2017-04-05 17:43:24 -04:00
|
|
|
assert actual_response.status_code == http.HTTPStatus.OK
|
|
|
|
|
2017-05-02 08:35:12 -04:00
|
|
|
expected_json = {}
|
2017-04-05 17:43:24 -04:00
|
|
|
assert expected_json == actual_response.json()
|
2017-05-02 08:35:12 -04:00
|
|
|
assert f'{api_base_uri}/api/site' == actual_response.json()['urls']['self']
|
2017-04-05 17:43:24 -04:00
|
|
|
|
|
|
|
|
|
|
|
@bdd.then(parsers.parse('I get a site can not be found message'))
|
2017-04-05 20:59:19 -04:00
|
|
|
def assert_resource_not_found_response(api_response):
|
|
|
|
actual_response = utils.extract_response(api_response)
|
2017-04-05 17:43:24 -04:00
|
|
|
expected_response_json = {
|
|
|
|
'error': {
|
|
|
|
'status_code': http.HTTPStatus.NOT_FOUND.value,
|
|
|
|
'message': 'Resource not found.',
|
|
|
|
'resource': actual_response.request.url,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert actual_response.status_code == http.HTTPStatus.NOT_FOUND
|
|
|
|
assert actual_response.json() == expected_response_json
|