Setup basic functional test of NSSMF RAN simulator 71/112971/3
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Tue, 22 Sep 2020 10:54:17 +0000 (12:54 +0200)
committerMorgan Richomme <morgan.richomme@orange.com>
Wed, 23 Sep 2020 07:12:43 +0000 (07:12 +0000)
This setup will be leveraged in CI for functional
verification of simulator.

Change-Id: I2e3e501c9eabfc3aadbfbb256e1e22ae2bf0221d
Issue-ID: INT-1723
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
test/mocks/ran-nssmf-simulator/.gitignore [new file with mode: 0644]
test/mocks/ran-nssmf-simulator/test-requirements.txt [new file with mode: 0644]
test/mocks/ran-nssmf-simulator/test/conftest.py [new file with mode: 0644]
test/mocks/ran-nssmf-simulator/test/test_auth.json [new file with mode: 0644]
test/mocks/ran-nssmf-simulator/test/test_main.py [new file with mode: 0644]
test/mocks/ran-nssmf-simulator/test/test_settings.py [new file with mode: 0644]
test/mocks/ran-nssmf-simulator/tox.ini [new file with mode: 0644]

diff --git a/test/mocks/ran-nssmf-simulator/.gitignore b/test/mocks/ran-nssmf-simulator/.gitignore
new file mode 100644 (file)
index 0000000..2b5a0df
--- /dev/null
@@ -0,0 +1,4 @@
+__pycache__
+.tox
+*.pyc
+RanNssmfSimulator.egg-info/
diff --git a/test/mocks/ran-nssmf-simulator/test-requirements.txt b/test/mocks/ran-nssmf-simulator/test-requirements.txt
new file mode 100644 (file)
index 0000000..547de5c
--- /dev/null
@@ -0,0 +1,2 @@
+pytest
+requests
diff --git a/test/mocks/ran-nssmf-simulator/test/conftest.py b/test/mocks/ran-nssmf-simulator/test/conftest.py
new file mode 100644 (file)
index 0000000..cfa00cd
--- /dev/null
@@ -0,0 +1,13 @@
+import pytest
+from test_settings import TEST_AUTH_DB_FILE
+from json import load
+import requests
+from requests.packages.urllib3.exceptions import InsecureRequestWarning
+
+requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
+
+@pytest.fixture(scope="module")
+def auth_credentials():
+    '''A fixture returning credentials for the simulator request'''
+    with open(TEST_AUTH_DB_FILE) as creds:
+        return load(creds)
diff --git a/test/mocks/ran-nssmf-simulator/test/test_auth.json b/test/mocks/ran-nssmf-simulator/test/test_auth.json
new file mode 100644 (file)
index 0000000..b8f6f93
--- /dev/null
@@ -0,0 +1,7 @@
+[
+  {
+    "grantType": "password",
+    "userName": "testuser",
+    "value": "Vue&W{ah0uch|ae&"
+  }
+]
diff --git a/test/mocks/ran-nssmf-simulator/test/test_main.py b/test/mocks/ran-nssmf-simulator/test/test_main.py
new file mode 100644 (file)
index 0000000..337b999
--- /dev/null
@@ -0,0 +1,10 @@
+from requests import post, codes
+from test_settings import TEST_REST_URL, TEST_REST_GET_ACCESS_TOKEN_ENDPOINT, TEST_REST_HEADERS
+
+def test_get_auth_token(auth_credentials):
+    url = f"{TEST_REST_URL}{TEST_REST_GET_ACCESS_TOKEN_ENDPOINT}"
+    response = post(url, headers=TEST_REST_HEADERS, verify=False, json=auth_credentials[0])
+    json_response = response.json()
+    assert "accessToken" in json_response
+    assert "expires" in json_response
+    assert response.status_code == codes.created
diff --git a/test/mocks/ran-nssmf-simulator/test/test_settings.py b/test/mocks/ran-nssmf-simulator/test/test_settings.py
new file mode 100644 (file)
index 0000000..445d972
--- /dev/null
@@ -0,0 +1,6 @@
+TEST_AUTH_DB_FILE = "test/test_auth.json"
+TEST_REST_PORT = 8443
+TEST_REST_IP = "127.0.0.1"
+TEST_REST_URL = f"https://{TEST_REST_IP}:{TEST_REST_PORT}"
+TEST_REST_GET_ACCESS_TOKEN_ENDPOINT = "/api/rest/securityManagement/v1/oauth/token"
+TEST_REST_HEADERS = { "Content-Type": "application/json" }
diff --git a/test/mocks/ran-nssmf-simulator/tox.ini b/test/mocks/ran-nssmf-simulator/tox.ini
new file mode 100644 (file)
index 0000000..a874ee4
--- /dev/null
@@ -0,0 +1,10 @@
+[tox]
+envlist =nssmf
+
+[testenv]
+basepython = python3
+deps = -r{toxinidir}/test-requirements.txt
+
+[testenv:nssmf]
+commands_pre = /bin/bash -c "RAN_NSSMF_REST_PORT=8443 RAN_NSSMF_AUTH_DB=test/test_auth.json python main.py &"
+commands = pytest -v