def test_expires_prior_checkins(self): """Should expire prior checkins of this user when checking in again.""" instance = CheckinFactory() instance2 = CheckinFactory(user=instance.user) instance = Checkin.objects.get(pk=instance.pk) self.assertTrue(instance.expired) self.assertFalse(instance2.expired)
def test_expires_all_checkins(self): checkin1 = CheckinFactory() checkin2 = CheckinFactory() form = CheckoutForm(user=checkin1.user, data={}) self.assertTrue(form.is_valid(), msg=('Errors: {0}'.format(form.errors.items()))) form.save() checkin1 = Checkin.objects.get(pk=checkin1.pk) checkin2 = Checkin.objects.get(pk=checkin2.pk) self.assertTrue(checkin1.expired) self.assertFalse(checkin2.expired)
def test_command(self): checkin = CheckinFactory() checkin.time = datetime.now() - timedelta(minutes=90) checkin.save() CheckinFactory() CheckinFactory() call_command('expire_checkins') self.assertEqual(Checkin.objects.filter(expired=True).count(), 1)
def test_handler(self): place = PlaceFactory() # Two users are subscribed to the same place SubscriptionFactory(content_object=place) SubscriptionFactory(content_object=place) # A third user is subscribed to something else SubscriptionFactory() CheckinFactory(place=place) message = Message.objects.all()[0] self.assertEqual(len(message.email.bcc), 2)
def test_tag(self): """ Should return the checkins for the place that are not yet expired. """ # Two checkins that are valid checkin1_1 = CheckinFactory() CheckinFactory(place=checkin1_1.place) # One checkin that is expired checkin1_3 = CheckinFactory(place=checkin1_1.place) checkin1_3.expired = True checkin1_3.save() # One checkin that belongs to another place CheckinFactory() result = get_checkins(checkin1_1.place) self.assertEqual(result.count(), 2)
def test_model(self): """Should be able to instantiate and save a Chekin object.""" instance = CheckinFactory() self.assertTrue(instance.pk)
def setUp(self): self.checkin = CheckinFactory()
def test_tag_with_user(self): """Should return the place where the given user is checked-in.""" checkin = CheckinFactory() result = get_checked_in_place(checkin.user) self.assertEqual(result, checkin.place)