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 all commits
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
87 changes: 87 additions & 0 deletions .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Frontend Tests

on:
pull_request:
branches:
- dev

jobs:
build-and-test:
runs-on: ubuntu-latest
env:
MONGO_USER: ${{ secrets.MONGO_USER }}
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
MONGO_HOST: ${{ secrets.MONGO_HOST }}
MONGO_DB: ${{ secrets.MONGO_DB }}
FIREBASE_SERVICE_KEY: ${{ secrets.FIREBASE_SERVICE_KEY }}
FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }}
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
IMGUR_KEY: ${{ secrets.IMGUR_KEY }}

SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
SENDER_EMAIL: ${{ secrets.SENDER_EMAIL }}
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
TWILIO_AUTH_TOKEN: ${{ secrets.TWILIO_AUTH_TOKEN }}
TWILIO_PHONE: ${{ secrets.TWILIO_PHONE }}
FLASK_APP: ${{ secrets.FLASK_APP }}

BASE_URL: ${{ secrets.BASE_URL }}
MENTOR_EMAIL: ${{ secrets.TEST_MENTOR_EMAIL }}
MENTEE_EMAIL: ${{ secrets.TEST_MENTEE_EMAIL }}
PARTNER_EMAIL: ${{ secrets.TEST_PARTNER_EMAIL }}
GUEST_EMAIL: ${{ secrets.TEST_GUEST_EMAIL }}
MENTOR_PASSWORD: ${{ secrets.TEST_MENTOR_PASSWORD }}
MENTEE_PASSWORD: ${{ secrets.TEST_MENTEE_PASSWORD }}
PARTNER_PASSWORD: ${{ secrets.TEST_PARTNER_PASSWORD }}
GUEST_PASSWORD: ${{ secrets.TEST_GUEST_PASSWORD }}
MENTEE_PROFILE_ID: ${{ secrets.TEST_MENTEE_PROFILE_ID }}
MENTOR_PROFILE_ID: ${{ secrets.TEST_MENTOR_PROFILE_ID }}
PARTNER_PROFILE_ID: ${{ secrets.TEST_PARTNER_PROFILE_ID }}
GUEST_PROFILE_ID: ${{ secrets.TEST_GUEST_PROFILE_ID }}
CYPRESS_ENV: ${{ secrets.CYPRESS_ENV }}
CYPRESS_BASE_URL: ${{ secrets.CYPRESS_BASE_URL }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build and run Backend
run: |
cd backend
touch firebase_service_key.json
echo "$FIREBASE_SERVICE_KEY" > firebase_service_key.json
cp firebase_service_key.json ./tests
docker build -t backend .
docker run --name backend -d -e SENDGRID_API_KEY="$SENDGRID_API_KEY" -e SENDER_EMAIL="$SENDER_EMAIL" -e TWILIO_ACCOUNT_SID="$TWILIO_ACCOUNT_SID" -e TWILIO_AUTH_TOKEN="$TWILIO_AUTH_TOKEN" -e TWILIO_PHONE="$TWILIO_PHONE" -e FLASK_APP="$FLASK_APP" -e IMGUR_KEY="$IMGUR_KEY" -e FIREBASE_API_KEY="$FIREBASE_API_KEY" -e MONGO_USER="$MONGO_USER" -e MONGO_PASSWORD="$MONGO_PASSWORD" -e MONGO_HOST="$MONGO_HOST" -e MONGO_DB="$MONGO_DB" -e GOOGLE_APPLICATION_CREDENTIALS="$GOOGLE_APPLICATION_CREDENTIALS" -p 8000:8000 backend

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Build and run Frontend
run: |
cd frontend
docker build -t frontend-app .
docker run --name frontend-app -d -e REACT_APP_FIREBASE_API_KEY="$FIREBASE_API_KEY" -p 3000:3000 frontend-app

- name: Wait for Frontend to be ready
run: |
retries=100
until curl -sSf http://localhost:3000; do
((retries--)) || exit 1
sleep 1
done

- name: Create cypress.env.json
run: |
cd tests
rm cypress.env.json
touch cypress.env.json
echo "$CYPRESS_ENV" > cypress.env.json

- name: Run Cypress Tests
run: |
npm install
cd tests
CYPRESS_BASE_URL="$CYPRESS_BASE_URL" npx cypress run --headless
68 changes: 68 additions & 0 deletions .github/workflows/pytest-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Backend Tests

on:
pull_request:
branches:
- dev

jobs:
build-and-test:
runs-on: ubuntu-latest
env:
MONGO_USER: ${{ secrets.MONGO_USER }}
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
MONGO_HOST: ${{ secrets.MONGO_HOST }}
MONGO_DB: ${{ secrets.MONGO_DB }}
FIREBASE_SERVICE_KEY: ${{ secrets.FIREBASE_SERVICE_KEY }}
FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }}
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
IMGUR_KEY: ${{ secrets.IMGUR_KEY }}
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
SENDER_EMAIL: ${{ secrets.SENDER_EMAIL }}
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
TWILIO_AUTH_TOKEN: ${{ secrets.TWILIO_AUTH_TOKEN }}
TWILIO_PHONE: ${{ secrets.TWILIO_PHONE }}
FLASK_APP: ${{ secrets.FLASK_APP }}

