From 6049499c5a17cfa58f351b3731837463b7359047 Mon Sep 17 00:00:00 2001 From: Bartek Grzybowski Date: Wed, 15 Apr 2020 04:48:16 -0700 Subject: Move tests to their own directory File layout was also restructured for better readability. Change-Id: Id1cba755127319c45ec50b08d12daa543c8c9ae5 Issue-ID: INT-1529 Signed-off-by: Bartek Grzybowski --- .../prov-mns-provider/src/test-requirements.txt | 2 - test/mocks/prov-mns-provider/src/test_mns.py | 74 ---------------------- .../prov-mns-provider/src/tests/ConfigInfo.json | 1 + .../src/tests/DefinedNRMFunction.json | 1 + .../prov-mns-provider/src/tests/ProvMnSProvider.py | 1 + .../prov-mns-provider/src/tests/UserInfo.json | 1 + test/mocks/prov-mns-provider/src/tests/common.py | 23 +++++++ .../prov-mns-provider/src/tests/preSetMOI.json | 1 + .../src/tests/test-requirements.txt | 2 + .../src/tests/test_rest_api_endpoints.py | 52 +++++++++++++++ test/mocks/prov-mns-provider/src/tox.ini | 2 +- 11 files changed, 83 insertions(+), 77 deletions(-) delete mode 100644 test/mocks/prov-mns-provider/src/test-requirements.txt delete mode 100644 test/mocks/prov-mns-provider/src/test_mns.py create mode 120000 test/mocks/prov-mns-provider/src/tests/ConfigInfo.json create mode 120000 test/mocks/prov-mns-provider/src/tests/DefinedNRMFunction.json create mode 120000 test/mocks/prov-mns-provider/src/tests/ProvMnSProvider.py create mode 120000 test/mocks/prov-mns-provider/src/tests/UserInfo.json create mode 100644 test/mocks/prov-mns-provider/src/tests/common.py create mode 120000 test/mocks/prov-mns-provider/src/tests/preSetMOI.json create mode 100644 test/mocks/prov-mns-provider/src/tests/test-requirements.txt create mode 100644 test/mocks/prov-mns-provider/src/tests/test_rest_api_endpoints.py (limited to 'test') diff --git a/test/mocks/prov-mns-provider/src/test-requirements.txt b/test/mocks/prov-mns-provider/src/test-requirements.txt deleted file mode 100644 index 547de5c5b..000000000 --- a/test/mocks/prov-mns-provider/src/test-requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -pytest -requests diff --git a/test/mocks/prov-mns-provider/src/test_mns.py b/test/mocks/prov-mns-provider/src/test_mns.py deleted file mode 100644 index 53a984738..000000000 --- a/test/mocks/prov-mns-provider/src/test_mns.py +++ /dev/null @@ -1,74 +0,0 @@ -import requests -from uuid import uuid4 -import ProvMnSProvider -import logging -from json import dumps - -logging.basicConfig(level=logging.DEBUG) -logger = logging.getLogger(__name__) - -MOI_ID = str(uuid4()) -MOI_CLASS = ProvMnSProvider.Cretaed_MOIs_list[0]['class'] -MOI_DATA_TMPL = { 'data': ProvMnSProvider.Cretaed_MOIs_list[0] } -MOI_DATA_PATCH = { "data": { "pLMNId": "xxx", "gNBId": "1234", "gNBIdLength": "4" }} -URI_SCHEMA = 'http' -AUTH_STRING = (ProvMnSProvider.username, ProvMnSProvider.password) -URI_BASE_STRING = URI_SCHEMA + '://' + ProvMnSProvider.ipAddress + ':' + \ - str(ProvMnSProvider.portNumber) + ProvMnSProvider.prefix + \ - '/' + MOI_CLASS + '/' + MOI_ID -URI_PUT_STRING = URI_BASE_STRING -URI_GET_STRING = URI_BASE_STRING + '?scope=BASE_ONLY&filter=' + MOI_CLASS + \ - '&fields=gNBId&fields=gNBIdLength' -URI_PATCH_STRING = URI_BASE_STRING + '?scope=BASE_ONLY&filter=' + MOI_CLASS -URI_DELETE_STRING = URI_PATCH_STRING - -def test_put(): - '''Validate PUT request''' - - MOI_DATA = MOI_DATA_TMPL - MOI_DATA['data']['id'] = MOI_ID - MOI_DATA['data']['href'] = '/' + MOI_CLASS + '/' + MOI_ID - req_put = requests.put('{0}'.format(URI_PUT_STRING), auth=AUTH_STRING, - json=MOI_DATA) - - if req_put.status_code != requests.codes.created: - logger.error('PUT request to {0} failed'.format(URI_PUT_STRING)) - logger.debug('MOI data payload: {0}'.format(dumps(MOI_DATA,indent=2))) - logger.debug('Response content: {0}'.format(req_put.text)) - - assert req_put.status_code == requests.codes.created - -def test_get(): - '''Validate GET request''' - - req_get = requests.get('{0}'.format(URI_GET_STRING), auth=AUTH_STRING) - - if req_get.status_code != requests.codes.ok: - logger.error('GET request to {0} failed'.format(URI_GET_STRING)) - logger.debug('Response content: {0}'.format(req_get.text)) - - assert req_get.status_code == requests.codes.ok - -def test_patch(): - '''Validate PATCH request''' - - req_patch = requests.patch('{0}'.format(URI_PATCH_STRING), - auth=AUTH_STRING, json=MOI_DATA_PATCH) - - if req_patch.status_code != requests.codes.ok: - logger.error('PATCH request to {0} failed'.format(URI_PATCH_STRING)) - logger.debug('Response content: {0}'.format(req_patch.text)) - - assert req_patch.status_code == requests.codes.ok - -def test_delete(): - '''Validate DELETE request''' - - req_delete = requests.delete('{0}'.format(URI_DELETE_STRING), - auth=AUTH_STRING) - - if req_delete.status_code != requests.codes.ok: - logger.error('DELETE request to {0} failed'.format(URI_DELETE_STRING)) - logger.debug('Response content: {0}'.format(req_delete.text)) - - assert req_delete.status_code == requests.codes.ok diff --git a/test/mocks/prov-mns-provider/src/tests/ConfigInfo.json b/test/mocks/prov-mns-provider/src/tests/ConfigInfo.json new file mode 120000 index 000000000..66ede7d7a --- /dev/null +++ b/test/mocks/prov-mns-provider/src/tests/ConfigInfo.json @@ -0,0 +1 @@ +../ConfigInfo.json \ No newline at end of file diff --git a/test/mocks/prov-mns-provider/src/tests/DefinedNRMFunction.json b/test/mocks/prov-mns-provider/src/tests/DefinedNRMFunction.json new file mode 120000 index 000000000..a56d54d9d --- /dev/null +++ b/test/mocks/prov-mns-provider/src/tests/DefinedNRMFunction.json @@ -0,0 +1 @@ +../DefinedNRMFunction.json \ No newline at end of file diff --git a/test/mocks/prov-mns-provider/src/tests/ProvMnSProvider.py b/test/mocks/prov-mns-provider/src/tests/ProvMnSProvider.py new file mode 120000 index 000000000..96f10491e --- /dev/null +++ b/test/mocks/prov-mns-provider/src/tests/ProvMnSProvider.py @@ -0,0 +1 @@ +../ProvMnSProvider.py \ No newline at end of file diff --git a/test/mocks/prov-mns-provider/src/tests/UserInfo.json b/test/mocks/prov-mns-provider/src/tests/UserInfo.json new file mode 120000 index 000000000..cc7354bc5 --- /dev/null +++ b/test/mocks/prov-mns-provider/src/tests/UserInfo.json @@ -0,0 +1 @@ +../UserInfo.json \ No newline at end of file diff --git a/test/mocks/prov-mns-provider/src/tests/common.py b/test/mocks/prov-mns-provider/src/tests/common.py new file mode 100644 index 000000000..08075e999 --- /dev/null +++ b/test/mocks/prov-mns-provider/src/tests/common.py @@ -0,0 +1,23 @@ +import requests # pylint: disable=W0611 +from uuid import uuid4 +import ProvMnSProvider +import logging +from json import dumps # pylint: disable=W0611 + +logging.basicConfig(level=logging.DEBUG) +logger = logging.getLogger(__name__) + +MOI_ID = str(uuid4()) +MOI_CLASS = ProvMnSProvider.Cretaed_MOIs_list[0]['class'] +MOI_DATA_TMPL = { 'data': ProvMnSProvider.Cretaed_MOIs_list[0] } +MOI_DATA_PATCH = { "data": { "pLMNId": "xxx", "gNBId": "1234", "gNBIdLength": "4" }} +URI_SCHEMA = 'http' +AUTH_STRING = (ProvMnSProvider.username, ProvMnSProvider.password) +URI_BASE_STRING = URI_SCHEMA + '://' + ProvMnSProvider.ipAddress + ':' + \ + str(ProvMnSProvider.portNumber) + ProvMnSProvider.prefix + \ + '/' + MOI_CLASS + '/' + MOI_ID +URI_PUT_STRING = URI_BASE_STRING +URI_GET_STRING = URI_BASE_STRING + '?scope=BASE_ONLY&filter=' + MOI_CLASS + \ + '&fields=gNBId&fields=gNBIdLength' +URI_PATCH_STRING = URI_BASE_STRING + '?scope=BASE_ONLY&filter=' + MOI_CLASS +URI_DELETE_STRING = URI_PATCH_STRING diff --git a/test/mocks/prov-mns-provider/src/tests/preSetMOI.json b/test/mocks/prov-mns-provider/src/tests/preSetMOI.json new file mode 120000 index 000000000..053256d80 --- /dev/null +++ b/test/mocks/prov-mns-provider/src/tests/preSetMOI.json @@ -0,0 +1 @@ +../preSetMOI.json \ No newline at end of file diff --git a/test/mocks/prov-mns-provider/src/tests/test-requirements.txt b/test/mocks/prov-mns-provider/src/tests/test-requirements.txt new file mode 100644 index 000000000..547de5c5b --- /dev/null +++ b/test/mocks/prov-mns-provider/src/tests/test-requirements.txt @@ -0,0 +1,2 @@ +pytest +requests diff --git a/test/mocks/prov-mns-provider/src/tests/test_rest_api_endpoints.py b/test/mocks/prov-mns-provider/src/tests/test_rest_api_endpoints.py new file mode 100644 index 000000000..0cc459195 --- /dev/null +++ b/test/mocks/prov-mns-provider/src/tests/test_rest_api_endpoints.py @@ -0,0 +1,52 @@ +from common import * + +def test_put(): + '''Validate PUT request''' + + MOI_DATA = MOI_DATA_TMPL + MOI_DATA['data']['id'] = MOI_ID + MOI_DATA['data']['href'] = '/' + MOI_CLASS + '/' + MOI_ID + req_put = requests.put('{0}'.format(URI_PUT_STRING), auth=AUTH_STRING, + json=MOI_DATA) + + if req_put.status_code != requests.codes.created: + logger.error('PUT request to {0} failed'.format(URI_PUT_STRING)) + logger.debug('MOI data payload: {0}'.format(dumps(MOI_DATA,indent=2))) + logger.debug('Response content: {0}'.format(req_put.text)) + + assert req_put.status_code == requests.codes.created + +def test_get(): + '''Validate GET request''' + + req_get = requests.get('{0}'.format(URI_GET_STRING), auth=AUTH_STRING) + + if req_get.status_code != requests.codes.ok: + logger.error('GET request to {0} failed'.format(URI_GET_STRING)) + logger.debug('Response content: {0}'.format(req_get.text)) + + assert req_get.status_code == requests.codes.ok + +def test_patch(): + '''Validate PATCH request''' + + req_patch = requests.patch('{0}'.format(URI_PATCH_STRING), + auth=AUTH_STRING, json=MOI_DATA_PATCH) + + if req_patch.status_code != requests.codes.ok: + logger.error('PATCH request to {0} failed'.format(URI_PATCH_STRING)) + logger.debug('Response content: {0}'.format(req_patch.text)) + + assert req_patch.status_code == requests.codes.ok + +def test_delete(): + '''Validate DELETE request''' + + req_delete = requests.delete('{0}'.format(URI_DELETE_STRING), + auth=AUTH_STRING) + + if req_delete.status_code != requests.codes.ok: + logger.error('DELETE request to {0} failed'.format(URI_DELETE_STRING)) + logger.debug('Response content: {0}'.format(req_delete.text)) + + assert req_delete.status_code == requests.codes.ok diff --git a/test/mocks/prov-mns-provider/src/tox.ini b/test/mocks/prov-mns-provider/src/tox.ini index 02bc0435b..2f2976307 100644 --- a/test/mocks/prov-mns-provider/src/tox.ini +++ b/test/mocks/prov-mns-provider/src/tox.ini @@ -3,7 +3,7 @@ envlist = py3 skipsdist = True [testenv] -deps = -r{toxinidir}/test-requirements.txt +deps = -r{toxinidir}/tests/test-requirements.txt commands = pytest [pytest] -- cgit 1.2.3-korg