def setUp(self): create_groups.Command().handle() self.user = get_user_model().objects.create(username="******") self.admin = get_user_model().objects.create(username="******") self.user.groups.add(AdministrativeStaffGroup) self.admin.groups.add(InstanceAdminGroup) self.form = Form.objects.create( name="Hundiformular", description="Doggo", js_code="var foo;", xml_code="<xml></xml>", active=True, ) # create a group and add a form/user to it self.group = TeamService.create(self.admin, "Hunditeam", {}) create_mock_cert(self.group) TeamMembershipService.add_member(self.admin, team_id=self.group.id, keys={}, invited_user_id=self.user.id) self.form.teams.add(self.group) self.keypair = generate_test_keypair() self.first_key = EncryptionKey.objects.create( public_key=self.keypair["publickey"], user=self.user, active=True) create_signature_key.Command().handle() self.form_submission = FormService.submit(form_id=self.form.id, content="helo")
def test_update_form_groups(self): form = FormService.create_form_(self.admin, "A form", "Hello") form = FormService.update_form_( self.admin, form.pk, name="blub", active=True, js_code="var foo;", xml_code="<xml></xml>", ) self.assertEqual(form.xml_code, "<xml></xml>") grp = TeamService.create(self.admin, name="yolo", keys={}) create_mock_cert(grp) form = FormService.update_form_teams(self.admin, form.pk, [self.group.pk]) self.assertEqual(form.teams.first(), self.group) self.assertEqual(form.teams.count(), 1) form = FormService.update_form_teams(self.admin, form.pk, [grp.pk]) self.assertEqual(form.teams.first(), grp) self.assertEqual(form.teams.count(), 1) form = FormService.update_form_teams(self.admin, form.pk, [self.group.pk, grp.pk]) self.assertEqual(form.teams.count(), 2) with self.assertRaises(PermissionError): form = FormService.update_form_teams(self.user, form.pk, [grp.pk])
def test_update_member_replace_admin_by_update(self): team = TeamService.create(self.admin, "Hunditeam__", {}) TeamMembershipService.add_member( self.admin, team.pk, {}, self.user.pk, role=TeamRoleChoices.ADMIN ) TeamMembershipService.update_member( self.user, team.id, self.admin.id, role=TeamRoleChoices.MEMBER ) self.assertEqual(team.members.count(), 2)
def test_update_member_remove_admin_by_update(self): team = TeamService.create(self.admin, "Hunditeam__", {}) membership = TeamMembershipService.add_member( self.admin, team.pk, {}, self.user.pk ) with self.assertRaises(TeamServiceException): TeamMembershipService.update_member( self.user, team.id, self.user.id, role=TeamRoleChoices.MEMBER )
def test_update_member_unprivileged(self): team = TeamService.create(self.admin, "Hunditeam__", {}) membership = TeamMembershipService.add_member( self.admin, team.pk, {}, self.user.pk ) with self.assertRaises(TeamServiceException): TeamMembershipService.update_member( self.user, team.id, self.user.id, role=TeamRoleChoices.ADMIN )
def test_delete_member_remove_admin(self): team = TeamService.create(self.admin, "Hunditeam", {}) membership = TeamMembershipService.add_member( self.admin, team.pk, {}, self.user.pk ) team.refresh_from_db() self.assertEqual(team.members.count(), 2) with self.assertRaises(TeamServiceException): TeamMembershipService.remove_member(self.admin, team.id, self.admin.id)
def test_delete_member(self): team = TeamService.create(self.admin, "Hunditeam", {}) membership = TeamMembershipService.add_member( self.admin, team.pk, {}, self.user.pk ) team.refresh_from_db() self.assertEqual(team.members.count(), 2) TeamMembershipService.remove_member(self.admin, team.id, self.user.id) self.assertEqual(team.members.count(), 1)
def test_update_member(self): team = TeamService.create(self.admin, "Hunditeam__", {}) membership = TeamMembershipService.add_member( self.admin, team.pk, {}, self.user.pk ) team.refresh_from_db() self.assertEqual(team.members.count(), 2) TeamMembershipService.update_member( self.admin, team.id, self.user.id, role=TeamRoleChoices.ADMIN )
def mutate(self, info, name, keys): user = get_user_from_info(info) c_keys = {} for key in keys: c_keys[int(from_global_id( key["encryption_key_id"])[1])] = key["key"] try: result = TeamService.create(user, name=name, keys=c_keys) except TeamService.exceptions as e: raise MutationExecutionException(str(e)) return CreateTeam(success=True, team=result)
def mutate(self, info, public_key, csr, team_id): user = get_user_from_info(info) try: result = TeamService.add_csr( user, team_id=int(from_global_id(team_id)[1]), public_key=public_key, csr=csr, ) except TeamService.exceptions as e: raise MutationExecutionException(str(e)) return AddCSRForTeam(success=True, team=result)
def setUp(self): create_groups.Command().handle() self.user = get_user_model().objects.create(username="******") self.admin = get_user_model().objects.create(username="******") self.user.groups.add(AdministrativeStaffGroup) self.admin.groups.add(InstanceAdminGroup) self.form = Form.objects.create( name="Hundiformular", description="Doggo", js_code="var foo;", xml_code="<xml></xml>", active=True, ) # create a group and add a form/user to it self.group = TeamService.create(self.admin, "Hunditeam", {}) create_mock_cert(self.group) TeamMembershipService.add_member(self.admin, team_id=self.group.id, keys={}, invited_user_id=self.user.id) self.form.teams.add(self.group)
def test_update_member_not_in_team(self): team = TeamService.create(self.admin, "Hunditeam__", {}) with self.assertRaises(TeamServiceException): TeamMembershipService.update_member( self.admin, team.id, self.user.id, role=TeamRoleChoices.ADMIN )
def test_add_member_unprivileged_user(self): team = TeamService.create(self.admin, "Hunditeam_", {}) with self.assertRaises(TeamServiceException): TeamMembershipService.add_member(self.user, team.pk, {}, self.user.id)
def test_add_member(self): team = TeamService.create(self.admin, "Hunditeam_", {}) TeamMembershipService.add_member(self.admin, team.pk, {}, self.user.id) team.refresh_from_db() self.assertEqual(team.members.count(), 2)
def test_create_team_unprivileged_user(self): with self.assertRaises(TeamServiceException): team = TeamService.create(self.user, "Hunditeam", {})
def test_create_team(self): team = TeamService.create(self.admin, "Hunditeam", {}) self.assertEqual(team.name, "Hunditeam") self.assertEqual(team.slug, "hunditeam") self.assertEqual(team.members.count(), 1)