generated from nyu-devops/project-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from CSCI-GA-2820-SP24-001/config-bdd
Config bdd
- Loading branch information
Showing
21 changed files
with
1,339 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: BDD Tests | ||
on: | ||
push: | ||
branches: | ||
- master | ||
paths-ignore: | ||
- "README.md" | ||
- ".vscode/**" | ||
- "**.md" | ||
pull_request: | ||
branches: | ||
- master | ||
paths-ignore: | ||
- "README.md" | ||
- ".vscode/**" | ||
- "**.md" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
container: rofrano/pipeline-selenium:latest | ||
|
||
services: | ||
postgres: | ||
image: postgres:15-alpine | ||
env: | ||
POSTGRES_PASSWORD: pgs3cr3t | ||
POSTGRES_DB: testdb | ||
ports: | ||
- 5432:5432 | ||
# Set health checks to wait until postgres has started | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install -U pip poetry | ||
poetry config virtualenvs.create false | ||
poetry install | ||
- name: Run the service locally | ||
run: | | ||
echo "\n*** STARTING APPLICATION ***\n" | ||
gunicorn --log-level=info --bind=0.0.0.0:8080 wsgi:app & | ||
echo "Waiting for service to stabilize..." | ||
sleep 5 | ||
echo "Checking service /health..." | ||
curl -i http://localhost:8080/health | ||
echo "\n*** SERVER IS RUNNING ***" | ||
env: | ||
DATABASE_URI: "postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/testdb" | ||
|
||
- name: Run Integration Tests | ||
run: behave |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
Environment for Behave Testing | ||
""" | ||
from os import getenv | ||
from selenium import webdriver | ||
|
||
WAIT_SECONDS = int(getenv('WAIT_SECONDS', '60')) | ||
BASE_URL = getenv('BASE_URL', 'http://localhost:8080') | ||
DRIVER = getenv('DRIVER', 'chrome').lower() | ||
|
||
|
||
def before_all(context): | ||
""" Executed once before all tests """ | ||
context.base_url = BASE_URL | ||
context.wait_seconds = WAIT_SECONDS | ||
# Select either Chrome or Firefox | ||
if 'firefox' in DRIVER: | ||
context.driver = get_firefox() | ||
else: | ||
context.driver = get_chrome() | ||
context.driver.implicitly_wait(context.wait_seconds) | ||
context.config.setup_logging() | ||
|
||
|
||
def after_all(context): | ||
""" Executed after all tests """ | ||
context.driver.quit() | ||
|
||
###################################################################### | ||
# Utility functions to create web drivers | ||
###################################################################### | ||
|
||
def get_chrome(): | ||
"""Creates a headless Chrome driver""" | ||
options = webdriver.ChromeOptions() | ||
options.add_argument("--no-sandbox") | ||
options.add_argument("--headless") | ||
return webdriver.Chrome(options=options) | ||
|
||
|
||
def get_firefox(): | ||
"""Creates a headless Firefox driver""" | ||
options = webdriver.FirefoxOptions() | ||
options.add_argument("--headless") | ||
return webdriver.Firefox(options=options) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Feature: The promotion store service back-end | ||
As a promotion Store Owner | ||
I need a RESTful catalog service | ||
So that I can keep track of all my promotions | ||
|
||
Background: | ||
Given the following promotions | ||
| cust_promo_code | type | value | quantity | start_date | end_date | active | product_id | dev_created_at | | ||
| JULY4 | SAVING | 50 | 10 | 2024-03-05 | 2024-03-10 | True | 33422 | 2024-03-05 | | ||
| JUN2 | BOGO | 20 | 5 | 2024-03-05 | 2024-03-10 | True | 2928383 | 2024-03-05 | | ||
|
||
Scenario: The server is running | ||
When I visit the "Home Page" | ||
Then I should see "promotion Demo RESTful Service" in the title | ||
And I should not see "404 Not Found" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
###################################################################### | ||
# Copyright 2016, 2023 John J. Rofrano. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
###################################################################### | ||
|
||
""" | ||
promotion Steps | ||
Steps file for promotion.feature | ||
For information on Waiting until elements are present in the HTML see: | ||
https://selenium-python.readthedocs.io/waits.html | ||
""" | ||
import requests | ||
from behave import given | ||
|
||
# HTTP Return Codes | ||
HTTP_200_OK = 200 | ||
HTTP_201_CREATED = 201 | ||
HTTP_204_NO_CONTENT = 204 | ||
|
||
|
||
@given("the following promotions") | ||
def step_impl(context): | ||
"""Delete all promotions and load new ones""" | ||
|
||
# List all of the promotions and delete them one by one | ||
rest_endpoint = f"{context.base_url}/promotions" | ||
context.resp = requests.get(rest_endpoint) | ||
assert context.resp.status_code == HTTP_200_OK | ||
for promotion in context.resp.json(): | ||
context.resp = requests.delete(f"{rest_endpoint}/{promotion['id']}") | ||
assert context.resp.status_code == HTTP_204_NO_CONTENT | ||
|
||
# load the database with new promotions | ||
for row in context.table: | ||
payload = { | ||
"cust_promo_code": row["cust_promo_code"], | ||
"type": row["type"], | ||
"value": row["value"], | ||
"quantity": row["quantity"], | ||
"start_date": row["start_date"], | ||
"end_date": row["end_date"], | ||
"active": row["active"] in ["True", "true", "1"], | ||
"product_id": row["product_id"], | ||
"dev_created_at": row["dev_created_at"] | ||
} | ||
context.resp = requests.post(rest_endpoint, json=payload) | ||
assert context.resp.status_code == HTTP_201_CREATED |
Oops, something went wrong.