diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/unit/test_config_api.tavern.yaml b/tests/api/test_config_api.tavern.yaml similarity index 88% rename from tests/unit/test_config_api.tavern.yaml rename to tests/api/test_config_api.tavern.yaml index 6c89c4c..ddb5bbb 100644 --- a/tests/unit/test_config_api.tavern.yaml +++ b/tests/api/test_config_api.tavern.yaml @@ -3,7 +3,7 @@ test_name: configuration API stages: - name: Get config request: - url: "{tavern.env_vars.ARM_URL}configuration" + url: "{api_url}configuration" method: GET response: status_code: 200 diff --git a/tests/unit/test_lifecycle_api.tavern.yaml b/tests/api/test_lifecycle_api.tavern.yaml similarity index 82% rename from tests/unit/test_lifecycle_api.tavern.yaml rename to tests/api/test_lifecycle_api.tavern.yaml index e9a4134..a075d86 100644 --- a/tests/unit/test_lifecycle_api.tavern.yaml +++ b/tests/api/test_lifecycle_api.tavern.yaml @@ -4,9 +4,9 @@ marks: - get_uuid stages: - - name: request test resource install + - name: Install an instance of the hello-world resrouce request: - url: "{tavern.env_vars.ARM_URL}lifecycle/transitions" + url: "{api_url}lifecycle/transitions" method: POST json: deploymentLocation: "world" @@ -31,10 +31,9 @@ stages: json: req_id: requestId - - - name: get request status + - name: Get the request status request: - url: "{tavern.env_vars.ARM_URL}lifecycle/transitions/{req_id}/status" + url: "{api_url}lifecycle/transitions/{req_id}/status" method: GET response: status_code: 200 @@ -50,9 +49,9 @@ stages: json: res_id: resourceId - - name: get resource instance status + - name: Get the instance status request: - url: "{tavern.env_vars.ARM_URL}topology/instances/{res_id}" + url: "{api_url}topology/instances/{res_id}" method: GET response: status_code: 200 @@ -69,9 +68,9 @@ stages: resourceName: "test_{res_id}" resourceType: "resource::hello-world::1.0" - - name: get resource for location + - name: Query the location for the instance request: - url: "{tavern.env_vars.ARM_URL}topology/deployment-locations/world/instances" + url: "{api_url}topology/deployment-locations/world/instances" params: instanceName: "test_{res_id}" method: GET diff --git a/tests/api/test_resourcetype_api.tavern.yaml b/tests/api/test_resourcetype_api.tavern.yaml new file mode 100644 index 0000000..8ee3256 --- /dev/null +++ b/tests/api/test_resourcetype_api.tavern.yaml @@ -0,0 +1,51 @@ +test_name: resource type API + +strict: + - json:off + +marks: + - parametrize: + key: res_type + vals: + - "resource::hello-world::1.2" + - "resource::hello-worlds::1.0" + - "resource::hello-world:1.0" + + +stages: + - name: Get all resource types + request: + url: "{api_url}types" + method: GET + response: + status_code: 200 + json: + - name: "resource::hello-world::1.0" + state: "PUBLISHED" + - name: "resource::openstack-network::1.0" + state: "PUBLISHED" + + - name: Get resource type details by name + request: + url: "{api_url}types/resource::hello-world::1.0" + method: GET + response: + status_code: 200 + json: + name: "resource::hello-world::1.0" + state: "PUBLISHED" + descriptor: !anystr + + - name: Get resource type details by name, not found cases + request: + url: "{api_url}types/{res_type}" + method: GET + response: + status_code: 404 + json: + detail: !anystr + status: 404 + title: "Not Found" + type: "about:blank" + + diff --git a/tests/unit/test_topology_api.tavern.yaml b/tests/api/test_topology_api.tavern.yaml similarity index 67% rename from tests/unit/test_topology_api.tavern.yaml rename to tests/api/test_topology_api.tavern.yaml index e4dc2ee..cc7bb37 100644 --- a/tests/unit/test_topology_api.tavern.yaml +++ b/tests/api/test_topology_api.tavern.yaml @@ -3,7 +3,7 @@ test_name: topology API stages: - name: Get all deployment locations request: - url: "{tavern.env_vars.ARM_URL}topology/deployment-locations" + url: "{api_url}topology/deployment-locations" method: GET response: status_code: 200 @@ -13,7 +13,7 @@ stages: - name: Get a deployment location by name request: - url: "{tavern.env_vars.ARM_URL}topology/deployment-locations/world" + url: "{api_url}topology/deployment-locations/world" method: GET response: status_code: 200 @@ -21,9 +21,9 @@ stages: name: "world" type: "planet" - - name: Get a deployment location by name, not found + - name: Get a deployment location by name, not found cases request: - url: "{tavern.env_vars.ARM_URL}topology/deployment-locations/worlds" + url: "{api_url}topology/deployment-locations/worlds" method: GET response: status_code: 404 diff --git a/tests/conftest.py b/tests/conftest.py index 2e99d00..f7e1cdb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,3 +14,5 @@ def get_uuid(): return str(uuid.uuid1()) +def pytest_tavern_beta_before_every_test_run(test_dict, variables): + variables["api_url"] = "http://0.0.0.0:8080/api/v1.0/resource-manager/" \ No newline at end of file diff --git a/tests/unit/docker_test.py b/tests/docker_test.py similarity index 98% rename from tests/unit/docker_test.py rename to tests/docker_test.py index 0edf94f..aa26156 100644 --- a/tests/unit/docker_test.py +++ b/tests/docker_test.py @@ -1,7 +1,6 @@ import pytest import os import requests -import requests from urllib3.util.retry import Retry from requests.adapters import HTTPAdapter diff --git a/tests/features/helloworld11.csar b/tests/features/helloworld11.csar new file mode 100644 index 0000000..3812b8a Binary files /dev/null and b/tests/features/helloworld11.csar differ diff --git a/tests/features/helloworld11.zip b/tests/features/helloworld11.zip new file mode 100644 index 0000000..3812b8a Binary files /dev/null and b/tests/features/helloworld11.zip differ diff --git a/tests/features/helloworld_nodescriptoryaml.csar b/tests/features/helloworld_nodescriptoryaml.csar new file mode 100644 index 0000000..d4a6355 Binary files /dev/null and b/tests/features/helloworld_nodescriptoryaml.csar differ diff --git a/tests/features/helloworld_noinstall.csar b/tests/features/helloworld_noinstall.csar new file mode 100644 index 0000000..8bdbb20 Binary files /dev/null and b/tests/features/helloworld_noinstall.csar differ diff --git a/tests/features/helloworld_nolifecycle.csar b/tests/features/helloworld_nolifecycle.csar new file mode 100644 index 0000000..0bd84a1 Binary files /dev/null and b/tests/features/helloworld_nolifecycle.csar differ diff --git a/tests/features/helloworld_nomanifest.csar b/tests/features/helloworld_nomanifest.csar new file mode 100644 index 0000000..444bb84 Binary files /dev/null and b/tests/features/helloworld_nomanifest.csar differ diff --git a/tests/features/helloworld_nomanifestyaml.csar b/tests/features/helloworld_nomanifestyaml.csar new file mode 100644 index 0000000..97d2444 Binary files /dev/null and b/tests/features/helloworld_nomanifestyaml.csar differ diff --git a/tests/features/helloworld_nometainf.csar b/tests/features/helloworld_nometainf.csar new file mode 100644 index 0000000..49c9bc1 Binary files /dev/null and b/tests/features/helloworld_nometainf.csar differ diff --git a/tests/features/test_fulllifecycle_api.tavern.yaml b/tests/features/test_fulllifecycle_api.tavern.yaml new file mode 100644 index 0000000..1f0e8de --- /dev/null +++ b/tests/features/test_fulllifecycle_api.tavern.yaml @@ -0,0 +1,201 @@ +test_name: full package, location and instance lifecycle +marks: + - usefixtures: + - get_uuid + +stages: + - name: create a new deployment location MARS + request: + url: "{api_url}topology/deployment-locations/MARS" + method: PUT + json: + properties: + prop1: "this is a test" + prop2: "some other property" + type: "planet" + response: + status_code: 204 + + - name: check MARS exists + request: + url: "{api_url}topology/deployment-locations/MARS" + method: GET + response: + status_code: 200 + + - name: Upload a resource package + request: + url: "{api_url}types" + method: POST + data: + resource_name: "hello-world" + resource_version: "1.1" + files: + upfile: "features/helloworld11.csar" + response: + status_code: 200 + + - name: Verify the new resource type exists + request: + url: "{api_url}types/resource::hello-world::1.1" + method: GET + response: + status_code: 200 + json: + name: "resource::hello-world::1.1" + state: "PUBLISHED" + descriptor: !anystr + + - name: Install an instance of the new resource + request: + url: "{api_url}lifecycle/transitions" + method: POST + json: + deploymentLocation: "MARS" + metricKey: "{get_uuid}" + properties: + prop1: "nouse" + resourceManagerId: "ansible" + resourceName: "test_{get_uuid}" + resourceType: "resource::hello-world::1.1" + transitionName: "Install" + response: + status_code: 200 + json: + finishedAt: !anystr + requestFailureCode: "" + requestId: !anystr + requestState: "COMPLETED" + requestStateReason: !anystr + resourceId: !anystr + startedAt: !anystr + save: + json: + req_id: requestId + + - name: Check the install request state + request: + url: "{api_url}lifecycle/transitions/{req_id}/status" + method: GET + response: + status_code: 200 + json: + finishedAt: !anystr + requestFailureCode: "" + requestId: "{req_id}" + requestState: "COMPLETED" + requestStateReason: !anystr + resourceId: !anystr + startedAt: !anystr + save: + json: + res_id: resourceId + + - name: Query the location for the new instance + request: + url: "{api_url}topology/deployment-locations/MARS/instances" + data: + instanceType: "resource::hello-world::1.1" + method: GET + response: + status_code: 200 + json: + - resourceId: "{res_id}" + resourceName: "test_{res_id}" + resourceType: "resource::hello-world::1.1" + resourceManagerId: "ansible" + deploymentLocation: "MARS" + createdAt: !anystr + lastModifiedAt: !anystr + properties: + current_time: !anystr + prop1: "nouse" + + - name: Uninstall the instance of the new resource + request: + url: "{api_url}lifecycle/transitions" + method: POST + json: + deploymentLocation: "MARS" + metricKey: "{res_id}" + properties: + prop1: "nouse" + resourceManagerId: "ansible" + resourceName: "test_{res_id}" + resourceType: "resource::hello-world::1.1" + transitionName: "Uninstall" + response: + status_code: 200 + json: + finishedAt: !anystr + requestFailureCode: "" + requestId: !anystr + requestState: "COMPLETED" + requestStateReason: !anystr + resourceId: !anystr + startedAt: !anystr + save: + json: + req_id: requestId + + - name: Get the request status + request: + url: "{api_url}lifecycle/transitions/{req_id}/status" + method: GET + response: + status_code: 200 + json: + finishedAt: !anystr + requestFailureCode: "" + requestId: "{req_id}" + requestState: "COMPLETED" + requestStateReason: !anystr + resourceId: !anystr + startedAt: !anystr + + - name: Verify the instance is not longer part of the location + request: + url: "{api_url}topology/deployment-locations/MARS/instances" + data: + instanceType: "resource::hello-world::1.1" + method: GET + response: + status_code: 200 + json: [] + + - name: Delete location MARS + request: + url: "{api_url}topology/deployment-locations/MARS" + method: DELETE + response: + status_code: 200 + + - name: Verify MARS is gone + request: + url: "{api_url}topology/deployment-locations/MARS" + method: GET + response: + status_code: 404 + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/features/test_upload_api.tavern.yaml b/tests/features/test_upload_api.tavern.yaml new file mode 100644 index 0000000..0c689c1 --- /dev/null +++ b/tests/features/test_upload_api.tavern.yaml @@ -0,0 +1,55 @@ +test_name: package upload failures +strict: + - json:off + +marks: + - parametrize: + key: upfilename + vals: + - "features/helloworld_nodescriptoryaml.csar" + - "features/helloworld_noinstall.csar" + - "features/helloworld_nolifecycle.csar" + - "features/helloworld_nomanifest.csar" + - "features/helloworld_nomanifestyaml.csar" + - "features/helloworld_nometainf.csar" + +stages: + - name: upload a package, wrong resource name + request: + url: "{api_url}types" + method: POST + data: + resource_name: "wrong_name" + resource_version: "1.1" + files: + upfile: "features/helloworld11.csar" + response: + status_code: 400 + json: + detail: "no valid resource descriptor" + + - name: upload a package, wrong version + request: + url: "{api_url}types" + method: POST + data: + resource_name: "hello-world" + resource_version: "2.0" + files: + upfile: "features/helloworld11.csar" + response: + status_code: 400 + json: + detail: "no valid resource descriptor" + + - name: upload an invalid package + request: + url: "{api_url}types" + method: POST + data: + resource_name: "hello-world" + resource_version: "1.1" + files: + upfile: "{upfilename}" + response: + status_code: 400 diff --git a/tests/pytest.ini b/tests/pytest.ini index ffb595f..cb64ead 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -2,6 +2,6 @@ minversion = 6.0 testpaths = tests - unit + api features addopts = -ra -q --disable-warnings --docker-compose-no-build --use-running-containers --docker-compose="/Users/jochenkappel/Projects/arm_dev/osslm-ansible-resource-manager/alm-ansible-rm-docker-compose.yml" diff --git a/tests/unit/test_resourcetype_api.tavern.yaml b/tests/unit/test_resourcetype_api.tavern.yaml deleted file mode 100644 index 859eae9..0000000 --- a/tests/unit/test_resourcetype_api.tavern.yaml +++ /dev/null @@ -1,62 +0,0 @@ -test_name: resource type API - -stages: - - name: Get all resource types - request: - url: "{tavern.env_vars.ARM_URL}types" - method: GET - response: - status_code: 200 - json: - - name: "resource::hello-world::1.0" - state: "PUBLISHED" - - name: "resource::openstack-network::1.0" - state: "PUBLISHED" - - - name: Get resource type details by name - request: - url: "{tavern.env_vars.ARM_URL}types/resource::hello-world::1.0" - method: GET - response: - status_code: 200 - json: - name: "resource::hello-world::1.0" - state: "PUBLISHED" - descriptor: !anystr - - - name: Get resource type details by name, not found, wrong version - request: - url: "{tavern.env_vars.ARM_URL}types/resource::hello-world::1.1" - method: GET - response: - status_code: 404 - json: - detail: "resource type version 1.1 not found" - status: 404 - title: "Not Found" - type: "about:blank" - - - - name: Get resource type details by name, not found, wrong name - request: - url: "{tavern.env_vars.ARM_URL}types/resource::hello-worlds::1.0" - method: GET - response: - status_code: 404 - json: - detail: "resource type hello-worlds not found" - status: 404 - title: "Not Found" - type: "about:blank" - - - name: Get resource type details by name, not found, wrong format - request: - url: "{tavern.env_vars.ARM_URL}types/resource::hello-world:1.0" - method: GET - response: - status_code: 404 - json: - detail: "resource type resource::hello-world:1.0 not found. Invalid format. Should be resource::name::version" - status: 404 - title: "Not Found" - type: "about:blank" \ No newline at end of file