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

Add tests for challenges app #4406

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
73 changes: 73 additions & 0 deletions tests/unit/challenges/test_admin_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from django.test import TestCase
from django.utils import timezone
from challenges.models import Challenge
from challenges.admin import ChallengeFilter
from hosts.models import ChallengeHostTeam
from django.contrib.auth.models import User


class ChallengeFilterTest(TestCase):
def setUp(self):
# Create a user
self.user = User.objects.create_user(username='testuser', password='12345')

# Create a challenge host team
self.challenge_host_team = ChallengeHostTeam.objects.create(
team_name="Test Challenge Host Team", created_by=self.user
)

# Create test data
self.past_challenge = Challenge.objects.create(
title="Past Challenge",
start_date=timezone.now() - timezone.timedelta(days=10),
end_date=timezone.now() - timezone.timedelta(days=5),
published=True,
approved_by_admin=True,
is_disabled=False,
creator=self.challenge_host_team,
)
self.present_challenge = Challenge.objects.create(
title="Present Challenge",
start_date=timezone.now() - timezone.timedelta(days=5),
end_date=timezone.now() + timezone.timedelta(days=5),
published=True,
approved_by_admin=True,
is_disabled=False,
creator=self.challenge_host_team,
)
self.future_challenge = Challenge.objects.create(
title="Future Challenge",
start_date=timezone.now() + timezone.timedelta(days=5),
end_date=timezone.now() + timezone.timedelta(days=10),
published=True,
approved_by_admin=True,
is_disabled=False,
creator=self.challenge_host_team,
)

def test_past_challenge_filter(self):
request = None # Mock request if needed
filter_instance = ChallengeFilter(request, {}, Challenge, Challenge.objects.all())
filter_instance.value = lambda: "past"
queryset = filter_instance.queryset(request, Challenge.objects.all())
self.assertIn(self.past_challenge, queryset)
self.assertNotIn(self.present_challenge, queryset)
self.assertNotIn(self.future_challenge, queryset)

def test_present_challenge_filter(self):
request = None # Mock request if needed
filter_instance = ChallengeFilter(request, {}, Challenge, Challenge.objects.all())
filter_instance.value = lambda: "present"
queryset = filter_instance.queryset(request, Challenge.objects.all())
self.assertNotIn(self.past_challenge, queryset)
self.assertIn(self.present_challenge, queryset)
self.assertNotIn(self.future_challenge, queryset)

def test_future_challenge_filter(self):
request = None # Mock request if needed
filter_instance = ChallengeFilter(request, {}, Challenge, Challenge.objects.all())
filter_instance.value = lambda: "future"
queryset = filter_instance.queryset(request, Challenge.objects.all())
self.assertNotIn(self.past_challenge, queryset)
self.assertNotIn(self.present_challenge, queryset)
self.assertIn(self.future_challenge, queryset)
12 changes: 12 additions & 0 deletions tests/unit/challenges/test_apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.test import TestCase
from django.apps import apps
from challenges.apps import ChallengesConfig


class ChallengesConfigTest(TestCase):
def test_app_name(self):
self.assertEqual(ChallengesConfig.name, "challenges")

def test_app_config(self):
app_config = apps.get_app_config('challenges')
self.assertEqual(app_config.name, "challenges")
Loading