Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧒🏻 Docker, pytest and cypress setups #819

Merged
merged 34 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
91d88fe
test: Add initial structure for the frontend and backend tests, updat…
HamzaAnis Nov 14, 2023
f24763c
Added more test cases and loading url from .env
HamzaAnis Nov 16, 2023
3b3bd94
test: remove unwanted test
HamzaAnis Nov 16, 2023
8b9ebd7
Fixed formatting issues
HamzaAnis Nov 16, 2023
e8f4812
Fixed formatting issues for backend
HamzaAnis Nov 16, 2023
03121b8
Fixed formatting issues for test_mentor_auth.py
HamzaAnis Nov 16, 2023
ca21201
Merge branch 'dev' into tests/structure
HamzaAnis Nov 21, 2023
b37ef8d
tests: added more backend and frontend test
HamzaAnis Nov 24, 2023
add73c0
Merge branch 'dev' into tests/structure
HamzaAnis Nov 30, 2023
971797a
tests: added more tests and github actions for the tests
HamzaAnis Dec 3, 2023
c769d02
Merge branch 'dev' into tests/structure
HamzaAnis Dec 12, 2023
e999b1d
test cases done 👏
HamzaAnis Dec 12, 2023
c2331e0
chore: fixed formatting of backend
HamzaAnis Dec 12, 2023
cc52192
Updated the action to be trigerred on PR for dev
HamzaAnis Dec 14, 2023
8ef6ab7
test: added admin tests
HamzaAnis Dec 21, 2023
818d2a0
Merge branch 'dev' into tests/structure
HamzaAnis Dec 21, 2023
e04e5a6
Added test cases for the admin
HamzaAnis Dec 27, 2023
10788d8
Update cypress-tests.yml
HamzaAnis Dec 29, 2023
c342877
Update pytest-tests.yml
HamzaAnis Dec 29, 2023
c4ccbc0
Update pytest-tests.yml
HamzaAnis Dec 29, 2023
376ce5b
frontend action change
HamzaAnis Dec 29, 2023
dc2c4de
testing action
HamzaAnis Dec 31, 2023
25a6a08
fixed test cases and updated push branch
HamzaAnis Jan 2, 2024
10b845e
Debugging the actions
HamzaAnis Jan 2, 2024
d36d760
Running backend tests in the same action
HamzaAnis Jan 2, 2024
69fac33
Removed on push
HamzaAnis Jan 2, 2024
964395e
Updating actions
HamzaAnis Jan 2, 2024
f1fec7e
New action
HamzaAnis Jan 3, 2024
b0dbf61
Removed files that are in .gitignore
HamzaAnis Jan 3, 2024
2d576ee
Adding package.json
HamzaAnis Jan 3, 2024
76fa0d3
Reading the env variables
HamzaAnis Jan 3, 2024
13a08ef
Reordering the action
HamzaAnis Jan 3, 2024
868d822
Cleaning up and formatting
HamzaAnis Jan 3, 2024
52cbe0d
Asserting response
HamzaAnis Jan 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LABEL maintainer "Kelley Chau <[email protected]>"

COPY requirements.txt requirements.txt
RUN apt-get update -y && \
apt-get install -y python-pip python-dev
apt-get install -y python3-dev python3-pkg-resources python3-setuptools python3-wheel python3-pip

RUN pip install -r requirements.txt

Expand All @@ -13,4 +13,4 @@ WORKDIR /app

ENTRYPOINT [ "python" ]

CMD [ "manage.py", "runprod" ]
CMD [ "manage.py", "runprod" ]
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pymongo==4.6.0 ; python_version >= "3.8" and python_version < "4.0"
pyparsing==3.0.9 ; python_version >= "3.8" and python_version < "4.0"
pypdf2==3.0.1 ; python_version >= "3.8" and python_version < "4.0"
pyrebase4==4.6.0 ; python_version >= "3.8" and python_version < "4.0"
pytest==7.3.2 ; python_version >= "3.8" and python_version < "4.0"
python-dateutil==2.8.2 ; python_version >= "3.8" and python_version < "4.0"
python-dotenv==1.0.0 ; python_version >= "3.8" and python_version < "4.0"
python-editor==1.0.4 ; python_version >= "3.8" and python_version < "4.0"
Expand Down
26 changes: 3 additions & 23 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,19 @@
import tempfile
import time
from unittest import mock