BASE_URL: ${{ secrets.BASE_URL }}
TEST_MENTOR_EMAIL: ${{ secrets.TEST_MENTOR_EMAIL }}
TEST_MENTOR_PASSWORD: ${{ secrets.TEST_MENTOR_PASSWORD }}
TEST_MENTOR_PHONE_NUMBER: ${{ secrets.TEST_MENTOR_PHONE_NUMBER }}
TEST_MENTEE_EMAIL: ${{ secrets.TEST_MENTEE_EMAIL }}
TEST_MENTEE_PASSWORD: ${{ secrets.TEST_MENTEE_PASSWORD }}
TEST_MENTEE_PHONE_NUMBER: ${{ secrets.TEST_MENTEE_PHONE_NUMBER }}
TEST_PARTNER_EMAIL: ${{ secrets.TEST_PARTNER_EMAIL }}
TEST_PARTNER_PASSWORD: ${{ secrets.TEST_PARTNER_PASSWORD }}
TEST_GUEST_EMAIL: ${{ secrets.TEST_GUEST_EMAIL }}
TEST_GUEST_PASSWORD: ${{ secrets.TEST_GUEST_PASSWORD }}
TEST_ADMIN_EMAIL: ${{ secrets.TEST_ADMIN_EMAIL }}
TEST_ADMIN_PASSWORD: ${{ secrets.TEST_ADMIN_PASSWORD }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build and run Backend
run: |
cd backend
touch firebase_service_key.json
echo "$FIREBASE_SERVICE_KEY" > firebase_service_key.json
cp firebase_service_key.json ./tests
ls
cat firebase_service_key.json
docker build -t backend .
docker images
docker run --name backend -d -e SENDGRID_API_KEY="$SENDGRID_API_KEY" -e SENDER_EMAIL="$SENDER_EMAIL" -e TWILIO_ACCOUNT_SID="$TWILIO_ACCOUNT_SID" -e TWILIO_AUTH_TOKEN="$TWILIO_AUTH_TOKEN" -e TWILIO_PHONE="$TWILIO_PHONE" -e FLASK_APP="$FLASK_APP" -e IMGUR_KEY="$IMGUR_KEY" -e FIREBASE_API_KEY="$FIREBASE_API_KEY" -e MONGO_USER="$MONGO_USER" -e MONGO_PASSWORD="$MONGO_PASSWORD" -e MONGO_HOST="$MONGO_HOST" -e MONGO_DB="$MONGO_DB" -e GOOGLE_APPLICATION_CREDENTIALS="$GOOGLE_APPLICATION_CREDENTIALS" -e BASE_URL="$BASE_URL" -e TEST_MENTOR_EMAIL="$TEST_MENTOR_EMAIL" -e TEST_MENTOR_PASSWORD="$TEST_MENTOR_PASSWORD" -e TEST_MENTOR_PHONE_NUMBER="$TEST_MENTOR_PHONE_NUMBER" -e TEST_MENTEE_EMAIL="$TEST_MENTEE_EMAIL" -e TEST_MENTEE_PASSWORD="$TEST_MENTEE_PASSWORD" -e TEST_MENTEE_PHONE_NUMBER="$TEST_MENTEE_PHONE_NUMBER" -e TEST_PARTNER_EMAIL=$TEST_PARTNER_EMAIL -e TEST_PARTNER_PASSWORD=$TEST_PARTNER_PASSWORD -e TEST_GUEST_EMAIL="$TEST_GUEST_EMAIL" -e TEST_GUEST_PASSWORD="$TEST_GUEST_PASSWORD" -e TEST_ADMIN_EMAIL="$TEST_ADMIN_EMAIL" -e TEST_ADMIN_PASSWORD="$TEST_ADMIN_PASSWORD" -p 8000:8000 backend

- name: Check if Flask server is up
run: |
retries=100
until curl -sSf http://localhost:8000/api/translation; do
((retries--)) || exit 1
sleep 1
done

- name: Run Tests
run: |
docker ps
docker exec backend /bin/bash -c "cd tests && pytest"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ venv
node_modules
backend/firebase_service_key.json
package-lock.json
package.json
yarn.lock
heroku-logs-prod.txt
heroku-logs.txt
Expand All @@ -14,3 +13,5 @@ pyproject.toml000
.DS_Store
app.log
backend/app.log
tests/.env
tests/cypress/screenshots/
1 change: 0 additions & 1 deletion backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*
!api
!manage.py
!requirements.txt
Expand Down
5 changes: 3 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,5 @@ WORKDIR /app

ENTRYPOINT [ "python" ]

CMD [ "manage.py", "runprod" ]
CMD [ "manage.py", "runserver" ]
# CMD [ "manage.py", "runprod" ]
Binary file removed backend/api/.DS_Store
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HamzaAnis please remove this file

Binary file not shown.
Binary file removed backend/api/utils/.DS_Store
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HamzaAnis please remove this file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is removed in this PR. It was present on the other branches.

Binary file not shown.
Loading
Loading