예제 #1
0
 def test_is_member(self):
     user = User.objects.create(username="******")
     group = Group.objects.create(name="group")
     group.user_set.add(user)
     brewing_company = models.BrewingCompany(group=group)
     self.assertTrue(
         permissions.is_member_of_brewing_company(user, brewing_company))
예제 #2
0
    def test_does_not_have_permission(self):
        permission = permissions.IsMember()
        user = User.objects.create(username="******")
        group = Group.objects.create(name="group")
        request = Mock()
        request.user = user
        view = None
        brewing_company = models.BrewingCompany(group=group)

        self.assertFalse(
            permission.has_object_permission(request, view, brewing_company))
예제 #3
0
 def test_does_not_have_permission(self):
     permission = permissions.OwnsRecipe()
     user = User.objects.create(username="******")
     group = Group.objects.create(name="group")
     request = Mock()
     request.user = user
     view = None
     brewing_company = models.BrewingCompany(group=group)
     recipe = models.Recipe(company=brewing_company)
     recipe_instance = models.RecipeInstance(recipe=recipe)
     self.assertFalse(
         permission.has_object_permission(request, view, recipe_instance))
예제 #4
0
    def test_has_object_permission(self):
        permission = permissions.IsMemberOfBrewingCompany()
        user = User.objects.create(username="******")
        group = Group.objects.create(name="group")
        group.user_set.add(user)
        request = Mock()
        request.user = user
        view = None
        brewing_company = models.BrewingCompany(group=group)
        brewery = models.Brewery(company=brewing_company)

        self.assertTrue(
            permission.has_object_permission(request, view, brewery))
예제 #5
0
 def test_name_without_group(self):
     brewing_company = models.BrewingCompany()
     self.assertEquals(brewing_company.name, None)
예제 #6
0
    def test_name_with_group(self):
        group = Group.objects.create(name="Foo")
        brewing_company = models.BrewingCompany(group=group)

        self.assertEquals(brewing_company.name, "Foo")
예제 #7
0
 def test_no_group(self):
     user = User.objects.create(username="******")
     brewing_company = models.BrewingCompany()
     self.assertFalse(
         permissions.is_member_of_brewing_company(user, brewing_company))