import pytest
from flask_migrate import Migrate

from api import create_app


@pytest.fixture(scope="session")
def postgres():
"""
The postgres Fixture. Starts a postgres instance inside a temp directory
and closes it after tests are done.
"""
with testing.postgresql.Postgresql() as postgresql:
yield postgresql


# We spin up a temporary postgres instance
# in which we inject it into the app
@pytest.fixture(scope="session")
def client(postgres):
config_dict = {
"SQLALCHEMY_DATABASE_URI": postgres.url(),
"DEBUG": True,
"SQLALCHEMY_TRACK_MODIFICATIONS": False,
}
app = create_app(config_dict)
def client():
app = create_app()
app.app_context().push()

time.sleep(2)
from api.models import db

db.create_all()
# for test client api reference
# http://flask.pocoo.org/docs/1.0/api/#test-client
client = app.test_client()
yield client
23 changes: 2 additions & 21 deletions backend/tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
from api.models import db, Person
from api.models import db


# client passed from client - look into pytest for more info about fixtures
# test client api: http://flask.pocoo.org/docs/1.0/api/#test-client
def test_index(client):
rs = client.get("/")
rs = client.get("/api/translation/")
assert rs.status_code == 200


def test_get_person(client):
rs = client.get("/persons")

assert rs.status_code == 200
ret_dict = rs.json # gives you a dictionary
assert ret_dict["success"] == True
assert ret_dict["result"]["persons"] == []

# create Person and test whether it returns a person
temp_person = Person(name="Tim")
db.session.add(temp_person)
db.session.commit()

rs = client.get("/persons")
ret_dict = rs.json
assert len(ret_dict["result"]["persons"]) == 1
assert ret_dict["result"]["persons"][0]["name"] == "Tim"
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ services:
container_name: mentee-backend
build: ./backend
ports:
- '5000:5000'
- '8000:8000'
env_file:
- ./backend/.env
14 changes: 14 additions & 0 deletions mentee test case/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
watchForFileChanges:false,
ensureScrollable: true,
parseSpecialCharSequences: false,
defaultCommandTimeout:4000,

setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
9 changes: 9 additions & 0 deletions mentee test case/cypress/e2e/pages/ApplyPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class ApplyPage{
url() {
cy.url().then((url) => {
const extendedURL = url + '/apply';
cy.visit(extendedURL)
})
cy.url().should('include', '/apply')
}
}
34 changes: 34 additions & 0 deletions mentee test case/cypress/e2e/pages/HomePage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@


