Add Draw.successful()

It can decide if the given draw was successful:

* The word is accepted
* Work was submitted for the word
* The work was submitted on time
This commit is contained in:
Gergely Polonkai
2015-11-27 14:58:16 +01:00
parent 51035af3d0
commit e71eb45260
3 changed files with 71 additions and 0 deletions

View File

@@ -167,3 +167,31 @@ class DrawTest(TestCase):
Word.objects.create()
self.assertEquals(self.word, self.user.draw_word())
@override_settings(DRAW_TIME='1 00:00:00')
def test_draw_successful(self):
# If there is no work, but we are within the time range
draw = Draw.objects.create(
user=self.user,
word=Word.objects.create(),
accepted=True,
timestamp=timezone.now())
self.assertIsNone(draw.successful())
# If there is no work and we are out of time
draw.timestamp -= timedelta(days=2)
draw.save()
self.assertIsNotNone(draw.successful())
self.assertFalse(draw.successful())
# If there is work and it was submitted on time
draw.timestamp = timezone.now() + timedelta(minutes=1)
draw.save()
Work.objects.create(draw=draw)
self.assertTrue(draw.successful())
# If there is work and it wasnt submitted on time
draw.timestamp = timezone.now() - timedelta(days=2)
draw.save()
self.assertIsNotNone(draw.successful())
self.assertFalse(draw.successful())