-
Notifications
You must be signed in to change notification settings - Fork 17
Add basic tests #99
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
Merged
Add basic tests #99
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d9114c9
API v1 initial tests.
simi 4454801
Use pytest for testing
JelteF dfe4fb5
Bump to postgres 18 in CI
JelteF 558440f
Use example local settings in CI
JelteF 4931065
Fix db creation
JelteF 27a8d9b
Install dev dependencies in CI
JelteF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 @@ | ||
| # Tests for the commitfest application |
This file contains hidden or 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,94 @@ | ||
| from django.test import override_settings | ||
|
|
||
| import json | ||
| from datetime import date | ||
|
|
||
| import pytest | ||
|
|
||
| from pgcommitfest.commitfest.models import CommitFest | ||
|
|
||
| pytestmark = pytest.mark.django_db | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def commitfests(): | ||
| """Create test commitfests with various statuses.""" | ||
| return { | ||
| "open": CommitFest.objects.create( | ||
| name="2025-01", | ||
| status=CommitFest.STATUS_OPEN, | ||
| startdate=date(2025, 1, 1), | ||
| enddate=date(2025, 1, 31), | ||
| draft=False, | ||
| ), | ||
| "in_progress": CommitFest.objects.create( | ||
| name="2024-11", | ||
| status=CommitFest.STATUS_INPROGRESS, | ||
| startdate=date(2024, 11, 1), | ||
| enddate=date(2024, 11, 30), | ||
| draft=False, | ||
| ), | ||
| "recent_previous": CommitFest.objects.create( | ||
| name="2024-09", | ||
| status=CommitFest.STATUS_CLOSED, | ||
| startdate=date(2024, 9, 1), | ||
| enddate=date(2024, 9, 30), | ||
| draft=False, | ||
| ), | ||
| "old_previous": CommitFest.objects.create( | ||
| name="2024-07", | ||
| status=CommitFest.STATUS_CLOSED, | ||
| startdate=date(2024, 7, 1), | ||
| enddate=date(2024, 7, 31), | ||
| draft=False, | ||
| ), | ||
| "draft": CommitFest.objects.create( | ||
| name="2025-03-draft", | ||
| status=CommitFest.STATUS_OPEN, | ||
| startdate=date(2025, 3, 1), | ||
| enddate=date(2025, 3, 31), | ||
| draft=True, | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| def test_needs_ci_endpoint(client, commitfests): | ||
| """Test the /api/v1/commitfests/needs_ci endpoint returns correct data.""" | ||
| with override_settings(AUTO_CREATE_COMMITFESTS=False): | ||
| response = client.get("/api/v1/commitfests/needs_ci") | ||
|
|
||
| # Check response metadata | ||
| assert response.status_code == 200 | ||
| assert response["Content-Type"] == "application/json" | ||
| assert response["Access-Control-Allow-Origin"] == "*" | ||
|
|
||
| # Parse and compare response | ||
| data = json.loads(response.content) | ||
|
|
||
| expected = { | ||
| "commitfests": { | ||
| "open": { | ||
| "id": commitfests["open"].id, | ||
| "name": "2025-01", | ||
| "status": "Open", | ||
| "startdate": "2025-01-01", | ||
| "enddate": "2025-01-31", | ||
| }, | ||
| "in_progress": { | ||
| "id": commitfests["in_progress"].id, | ||
| "name": "2024-11", | ||
| "status": "In Progress", | ||
| "startdate": "2024-11-01", | ||
| "enddate": "2024-11-30", | ||
| }, | ||
| "draft": { | ||
| "id": commitfests["draft"].id, | ||
| "name": "2025-03-draft", | ||
| "status": "Open", | ||
| "startdate": "2025-03-01", | ||
| "enddate": "2025-03-31", | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| assert data == expected |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have assumed PostgreSQL 14 is used in production since it is recommended in README.md. https://github.com/postgres/pgcommitfest?tab=readme-ov-file#ubuntu-instructions It would be good to keep it 1:1. Any idea which PostgreSQL is app deployed with?