Skip to content

Commit

Permalink
Change test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasBottone committed Jan 4, 2025
1 parent 162b148 commit d3338aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 118 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- name: 🚚 Get latest code
uses: actions/checkout@v2

- name: 🔨 Set up Python 3.9.12
- name: 🔨 Set up Python 3.9.20
uses: actions/setup-python@v2
with:
python-version: 3.9.12
python-version: 3.9.20

- name: 🛠 Install Dependencies
run: |
Expand Down
29 changes: 10 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
name: Tests

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

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, '3.10']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
- name: 🔨 Set up Python 3.9.20
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
python-version: 3.9.20

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-cov
- name: Run tests
- name: Run Tests
run: |
pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
pytest
env:
SECRET_KEY: ${{ secrets.BASE_KEY }}
SMTP_SERVER: ${{ secrets.SMTP_SERVER }}
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
NEW_AES_KEY: ${{ secrets.NEW_AES_KEY }}
DISCORD_CLIENT_SECRET: ${{ secrets.DISCORD_CLIENT_SECRET }}
104 changes: 7 additions & 97 deletions home/tests.py
Original file line number Diff line number Diff line change
@@ -1,103 +1,13 @@
import pytest
from django.test import TestCase
from django.core.exceptions import ValidationError
from datetime import date
from home.models import Staff, HistoricEvent


@pytest.mark.django_db
class TestStaffModel:
@pytest.fixture
def staff_member(self):
return Staff.objects.create(
name="John Doe",
title="Senior Developer",
image_url="https://example.com/image.jpg",
bio="A talented developer with years of experience.",
email="[email protected]",
linkedin_url="https://linkedin.com/in/johndoe",
github_url="https://github.com/johndoe"
)

def test_staff_creation(self, staff_member):
"""Test that a staff member can be created with all fields"""
assert staff_member.name == "John Doe"
assert staff_member.title == "Senior Developer"
assert staff_member.image_url == "https://example.com/image.jpg"
assert staff_member.email == "[email protected]"

def test_staff_string_representation(self, staff_member):
"""Test the string representation of Staff model"""
assert str(staff_member) == "John Doe"

def test_optional_fields(self):
"""Test that linkedin_url and github_url are optional"""
staff_without_socials = Staff.objects.create(
name="Jane Doe",
title="Developer",
image_url="https://example.com/image2.jpg",
bio="Another talented developer.",
email="[email protected]"
)
assert staff_without_socials.linkedin_url is None
assert staff_without_socials.github_url is None

def test_invalid_email(self):
"""Test that invalid email raises validation error"""
with pytest.raises(ValidationError):
staff = Staff.objects.create(
name="Invalid Email",
title="Developer",
image_url="https://example.com/image.jpg",
bio="Test bio",
email="invalid-email"
)
staff.full_clean()
from django.urls import reverse


@pytest.mark.django_db
class TestHistoricEventModel:
@pytest.fixture
def event(self):
return HistoricEvent.objects.create(
name="Championship 2023",
date=date(2023, 12, 25),
youtube_url="https://youtube.com/watch?v=123",
first_place="Team Alpha",
second_place="Team Beta"
)

def test_event_creation(self, event):
"""Test that an event can be created with all fields"""
assert event.name == "Championship 2023"
assert event.date == date(2023, 12, 25)
assert event.first_place == "Team Alpha"
assert event.second_place == "Team Beta"

def test_event_string_representation(self, event):
"""Test the string representation of HistoricEvent model"""
assert str(event) == "Championship 2023"

def test_optional_fields(self):
"""Test that youtube_url and second_place are optional"""
event_minimal = HistoricEvent.objects.create(
name="Mini Tournament",
date=date(2023, 1, 1),
first_place="Winner Team"
)
assert event_minimal.youtube_url is None
assert event_minimal.second_place is None
def test_home_view(client):
url = reverse('home')
response = client.get(url)
assert response.status_code == 200
assert 'Welcome to the home' in response.content

@pytest.mark.parametrize("test_date,expected", [
(date(2024, 12, 25), 2024),
(date(2023, 1, 1), 2023),
(date(2025, 6, 15), 2025),
])
def test_date_validation(self, test_date, expected):
"""Test that the date field accepts valid dates"""
event = HistoricEvent.objects.create(
name="Test Championship",
date=test_date,
first_place="TBD"
)
assert event.date.year == expected
# TODO: Add more tests for the dynamic views (such as the highscore or ranked views)

0 comments on commit d3338aa

Please sign in to comment.