Skip to content

Commit

Permalink
Merge pull request #637 from drnlm/bugfix/fix_test_discovery
Browse files Browse the repository at this point in the history
Bugfix/fix test discovery
  • Loading branch information
drnlm committed Jun 16, 2022
2 parents 06de5da + a12c8b4 commit b120bf4
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 95 deletions.
Empty file added wafer/kv/tests/__init__.py
Empty file.
Empty file.
Empty file added wafer/pages/tests/__init__.py
Empty file.
Empty file.
76 changes: 41 additions & 35 deletions wafer/talks/tests/test_talk_type.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
from datetime import timedelta
from django.utils import timezone

from wafer.talks.models import TalkType


def test_open_by_default():
talk_type = TalkType.objects.create()
assert talk_type in TalkType.objects.open_for_submission()


def test_closed_when_flagged_as_such():
talk_type = TalkType.objects.create(disable_submission=True)
assert talk_type not in TalkType.objects.open_for_submission()


def test_open_for_submission_by_date():
now = timezone.now()
yesterday = now - timedelta(days=1)
tomorrow = now + timedelta(days=2)

closed_talk_type = TalkType.objects.create(submission_deadline=yesterday)
open_talk_type = TalkType.objects.create(submission_deadline=tomorrow)
disabled_talk_type = TalkType.objects.create(
submission_deadline=tomorrow,
disable_submission=True,
)

assert open_talk_type in TalkType.objects.open_for_submission()
assert closed_talk_type not in TalkType.objects.open_for_submission()
from django.test import TestCase

from wafer.talks.models import TalkType

def test_open_for_late_submissions():
now = timezone.now()
yesterday = now - timedelta(days=1)

talk_type = TalkType.objects.create(
submission_deadline=yesterday,
accept_late_submissions=True,
)
assert talk_type in TalkType.objects.open_for_submission()
class TestTalkTypes(TestCase):
"""Collection of tests for talk type handling."""

def test_open_by_default(self):
"""Check that types are open for submission by default"""
talk_type = TalkType.objects.create()
self.assertTrue(talk_type in TalkType.objects.open_for_submission())

def test_closed_when_flagged_as_such(self):
"""Check that the closed submission flag works"""
talk_type = TalkType.objects.create(disable_submission=True)
self.assertTrue(talk_type not in TalkType.objects.open_for_submission())

def test_open_for_submission_by_date(self):
"""Check taht we can use dates to manage open/ closed state"""
now = timezone.now()
yesterday = now - timedelta(days=1)
tomorrow = now + timedelta(days=2)

closed_talk_type = TalkType.objects.create(submission_deadline=yesterday)
open_talk_type = TalkType.objects.create(submission_deadline=tomorrow)
disabled_talk_type = TalkType.objects.create(
submission_deadline=tomorrow,
disable_submission=True,
)

self.assertTrue(open_talk_type in TalkType.objects.open_for_submission())
self.assertTrue(closed_talk_type not in TalkType.objects.open_for_submission())

def test_open_for_late_submissions(self):
"""Check that types that allow late submissions stay open"""
now = timezone.now()
yesterday = now - timedelta(days=1)

talk_type = TalkType.objects.create(
submission_deadline=yesterday,
accept_late_submissions=True,
)
self.assertTrue(talk_type in TalkType.objects.open_for_submission())
122 changes: 62 additions & 60 deletions wafer/talks/tests/test_wafer_basic_talks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,98 @@
from django.contrib.auth import get_user_model
from django.utils.timezone import datetime, now, utc

from django.test import TestCase

from wafer.talks.models import Talk, TalkType, SUBMITTED
from wafer.talks.tests.fixtures import create_talk
from wafer.tests.utils import create_user


def test_add_talk():
"""Create a user and add a talk to it"""
user = create_user('john')
create_talk('This is a test talk', status=SUBMITTED, user=user)

assert user.contact_talks.count() == 1

class TestBasicTalks(TestCase):
"""Basic talk tests"""

def test_filter_talk():
"""Create a second user and check some filters"""
create_user('james')
def setUp(self):
"""Setup a user with a talk"""
self.user = create_user('john')
create_talk('This is a test talk', status=SUBMITTED, user=self.user)

UserModel = get_user_model()
assert UserModel.objects.filter(contact_talks__isnull=False).count() == 1
assert UserModel.objects.filter(contact_talks__isnull=True).count() == 1
def test_add_talk(self):
"""Check that the created talk is found via the user"""
self.assertTrue(self.user.contact_talks.count() == 1)

def test_filter_talk(self):
"""Create a second user and check some filters"""
create_user('james')

def test_multiple_talks():
"""Add more talks"""
UserModel = get_user_model()
UserModel = get_user_model()
self.assertTrue(UserModel.objects.filter(contact_talks__isnull=False).count() == 1)
self.assertTrue(UserModel.objects.filter(contact_talks__isnull=True).count() == 1)

