From f3905ce4869249e25cb244a39dbc1bb144760f00 Mon Sep 17 00:00:00 2001 From: Yan <100032599+whykay-01@users.noreply.github.com> Date: Thu, 25 Apr 2024 01:50:45 +0000 Subject: [PATCH] feat: fixed BDD and added create a shopcart endpoint --- features/{environment => environment.py} | 0 features/shopcarts.feature | 32 +++++++++++++++++++ .../{shopcarts_steps => shopcarts_steps.py} | 12 +++---- features/steps/{web_steps => web_steps.py} | 3 +- 4 files changed, 40 insertions(+), 7 deletions(-) rename features/{environment => environment.py} (100%) rename features/steps/{shopcarts_steps => shopcarts_steps.py} (89%) rename features/steps/{web_steps => web_steps.py} (98%) diff --git a/features/environment b/features/environment.py similarity index 100% rename from features/environment rename to features/environment.py diff --git a/features/shopcarts.feature b/features/shopcarts.feature index e69de29..178d3d4 100644 --- a/features/shopcarts.feature +++ b/features/shopcarts.feature @@ -0,0 +1,32 @@ + +Feature: The shopcarts service back-end + As a Shopcarts Service Owner + I need a RESTful catalog service + So that I can keep track of all my shopcarts + + Background: + Given the following shopcarts + | user_id | + | 1 | + | 2 | + | 3 | + And the following items + | user_id | product_name | product_id | product_price | quantity | + | 1 | MacBook 13 Pro | 1 | 1500.0 | 2 | + | 2 | MacBook 13 Air | 2 | 1000.0 | 1 | + | 2 | MacBook 13 Pro | 1 | 1500.0 | 1 | + | 1 | MacBook 15 Air | 3 | 1200.0 | 3 | + | 3 | MacBook 15 Pro | 4 | 2700.0 | 1 | + + + Scenario: The server is running + When I visit the "Home Page" + Then I should see "Shopcart Demo RESTful Service" in the title + And I should not see "404 Not Found" + + Scenario: Create a shopcart + When I visit the "Home Page" + And I set the "Shopcart User ID" to "10" + And I press the "Create Shopcart" button + Then I should see the message "Success" + diff --git a/features/steps/shopcarts_steps b/features/steps/shopcarts_steps.py similarity index 89% rename from features/steps/shopcarts_steps rename to features/steps/shopcarts_steps.py index fedd415..3ae1134 100644 --- a/features/steps/shopcarts_steps +++ b/features/steps/shopcarts_steps.py @@ -30,13 +30,12 @@ def step_impl(context): # Load the database with new shopcarts for row in context.table: - payload = {"user_id": row["user_id"]} - + payload = {"user_id": row["user_id"], "items": []} context.resp = requests.post(rest_endpoint, json=payload) assert context.resp.status_code == HTTP_201_CREATED -@given("the following cartitems") +@given("the following items") def step_impl(context): """Delete all cart items and load new ones""" @@ -51,12 +50,13 @@ def step_impl(context): # Load the database with new shopcarts for row in context.table: user_id = row["user_id"] - shopcart_id = shopcarts.get(int(user_id), None) + shopcart_id = int(shopcarts[user_id]) payload = { - "product_price": row["product_price"], + "cart_id": shopcart_id, + "product_name": row["product_name"], "product_id": row["product_id"], + "product_price": row["product_price"], "quantity": row["quantity"], - "shopcart_id": shopcart_id, } rest_endpoint = f"{context.base_url}/shopcarts/{shopcart_id}/items" diff --git a/features/steps/web_steps b/features/steps/web_steps.py similarity index 98% rename from features/steps/web_steps rename to features/steps/web_steps.py index 4050fa4..f9b0cff 100644 --- a/features/steps/web_steps +++ b/features/steps/web_steps.py @@ -12,6 +12,7 @@ from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select, WebDriverWait from selenium.webdriver.support import expected_conditions +import requests # ID_PREFIX = "pet_" @@ -48,7 +49,7 @@ def step_impl(context, message): @when('I press the "{button}" button') def step_impl(context, button): """Presses button on the UI""" - button_id = button.lower() + "-btn" + button_id = button.replace(" ", "-").lower() + "-btn" context.driver.find_element(By.ID, button_id).click()