Skip to content

Commit

Permalink
Send default project in payload for runbooks with endpoint tests
Browse files Browse the repository at this point in the history
(cherry picked from commit 8d050d0f6b9e1580d4ef1911fd3bebf1eb774ab1)
  • Loading branch information
bhati-pradeep authored and abhijeetkaurav1st committed Mar 13, 2022
1 parent 77ba35a commit 882e9a2
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion tests/api_interface/test_runbooks/test_runbooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from calm.dsl.cli.main import get_api_client
from calm.dsl.cli.constants import RUNLOG
from calm.dsl.api.project import ProjectAPI
from calm.dsl.config.context import get_context
from calm.dsl.runbooks import create_endpoint_payload
from tests.sample_runbooks import DslSimpleRunbook
from utils import (
Expand All @@ -21,6 +23,41 @@


class TestRunbooks:

default_project_reference = None

def get_default_project_reference(self):
"""This method gets default project reference"""

if TestRunbooks.default_project_reference:
return TestRunbooks.default_project_reference

context_obj = get_context()
client = get_api_client()
project_config = context_obj.get_project_config()
project_name = project_config["name"]

project_obj = ProjectAPI(client.connection)
params = {"filter": "name=={}".format(project_name)}
res, err = project_obj.list(params=params)
if err:
pytest.fail("[{}] - {}".format(err["code"], err["error"]))

res = res.json()
entities = res.get("entities", None)
if not entities:
pytest.fail("No project with name {} exists".format(project_name))

project_uuid = entities[0]["metadata"]["uuid"]

project_ref = {
"kind": "project",
"uuid": project_uuid,
"name": project_name,
}
TestRunbooks.default_project_reference = project_ref
return project_ref

@pytest.mark.runbook
@pytest.mark.regression
def test_runbooks_list(self):
Expand Down Expand Up @@ -48,6 +85,8 @@ def test_rb_crud(self):
client = get_api_client()
runbook = change_uuids(RunbookPayload, {})

runbook["metadata"]["project_reference"] = self.get_default_project_reference()

# Runbook Create
res, err = client.runbook.create(runbook)
if err:
Expand Down Expand Up @@ -298,6 +337,8 @@ def test_rb_execute_with_deleted_ep(self):
client = get_api_client()
runbook = change_uuids(RunbookPayload, {})

runbook["metadata"]["project_reference"] = self.get_default_project_reference()

# Runbook Create
res, err = client.runbook.create(runbook)
if err:
Expand Down Expand Up @@ -377,4 +418,4 @@ def test_rb_execute_with_deleted_ep(self):
assert res.ok is True
res = res.json()
print("API Response: {}".format(res["description"]))
print(">> Delete call to runbook is successful >>")
print(">> Delete call to runbook is successful >>")

0 comments on commit 882e9a2

Please sign in to comment.