Skip to content

Commit

Permalink
Add #34 Add BDD test for getting started page
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa authored and georgepadayatti committed Nov 3, 2023
1 parent f22a206 commit 34e1235
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
Binary file added test/gherkin/assets/Default_Cover_Image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/gherkin/assets/Sports.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions test/gherkin/behave.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
paths = features/


stderr_capture=False
stdout_capture=False

[behave.userdata]
base_url = https://api.bb-consent.dev/v2
username = [email protected]
password = qwerty123
76 changes: 76 additions & 0 deletions test/gherkin/steps/getting_started.py
Original file line number Diff line number Diff line change
@@ -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
14 changes: 10 additions & 4 deletions test/gherkin/steps/login.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from behave import *
import requests
import json


@given("an organization admin for Data4Diabetes organization")
Expand All @@ -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": "[email protected]",
"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

0 comments on commit 34e1235

Please sign in to comment.