Exemplo n.º 1
0
    def test_claim(self):
        dlist = DiningList.get_latest()
        dlist.save()

        self.client.login(username="******", password="******")

        # We test claiming the dining list without participation

        r = self.client.get(self.view_url)

        dlist = DiningList.get_latest()

        self.assertIsNone(dlist.owner)

        # We test claiming the dining list with a participation

        dpart = DiningParticipation(user=self.testUser, dining_list=dlist)
        dpart.save()

        self.assertIsNone(dlist.owner)

        r = self.client.get(self.view_url)

        self.assertEqual(r.status_code, 302)

        dlist = DiningList.get_latest()

        self.assertIsNotNone(dlist.owner)
        self.assertEqual(dlist.owner, self.testUser)

        # Test that you cannot claim a dining list over someone else

        dpart = DiningParticipation(user=self.testUser2, dining_list=dlist)

        dpart.save()

        self.client.login(username=self.testUser2.username, password="******")

        r = self.client.get(self.view_url)

        self.assertEqual(r.status_code, 302)

        dlist = DiningList.get_latest()

        self.assertNotEqual(dlist.owner, self.testUser2)
        self.assertEqual(dlist.owner, self.testUser)

        dpart.delete()
        dlist.delete()
Exemplo n.º 2
0
    def test_get_registered_user(self):
        dlist = DiningList().get_latest()

        dlist.save()

        dpart = DiningParticipation(user=self.testUser, dining_list=dlist)

        dpart.save()

        # Tests

        self.assertEqual(len(dlist.get_participants()), 1)

        dpart.delete()
        dlist.delete()
Exemplo n.º 3
0
    def test_claim(self):
        dlist = DiningList.get_latest()
        dlist.save()

        self.client.login(username="******", password="******")

        # We test claiming the dining list without participation

        r = self.client.get(self.view_url)

        dlist = DiningList.get_latest()

        self.assertIsNone(dlist.owner)

        # We test claiming the dining list with a participation

        dpart = DiningParticipation(user=self.testUser, dining_list=dlist)
        dpart.save()

        self.assertIsNone(dlist.owner)

        r = self.client.get(self.view_url)

        self.assertEqual(r.status_code, 302)

        dlist = DiningList.get_latest()

        self.assertIsNotNone(dlist.owner)
        self.assertEqual(dlist.owner, self.testUser)

        # Test that you cannot claim a dining list over someone else

        dpart = DiningParticipation(user=self.testUser2, dining_list=dlist)

        dpart.save()

        self.client.login(username=self.testUser2.username, password="******")

        r = self.client.get(self.view_url)

        self.assertEqual(r.status_code, 302)

        dlist = DiningList.get_latest()

        self.assertNotEqual(dlist.owner, self.testUser2)
        self.assertEqual(dlist.owner, self.testUser)

        dpart.delete()
        dlist.delete()
Exemplo n.º 4
0
    def test_get_registered_user(self):
        dlist = DiningList().get_latest()

        dlist.save()

        dpart = DiningParticipation(user=self.testUser, dining_list=dlist)

        dpart.save()

        # Tests

        self.assertEqual(len(dlist.get_participants()), 1)

        dpart.delete()
        dlist.delete()
Exemplo n.º 5
0
    def test_new_participation(self):
        dlist = DiningList.get_latest()
        dlist.owner = self.testUser

        dlist.save()

        dpart = DiningParticipation(user=self.testUser, dining_list=dlist)

        dpart.work_cook = True

        dpart.save()

        dstats = DiningStats.objects.get(user=self.testUser)

        self.assertEquals(dstats.total_helped, 1)
        self.assertEquals(dstats.total_participated, 1)

        # Now we update

        dpart.work_cook = False

        dpart.save()

        dstats = DiningStats.objects.get(user=self.testUser)

        self.assertEqual(dstats.total_helped, 0)
        self.assertEqual(dstats.total_participated, 1)

        # Now we test for cooking and dishes at the same time

        dpart.work_cook = True
        dpart.work_dishes = True

        dpart.save()

        dstats = DiningStats.objects.get(user=self.testUser)

        self.assertEqual(dstats.total_helped, 2)
        self.assertEqual(dstats.total_participated, 1)
Exemplo n.º 6
0
    def test_new_participation(self):
        dlist = DiningList.get_latest()
        dlist.owner = self.testUser

        dlist.save()

        dpart = DiningParticipation(user=self.testUser, dining_list=dlist)

        dpart.work_cook = True

        dpart.save()

        dstats = DiningStats.objects.get(user=self.testUser)

        self.assertEquals(dstats.total_helped, 1)
        self.assertEquals(dstats.total_participated, 1)

        # Now we update

        dpart.work_cook = False

        dpart.save()

        dstats = DiningStats.objects.get(user=self.testUser)

        self.assertEqual(dstats.total_helped, 0)
        self.assertEqual(dstats.total_participated, 1)

        # Now we test for cooking and dishes at the same time

        dpart.work_cook = True
        dpart.work_dishes = True

        dpart.save()

        dstats = DiningStats.objects.get(user=self.testUser)

        self.assertEqual(dstats.total_helped, 2)
        self.assertEqual(dstats.total_participated, 1)