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))
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))
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))
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))
def test_name_without_group(self): brewing_company = models.BrewingCompany() self.assertEquals(brewing_company.name, None)
def test_name_with_group(self): group = Group.objects.create(name="Foo") brewing_company = models.BrewingCompany(group=group) self.assertEquals(brewing_company.name, "Foo")
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))