def setUp(self): self.test_admin = User.objects.get(pk=1) self.test_member = User.objects.get(pk=2) self.client.login(username='******', password='******') self.game_permission = GamePermission() self.game_permission.type = 'profile' self.game_permission.key = 'profile_email' self.game_permission.name = 'View email address' self.game_permission.save()
class UserPrivacyTestCase(TestCase): """ Tests how a member can interact with the site and manage their account privacy options """ fixtures = ['accounts_test_data.json'] def setUp(self): self.test_admin = User.objects.get(pk=1) self.test_member = User.objects.get(pk=2) self.client.login(username='******', password='******') self.game_permission = GamePermission() self.game_permission.type = 'profile' self.game_permission.key = 'profile_email' self.game_permission.name = 'View email address' self.game_permission.save() def testAddingPermissionByKey(self): """ Simply test that a permission can be added by key value """ self.test_member.userprofile.add_permission_by_key('profile_email', 'friend') self.test_member.userprofile.add_permission_by_key('profile_email', 'guild') self.assertTrue( self.test_member.userprofile.has_permission_by_key('profile_email', 'guild')) self.assertTrue( self.test_member.userprofile.has_permission_by_key('profile_email', 'friend')) self.assertFalse( self.test_member.userprofile.has_permission_by_key('profile_email', 'member')) def testInvalidPermissionByKey(self): """ Tests permission key error handling """ self.assertRaises(GamePermission.DoesNotExist, lambda: self.test_member.userprofile.add_permission_by_key( 'profile_fake', 'friend')) self.assertRaises(GamePermission.BadPermissionValue, lambda: self.test_member.userprofile.add_permission_by_key( 'profile_email', 'bad_choice')) self.test_member.userprofile.add_permission_by_key('profile_email', 'friend') self.assertRaises(GamePermission.DuplicatePermissionValue, lambda: self.test_member.userprofile.add_permission_by_key( 'profile_email', 'friend')) self.assertRaises(GamePermission.DoesNotExist, lambda: self.test_member.userprofile.has_permission_by_key( 'profile_fake', 'friend')) def testClearPermissions(self): """ Tests the permission reset button performs as expected """ self.test_member.userprofile.add_permission_by_key('profile_email', 'friend') self.test_member.userprofile.clear_permissions() self.assertFalse( self.test_member.userprofile.has_permission_by_key('profile_email', 'friend'))