Пример #1
0
    def test_save_user_does_not_exist(self):
        group = Group.objects.create(name="Foo")
        brewing_company = models.BrewingCompany.objects.create(group=group)
        brewery = models.Brewery.objects.create(company=brewing_company,
                                                name="Bar")
        brewhouse = models.Brewhouse(brewery=brewery, name="Baz")
        user_count_start = User.objects.count()
        token_count_start = Token.objects.count()

        brewhouse.save()
        self.assertEquals(User.objects.count(), user_count_start + 1)
        self.assertEquals(Token.objects.count(), token_count_start + 1)
        self.assertIn(brewhouse.user, brewing_company.group.user_set.all())
Пример #2
0
    def test_does_not_have_object_permission(self):
        permission = permissions.IsMemberOfBrewery()
        user = User.objects.create(username="******")
        group = Group.objects.create(name="group")
        request = Mock()
        request.user = user
        view = None
        brewing_company = models.BrewingCompany(group=group)
        brewery = models.Brewery(company=brewing_company)
        brewhouse = models.Brewhouse(brewery=brewery)

        self.assertFalse(
            permission.has_object_permission(request, view, brewhouse))
Пример #3
0
 def test_save_token_for_wrong_user(self):
     group = Group.objects.create(name="Foo")
     user = User.objects.create(username="******")
     user.groups.add(group)
     user_bad = User.objects.create(username="******")
     token = Token.objects.create(user=user_bad)
     brewing_company = models.BrewingCompany.objects.create(group=group)
     brewery = models.Brewery.objects.create(company=brewing_company,
                                             name="Bar")
     brewhouse = models.Brewhouse(brewery=brewery,
                                  name="Baz",
                                  user=user,
                                  token=token)
     with self.assertRaises(models.InvalidUserError):
         brewhouse.save()
Пример #4
0
    def test_save_token_does_not_exist(self):
        group = Group.objects.create(name="Foo")
        user = User.objects.create(username="******")
        user.groups.add(group)
        brewing_company = models.BrewingCompany.objects.create(group=group)
        brewery = models.Brewery.objects.create(company=brewing_company,
                                                name="Bar")
        brewhouse = models.Brewhouse(brewery=brewery, name="Baz", user=user)
        user_count_start = User.objects.count()
        token_count_start = Token.objects.count()

        brewhouse.save()
        self.assertEquals(User.objects.count(), user_count_start)
        self.assertEquals(Token.objects.count(), token_count_start + 1)
        self.assertEquals(brewhouse.token.user, user)
Пример #5
0
 def test_save_has_pump(self):
     brewhouse = models.Brewhouse()
     main_pump = models.Pump.objects.create()
     brewhouse.main_pump = main_pump
     brewhouse.save()
     self.assertIs(brewhouse.main_pump, main_pump)
Пример #6
0
 def test_save_no_pump(self):
     brewhouse = models.Brewhouse()
     self.assertIsNone(brewhouse.main_pump)
     brewhouse.save()
     self.assertIsNotNone(brewhouse.main_pump)
Пример #7
0
 def test_save_has_mash_tun(self):
     brewhouse = models.Brewhouse()
     mash_tun = models.MashTun.objects.create()
     brewhouse.mash_tun = mash_tun
     brewhouse.save()
     self.assertIs(brewhouse.mash_tun, mash_tun)
Пример #8
0
 def test_save_no_mash_tun(self):
     brewhouse = models.Brewhouse()
     self.assertIsNone(brewhouse.mash_tun)
     brewhouse.save()
     self.assertIsNotNone(brewhouse.mash_tun)
Пример #9
0
 def test_save_has_boil_kettle(self):
     brewhouse = models.Brewhouse()
     boil_kettle = models.HotLiquorTun.objects.create()
     brewhouse.boil_kettle = boil_kettle
     brewhouse.save()
     self.assertIs(brewhouse.boil_kettle, boil_kettle)
Пример #10
0
 def test_save_no_boil_kettle(self):
     brewhouse = models.Brewhouse()
     self.assertIsNone(brewhouse.boil_kettle)
     brewhouse.save()
     self.assertIsNotNone(brewhouse.boil_kettle)