Skip to content

Commit

Permalink
Merge pull request #48 from CSCI-GA-2820-FA23-001/47_support_bdd_ci
Browse files Browse the repository at this point in the history
47 support bdd ci
  • Loading branch information
WYB929 authored Nov 21, 2023
2 parents 1fd6799 + 4556f27 commit 1619b2d
Show file tree
Hide file tree
Showing 12 changed files with 514 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Image for a NYU Lab development environment
FROM rofrano/nyu-devops-base:fa23
FROM rofrano/pipeline-selenium:latest

# Set up the Python development environment
WORKDIR /app
Expand Down
118 changes: 58 additions & 60 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,60 @@
// cSpell: disable
{
"name": "NYU Project",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/app",
"remoteUser": "vscode",
"customizations": {
"vscode": {
"settings": {
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"markdown-preview-github-styles.colorTheme": "light",
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/*.pyc": true,
"**/__pycache__": true,
"**/.pytest_cache": true
}
},
"extensions": [
"VisualStudioExptTeam.vscodeintellicode",
"ms-python.python",
"ms-python.pylint",
"ms-python.vscode-pylance",
"ms-python.black-formatter",
// "alexkrechik.cucumberautocomplete",
"cstrap.flask-snippets",
"yzhang.markdown-all-in-one",
"bierner.github-markdown-preview",
"hnw.vscode-auto-open-markdown-preview",
"DavidAnson.vscode-markdownlint",
"donjayamanne.githistory",
"GitHub.vscode-pull-request-github",
"hbenl.vscode-test-explorer",
"LittleFoxTeam.vscode-python-test-adapter",
"njpwerner.autodocstring",
"redhat.vscode-yaml",
"wholroyd.jinja",
"Zignd.html-css-class-completion",
"bbenoist.vagrant",
"rangav.vscode-thunder-client",
"ms-azuretools.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"streetsidesoftware.code-spell-checker"
]
}
},
//"postCreateCommand": "",

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": 8080,

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {}
}
}
"name": "NYU Project",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/app",
"remoteUser": "vscode",
"customizations": {
"vscode": {
"settings": {
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"markdown-preview-github-styles.colorTheme": "light",
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/*.pyc": true,
"**/__pycache__": true,
"**/.pytest_cache": true
}
},
"extensions": [
"VisualStudioExptTeam.vscodeintellicode",
"ms-python.python",
"ms-python.pylint",
"ms-python.vscode-pylance",
"ms-python.black-formatter",
"alexkrechik.cucumberautocomplete",
"cstrap.flask-snippets",
"yzhang.markdown-all-in-one",
"bierner.github-markdown-preview",
"hnw.vscode-auto-open-markdown-preview",
"DavidAnson.vscode-markdownlint",
"donjayamanne.githistory",
"GitHub.vscode-pull-request-github",
"hbenl.vscode-test-explorer",
"LittleFoxTeam.vscode-python-test-adapter",
"njpwerner.autodocstring",
"redhat.vscode-yaml",
"wholroyd.jinja",
"Zignd.html-css-class-completion",
"bbenoist.vagrant",
"rangav.vscode-thunder-client",
"ms-azuretools.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"streetsidesoftware.code-spell-checker"
]
}
},
//"postCreateCommand": "",
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": 8080,
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {}
}
}
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PORT=8000
FLASK_APP=service:app
WAIT_SECONDS=5
62 changes: 62 additions & 0 deletions .github/workflows/bdd-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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
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:
- uses: actions/checkout@v2

- name: Install OS dependencies
run: |
apt-get update
apt-get install -y gcc libpq-dev
- name: Install Python packages
run: |
python -m pip install --upgrade pip wheel
pip install -r requirements.txt
- name: Run the service locally
run: |
echo "\n*** STARTING APPLICATION ***\n"
gunicorn --log-level=critical --bind=0.0.0.0:8000 service:app &
sleep 5
curl -i http://localhost:8000/health
echo "\n*** SERVER IS RUNNING ***"
env:
DATABASE_URI: "postgresql://postgres:pgs3cr3t@postgres:5432/testdb"

- name: Run Integration Tests
run: behave
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
name: CI Build
name: TDD Tests
on:
push:
branches:
- master
paths-ignore:
- "README.md"
- ".vscode/**"

