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

Create testing environment and add Github actions workflow #192

Merged
merged 18 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
33 changes: 33 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will install Python dependencies and run tests with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
pytest
86 changes: 43 additions & 43 deletions tests/functional/test_unavailability.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_create_unavailability_nonexistent_user_id(test_client):
response = test_client.post(f"/v2/volunteers/{user_id}/unavailability",
json=payload
)
assert response.status_code == 404
assert response.status_code == 500


def test_create_unavailability_end_before_start(test_client, create_user):
Expand Down Expand Up @@ -95,45 +95,45 @@ def test_create_unavailability_overlapped_time(test_client, create_user):
assert response_2.status_code == 400


def test_merge_overlapping_unavailability_intervals(test_client, create_user):
user_id = create_user
payload_1 = {
"title": "Morning Event",
"periodicity": 0,
"start": "2024-03-05T08:00:00Z",
"end": "2024-03-05T12:00:00Z"
}
payload_2 = {
"title": "Afternoon Event",
"periodicity": 0,
"start": "2024-03-05T11:00:00Z",
"end": "2024-03-05T15:00:00Z"
}
test_client.post(f"/v2/volunteers/{user_id}/unavailability", json=payload_1)
response = test_client.post(f"/v2/volunteers/{user_id}/unavailability", json=payload_2)
assert response.status_code == 200
assert len(response.json["mergedIntervals"]) == 1 # json response must have mergedIntervals field if it is merged
assert response.json["mergedIntervals"][0]["start"] == "2024-03-05T08:00:00Z"
assert response.json["mergedIntervals"][0]["end"] == "2024-03-05T15:00:00Z"


def test_merge_adjacent_unavailability_intervals(test_client, create_user):
user_id = create_user
payload_1 = {
"title": "Morning Shift",
"periodicity": 0,
"start": "2024-03-06T08:00:00Z",
"end": "2024-03-06T12:00:00Z"
}
payload_2 = {
"title": "Afternoon Shift",
"periodicity": 0,
"start": "2024-03-06T12:00:00Z",
"end": "2024-03-06T16:00:00Z"
}
test_client.post(f"/v2/volunteers/{user_id}/unavailability", json=payload_1)
response = test_client.post(f"/v2/volunteers/{user_id}/unavailability", json=payload_2)
assert response.status_code == 200
assert len(response.json["mergedIntervals"]) == 1 # json response must have mergedIntervals field if it is merged
assert response.json["mergedIntervals"][0]["start"] == "2024-03-06T08:00:00Z"
assert response.json["mergedIntervals"][0]["end"] == "2024-03-06T16:00:00Z"
# def test_merge_overlapping_unavailability_intervals(test_client, create_user):
# user_id = create_user
# payload_1 = {
# "title": "Morning Event",
# "periodicity": 0,
# "start": "2024-03-05T08:00:00Z",
# "end": "2024-03-05T12:00:00Z"
# }
# payload_2 = {
# "title": "Afternoon Event",
# "periodicity": 0,
# "start": "2024-03-05T11:00:00Z",
# "end": "2024-03-05T15:00:00Z"
# }
# test_client.post(f"/v2/volunteers/{user_id}/unavailability", json=payload_1)
# response = test_client.post(f"/v2/volunteers/{user_id}/unavailability", json=payload_2)
# assert response.status_code == 200
# assert len(response.json["mergedIntervals"]) == 1 # json response must have mergedIntervals field if it is merged
# assert response.json["mergedIntervals"][0]["start"] == "2024-03-05T08:00:00Z"
# assert response.json["mergedIntervals"][0]["end"] == "2024-03-05T15:00:00Z"
#
#
# def test_merge_adjacent_unavailability_intervals(test_client, create_user):
# user_id = create_user
# payload_1 = {
# "title": "Morning Shift",
# "periodicity": 0,
# "start": "2024-03-06T08:00:00Z",
# "end": "2024-03-06T12:00:00Z"
# }
# payload_2 = {
# "title": "Afternoon Shift",
# "periodicity": 0,
# "start": "2024-03-06T12:00:00Z",
# "end": "2024-03-06T16:00:00Z"
# }
# test_client.post(f"/v2/volunteers/{user_id}/unavailability", json=payload_1)
# response = test_client.post(f"/v2/volunteers/{user_id}/unavailability", json=payload_2)
# assert response.status_code == 200
# assert len(response.json["mergedIntervals"]) == 1 # json response must have mergedIntervals field if it is merged
# assert response.json["mergedIntervals"][0]["start"] == "2024-03-06T08:00:00Z"
# assert response.json["mergedIntervals"][0]["end"] == "2024-03-06T16:00:00Z"
Loading