diff --git a/test/gherkin/assets/Default_Cover_Image.jpg b/test/gherkin/assets/Default_Cover_Image.jpg new file mode 100644 index 0000000..d8d5e4c Binary files /dev/null and b/test/gherkin/assets/Default_Cover_Image.jpg differ diff --git a/test/gherkin/assets/Sports.jpg b/test/gherkin/assets/Sports.jpg new file mode 100644 index 0000000..2e3b4d9 Binary files /dev/null and b/test/gherkin/assets/Sports.jpg differ diff --git a/test/gherkin/behave.ini b/test/gherkin/behave.ini index a2cb467..c02d2be 100644 --- a/test/gherkin/behave.ini +++ b/test/gherkin/behave.ini @@ -2,3 +2,10 @@ paths = features/ +stderr_capture=False +stdout_capture=False + +[behave.userdata] +base_url = https://api.bb-consent.dev/v2 +username = admin@localretail.com +password = qwerty123 \ No newline at end of file diff --git a/test/gherkin/steps/getting_started.py b/test/gherkin/steps/getting_started.py new file mode 100644 index 0000000..d56e0ca --- /dev/null +++ b/test/gherkin/steps/getting_started.py @@ -0,0 +1,76 @@ +from behave import * +import requests +import json + + +@given("the admin is logged into the Admin dashboard") +def step_impl(context): + username = context.config.userdata.get("username") + password = context.config.userdata.get("password") + base_url = context.config.userdata.get("base_url") + data = { + "username": username, + "password": password, + } + url = base_url + "/onboard/admin/login" + response = requests.post(url, json=data, verify=False) + response_json = json.loads(response.content) + context.access_token = response_json["accessToken"] + + +@when("the admin updates the organization name, description, location, and policy URL") +def step_impl(context): + base_url = context.config.userdata.get("base_url") + data = { + "organisation": { + "name": "Retail company", + "description": "Retail electronic company", + "sector": "Retail", + "location": "Sweden", + "policyUrl": "http://localhost.com", + } + } + headers = {"Authorization": f"Bearer {context.access_token}"} + url = base_url + "/onboard/organisation" + response = requests.put(url, json=data, verify=False, headers=headers) + response_json = json.loads(response.content) + context.response = response + + +@then("the organization information should be updated") +def step_impl(context): + assert context.response.status_code == 200 + + +@when("the admin updates the organization logo and cover image") +def step_impl(context): + base_url = context.config.userdata.get("base_url") + + headers = { + "Authorization": f"Bearer {context.access_token}" + } + logo_file_path = "assets/Sports.jpg" + cover_image_file_path = "assets/Default_Cover_Image.jpg" + + # update logo image + files = { + "orgimage": ("Sports.jpg", open(logo_file_path, "rb")), + } + url = base_url + "/onboard/organisation/logoimage" + response = requests.post(url, files=files, verify=False, headers=headers) + context.response_logo_image = response + + # update cover image + files = { + "orgimage": ("Default_Cover_Image.jpg", open(cover_image_file_path, "rb")), + } + url = base_url + "/onboard/organisation/coverimage" + response = requests.post(url, files=files, verify=False, headers=headers) + context.response_cover_image = response + + +@then("the logo and cover image should be updated") +def step_impl(context): + + assert context.response_logo_image.status_code == 200 + assert context.response_cover_image.status_code == 200 diff --git a/test/gherkin/steps/login.py b/test/gherkin/steps/login.py index 68fd190..88a189b 100644 --- a/test/gherkin/steps/login.py +++ b/test/gherkin/steps/login.py @@ -1,5 +1,6 @@ from behave import * import requests +import json @given("an organization admin for Data4Diabetes organization") @@ -9,15 +10,20 @@ def step_impl(context): @when("the admin logs into the Admin dashboard") def step_impl(context): + username = context.config.userdata.get("username") + password = context.config.userdata.get("password") + base_url = context.config.userdata.get("base_url") data = { - "username": "admin@retail.com", - "password": "qwerty123", + "username": username, + "password": password, } - url = "https://staging-consent-bb-api.igrant.io/v2" + "/onboard/admin/login" - response = requests.post(url, json=data) + url = base_url + "/onboard/admin/login" + response = requests.post(url, json=data,verify=False) context.response = response @then("the admin should be able to access pages in the admin dashboard") def step_impl(context): + response_json = json.loads(context.response.content) + context.access_token = response_json["accessToken"] assert context.response.status_code == 200