- "**.md"
pull_request:
branches:
- master
paths-ignore:
- "README.md"
- ".vscode/**"
- "**.md"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# NYU DevOps: Recommendation

[![Build Status](https://github.com/CSCI-GA-2820-FA23-001/recommendations/actions/workflows/workflow.yml/badge.svg)](https://github.com/CSCI-GA-2820-FA23-001/recommendations/actions)
[![Build Status](https://github.com/CSCI-GA-2820-FA23-001/recommendations/actions/workflows/tdd-tests/badge.svg)](https://github.com/CSCI-GA-2820-FA23-001/recommendations/actions)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Python](https://img.shields.io/badge/Language-Python-blue.svg)](https://python.org/)

Expand Down
47 changes: 47 additions & 0 deletions features/environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
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:8000")
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)
100 changes: 100 additions & 0 deletions features/recommendations.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Feature: The recommendation service back-end
As a Product Manager
I need a RESTful catalog service
So that I can keep track of all recommendations

Background:
Given the following recommendations

| id | source_item_id | target_item_id | type | weight | status | number_of_likes |
| 1 | 123 | 456 | UP_SELL | 0.5 | VALID | 10 |
| 2 | 789 | 101 | CROSS_SELL | 0.8 | OUT_OF_STOCK | 5 |
| 3 | 222 | 333 | ACCESSORY | 0.2 | DEPRECATED | 2 |


Scenario: The server is running
When I visit the "Home Page"
Then I should see "Recommendation Demo RESTful Service" in the title
And I should not see "404 Not Found"

# Scenario: Create a Pet
# When I visit the "Home Page"
# And I set the "Name" to "Happy"
# And I set the "Category" to "Hippo"
# And I select "False" in the "Available" dropdown
# And I select "Male" in the "Gender" dropdown
# And I set the "Birthday" to "06-16-2022"
# And I press the "Create" button
# Then I should see the message "Success"
# When I copy the "Id" field
# And I press the "Clear" button
# Then the "Id" field should be empty
# And the "Name" field should be empty
# And the "Category" field should be empty
# When I paste the "Id" field
# And I press the "Retrieve" button
# Then I should see the message "Success"
# And I should see "Happy" in the "Name" field
# And I should see "Hippo" in the "Category" field
# And I should see "False" in the "Available" dropdown
# And I should see "Male" in the "Gender" dropdown
# And I should see "2022-06-16" in the "Birthday" field

# Scenario: List all pets
# When I visit the "Home Page"
# And I press the "Search" button
# Then I should see the message "Success"
# And I should see "fido" in the results
# And I should see "kitty" in the results
# And I should not see "leo" in the results

# Scenario: Search for dogs
# When I visit the "Home Page"
# And I set the "Category" to "dog"
# And I press the "Search" button
# Then I should see the message "Success"
# And I should see "fido" in the results
# And I should not see "kitty" in the results
# And I should not see "leo" in the results

# Scenario: Search for available
# When I visit the "Home Page"
# And I select "True" in the "Available" dropdown
# And I press the "Search" button
# Then I should see the message "Success"
# And I should see "fido" in the results
# And I should see "kitty" in the results
# And I should see "sammy" in the results
# And I should not see "leo" in the results

# Scenario: Update a Pet
# When I visit the "Home Page"
# And I set the "Name" to "fido"
# And I press the "Search" button
# Then I should see the message "Success"
# And I should see "fido" in the "Name" field
# And I should see "dog" in the "Category" field
# When I change "Name" to "Loki"
# And I press the "Update" button
# Then I should see the message "Success"
# When I copy the "Id" field
# And I press the "Clear" button
# And I paste the "Id" field
# And I press the "Retrieve" button
# Then I should see the message "Success"
# And I should see "Loki" in the "Name" field
# When I press the "Clear" button
# And I press the "Search" button
# Then I should see the message "Success"
# And I should see "Loki" in the results
# And I should not see "fido" in the results

# Scenario: Delete a Pet
# When I visit the "Home Page"
# And I set the "Name" to "sammy"
# And I press the "Search" button
# Then I should see the message "Success"
# And I should see "sammy" in the "Name" field
# And I should see "snake" in the "Category" field
# When I press the "Delete" button
# Then I should see the message "Pet has been Deleted!"
Loading

0 comments on commit 1619b2d

Please sign in to comment.