export class HomePage {
componentExist() {
cy.url().should('eq', 'https://mentee-dev.herokuapp.com/')
HamzaAnis marked this conversation as resolved.
Show resolved Hide resolved
cy.get('.css-mznafe').should('exist').and('have.attr', 'xmlns', 'http://www.w3.org/2000/svg').should('be.visible')

cy.get('.ant-space-horizontal').should('exist').should('be.visible')
cy.get('span.anticon.anticon-form.css-15ifzd0').should('exist').and('have.attr', 'aria-label', 'form').should('be.visible')
cy.get('span.anticon.anticon-global.ant-dropdown-trigger.css-c1sjzn').should('exist').and('have.attr', 'aria-label', 'global').should('be.visible')

cy.get('span.anticon.anticon-user').should('exist').and('have.attr', 'aria-label', 'user').should('be.visible')
cy.get('[style=""] > .ant-card').should('have.attr', 'class', 'ant-card ant-card-bordered css-ot64mz css-wxm1m1').and('contain', 'Existing').should('be.visible')
cy.get('span.anticon.anticon-right-circle').should('exist').and('have.attr', 'aria-label', 'right-circle').should('be.visible')
cy.get('.ant-card-meta-description').should('contain', 'Platform Login').should('be.visible')

cy.get('span.anticon.anticon-usergroup-add').should('exist').and('have.attr', 'aria-label', 'usergroup-add').should('be.visible')
cy.get(':nth-child(2) > .ant-card').should('have.attr', 'class', 'ant-card ant-card-bordered css-ot64mz css-wxm1m1').and('contain', 'New').should('be.visible')
cy.get('span.anticon.anticon-right-circle').should('exist').and('have.attr', 'aria-label', 'right-circle').should('be.visible')
cy.get('.ant-card-meta-description').should('exist').and('contain', 'Apply - Train - Build').should('be.visible')

cy.get('.css-5lbmdi').should('exist').and('be.visible').and('have.attr', 'xmlns', 'http://www.w3.org/2000/svg')

}

isClickable() {
cy.url().should('eq', 'https://mentee-dev.herokuapp.com/')
HamzaAnis marked this conversation as resolved.
Show resolved Hide resolved
cy.get('.css-mznafe').should('have.css', 'cursor', 'pointer').and('be.visible')
cy.get('span.anticon.anticon-form.css-15ifzd0').should('have.css', 'cursor', 'pointer')
cy.get('span.anticon.anticon-global.ant-dropdown-trigger.css-c1sjzn').should('have.css', 'cursor', 'pointer')
cy.get('.ant-card.ant-card-bordered.css-ot64mz.css-wxm1m1').should('have.css', 'cursor', 'pointer')
cy.get('.ant-space-item').should('have.css', 'cursor', 'pointer')
}
}
11 changes: 11 additions & 0 deletions mentee test case/cypress/e2e/test/ApplyPageTest.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe } from "mocha";

describe('Apply Page', () => {
beforeEach('Open Apply Page', () => {
// TODO: Will add base url from config
cy.visit('https://mentee-dev.herokuapp.com/apply')
HamzaAnis marked this conversation as resolved.
Show resolved Hide resolved
})

it('Existance of Apply Page Components ', () => {
})
})
38 changes: 38 additions & 0 deletions mentee test case/cypress/e2e/test/HomePageTest.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { HomePage } from "../pages/HomePage"

const homePage = new HomePage()

describe('HomePage', () => {
beforeEach('Open Home Page', () => {
cy.visit('https://mentee-dev.herokuapp.com/')
HamzaAnis marked this conversation as resolved.
Show resolved Hide resolved
})

it('Existance of Home Page Components', () => {
homePage.componentExist()
})

it('Clickable components at Home Page ', () => {
homePage.isClickable()
})

it('should check the behavior upon click Mentee Logo', () => {
cy.url().should('eq', 'https://mentee-dev.herokuapp.com/')
cy.get('.css-mznafe').click()
cy.url().should('include', '/mentee-dev.herokuapp.com');
cy.get('.css-5lbmdi').should('be.visible');
})

it('should check the behavior upon Hover on "Report A Bug" Icon', () => {
cy.url().should('eq', 'https://mentee-dev.herokuapp.com/')
cy.get('.anticon.anticon-form.css-15ifzd0').trigger('mouseover')
cy.get('.ant-tooltip-inner').should('be.visible')
})

it('should check the behavior upon Hover or click on "Global" Icon', () => {
cy.url().should('eq', 'https://mentee-dev.herokuapp.com/')
cy.get('.anticon.anticon-global.ant-dropdown-trigger.css-c1sjzn').click()
cy.get('.anticon.anticon-global.ant-dropdown-trigger.css-c1sjzn').trigger('mouseover')
cy.get('.ant-dropdown-menu.ant-dropdown-menu-root.ant-dropdown-menu-vertical.ant-dropdown-menu-light.css-wxm1m1').should('be.visible')
cy.url().should('include', '/mentee-dev.herokuapp.com')
})
})
5 changes: 5 additions & 0 deletions mentee test case/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
25 changes: 25 additions & 0 deletions mentee test case/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
Empty file.
21 changes: 21 additions & 0 deletions mentee test case/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import 'cypress-plugin-api'

// Alternatively you can use CommonJS syntax:
// require('./commands')