user1 = UserModel.objects.filter(username='john').get()
user2 = UserModel.objects.filter(username='james').get()
def test_multiple_talks(self):
"""Add more talks"""
user2 = create_user('james')

create_talk('This is a another test talk', status=SUBMITTED, user=user1)
create_talk('This is a another test talk', status=SUBMITTED, user=self.user)

assert len([x.title for x in user1.contact_talks.all()]) == 2
assert len([x.title for x in user2.contact_talks.all()]) == 0
self.assertTrue(len([x.title for x in self.user.contact_talks.all()]) == 2)
self.assertTrue(len([x.title for x in user2.contact_talks.all()]) == 0)

create_talk('This is a third test talk', status=SUBMITTED, user=user2)
create_talk('This is a third test talk', status=SUBMITTED, user=user2)

assert len([x.title for x in user2.contact_talks.all()]) == 1
self.assertTrue(len([x.title for x in user2.contact_talks.all()]) == 1)


def test_corresponding_author_details():
"""Create a second user and check some filters"""
user = create_user('jeff')
profile = user.userprofile
profile.contact_number = '77776'
profile.save()
def test_corresponding_author_details(self):
"""Create a second user and check some filters"""
user = create_user('jeff')
profile = user.userprofile
profile.contact_number = '77776'
profile.save()

speaker = create_user('bob')
speaker = create_user('bob')

create_talk('This is a another test talk', status=SUBMITTED, user=user)
create_talk('This is a another test talk', status=SUBMITTED, user=user)

talk = user.contact_talks.all()[0]
talk.authors.add(user)
talk.authors.add(speaker)
talk.save()
talk = user.contact_talks.all()[0]
talk.authors.add(user)
talk.authors.add(speaker)
talk.save()

assert talk.get_authors_display_name() == 'jeff & bob'
assert talk.get_corresponding_author_contact() == 'jeff@example.com - 77776'
assert talk.get_corresponding_author_name() == 'jeff (jeff)'
self.assertTrue(talk.get_authors_display_name() == 'jeff & bob')
self.assertTrue(talk.get_corresponding_author_contact() == 'jeff@example.com - 77776')
self.assertTrue(talk.get_corresponding_author_name() == 'jeff (jeff)')

speaker.first_name = 'Bob'
speaker.last_name = 'Robert'
speaker.save()
speaker.first_name = 'Bob'
speaker.last_name = 'Robert'
speaker.save()

assert talk.get_authors_display_name() == 'jeff & Bob Robert'
self.assertTrue(talk.get_authors_display_name() == 'jeff & Bob Robert')


def test_is_late_submission_no_talk_type():
assert not Talk().is_late_submission
def test_is_late_submission_no_talk_type(self):
self.assertTrue(not Talk().is_late_submission)


def test_is_late_submission_no_deadline():
talk_type = TalkType()
talk = Talk(submission_time=now(), talk_type=talk_type)
def test_is_late_submission_no_deadline(self):
talk_type = TalkType()
talk = Talk(submission_time=now(), talk_type=talk_type)

assert not talk.is_late_submission
self.assertTrue(not talk.is_late_submission)


def test_is_late_submission_not_late():
deadline = datetime(2019, 11, 1, 0, 0, 0, 0, utc)
before_deadline = datetime(2019, 10, 15, 0, 0, 0, 0, utc)
def test_is_late_submission_not_late(self):
deadline = datetime(2019, 11, 1, 0, 0, 0, 0, utc)
before_deadline = datetime(2019, 10, 15, 0, 0, 0, 0, utc)

talk_type = TalkType(submission_deadline=deadline)
not_late = Talk(talk_type=talk_type, submission_time=before_deadline)
assert not not_late.is_late_submission
talk_type = TalkType(submission_deadline=deadline)
not_late = Talk(talk_type=talk_type, submission_time=before_deadline)
self.assertTrue(not not_late.is_late_submission)


def test_is_late_submission_late():
deadline = datetime(2019, 11, 1, 0, 0, 0, 0, utc)
after_deadline = datetime(2019, 11, 2, 0, 0, 0, 0, utc)
def test_is_late_submission_late(self):
deadline = datetime(2019, 11, 1, 0, 0, 0, 0, utc)
after_deadline = datetime(2019, 11, 2, 0, 0, 0, 0, utc)

talk_type = TalkType(submission_deadline=deadline)
late = Talk(talk_type=talk_type, submission_time=after_deadline)
assert late.is_late_submission
talk_type = TalkType(submission_deadline=deadline)
late = Talk(talk_type=talk_type, submission_time=after_deadline)
self.assertTrue(late.is_late_submission)
Empty file added wafer/users/tests/__init__.py
Empty file.

0 comments on commit b120bf4

Please sign in to comment.