def handle(self, *args, **options): test_user = UserFactory( first_name="Test", last_name="User", email="*****@*****.**", # /PS-IGNORE legacy_sso_user_id=None, username="******", # /PS-IGNORE sso_contact_email="*****@*****.**", # /PS-IGNORE ) self.stdout.write( self.style.SUCCESS( f"{test_user.first_name} {test_user.last_name} ({test_user.email}) was created" )) another_user = UserFactory( first_name="Another", last_name="User", email="*****@*****.**", # /PS-IGNORE legacy_sso_user_id=None, username="******", # /PS-IGNORE sso_contact_email="*****@*****.**", # /PS-IGNORE is_staff=False, is_superuser=False, ) self.stdout.write( self.style.SUCCESS( f"{another_user.first_name} {another_user.last_name} ({another_user.email}) was created" ))
def test_profile_delete_button_visible_with_permission(state): other_user = UserFactory( first_name="Other", last_name="User", email="*****@*****.**", # /PS-IGNORE legacy_sso_user_id=None, username="******", # /PS-IGNORE sso_contact_email="*****@*****.**", # /PS-IGNORE ) other_user.save() other_person = PersonService().create_user_profile(other_user) profile_url = reverse( "profile-view", kwargs={ "profile_slug": other_person.slug, }, ) delete_person_perm = Permission.objects.get(codename="delete_person") state.user.user_permissions.add(delete_person_perm) response = state.client.get(profile_url) assert response.status_code == 200 assert button_is_visible(response.content, "delete-profile")
def test_delete_view_with_other_users_profile(state): other_user = UserFactory( first_name="Other", last_name="User", email="*****@*****.**", # /PS-IGNORE legacy_sso_user_id=None, username="******", # /PS-IGNORE sso_contact_email="*****@*****.**", # /PS-IGNORE ) other_user.save() other_person = PersonService().create_user_profile(other_user) assert Person.objects.filter(pk=other_person.pk).exists() view_url = reverse( "profile-delete", kwargs={ "profile_slug": other_person.slug, }, ) response = state.client.post(view_url, follow=True) next_url, status_code = response.redirect_chain[0] assert status_code == 302 assert next_url == reverse("delete-confirmation") assert not Person.objects.filter(pk=other_person.pk).exists()
def test_profile_log_visible_permission(state): other_user = UserFactory(username="******", legacy_sso_user_id="other_user") other_user.save() other_person = PersonService().create_user_profile(other_user) view_url = reverse( "profile-view", kwargs={ "profile_slug": other_person.slug, }, ) response = state.client.get(view_url) assert response.status_code == 200 title = b"Audit log" assert title not in response.content soup = BeautifulSoup(response.content, features="html.parser") log_detail = soup.find_all(attrs={"data-module": "govuk-details"}) log_detail_len = len(log_detail) view_log_perm = Permission.objects.get(codename="view_auditlog") state.user.user_permissions.add(view_log_perm) response = state.client.get(view_url) assert response.status_code == 200 assert title in response.content soup = BeautifulSoup(response.content, features="html.parser") log_detail = soup.find_all(attrs={"data-module": "govuk-details"}) assert len(log_detail) == log_detail_len + 2
def state(db): team = Team.objects.all().last() if team == None: team = TeamFactory() user = UserFactory() user.save() person = PersonService().create_user_profile(user) client = Client() client.force_login(user) return State(client=client, person=person, team=team, user=user)
def test_empty_query(self): user = UserFactory() PersonService().create_user_profile(user) c = Client() c.force_login(user) response = c.get("/search/", {"query": ""}) self.assertEqual(response.status_code, 200)
def test_old_style_user_ignored(self): user_count = User.objects.count() sso_user_id = str(uuid.uuid4()) UserFactory( username=sso_user_id, email="*****@*****.**", first_name="Deborah", last_name="Test", legacy_sso_user_id=None, sso_contact_email="*****@*****.**", ) self.assertEqual( User.objects.get(email="*****@*****.**").username, sso_user_id, ) profile = { "email_user_id": "*****@*****.**", "email": "*****@*****.**", "contact_email": "*****@*****.**", "first_name": "Deborah", "last_name": "Test", "user_id": sso_user_id, } CustomAuthbrokerBackend.get_or_create_user(profile) self.assertEqual(User.objects.count(), user_count + 2) self.assertEqual( User.objects.filter(username=profile["email_user_id"]).count(), 1, )
def test_order_team_leaders(self, team_admin_user, software_team): red_leader = UserFactory( first_name="Red", last_name="Leader", email="*****@*****.**", legacy_sso_user_id=None, username="******", sso_contact_email="*****@*****.**", ) gold_leader = UserFactory( first_name="Gold", last_name="Leader", email="*****@*****.**", legacy_sso_user_id=None, username="******", sso_contact_email="*****@*****.**", ) call_command("create_user_profiles") red_leader_role, _ = red_leader.profile.roles.get_or_create( team=software_team, job_title="Product Manager", head_of_team=True, ) gold_leader_role, _ = gold_leader.profile.roles.get_or_create( team=software_team, job_title="Delivery Manager", head_of_team=True, ) r = self.client.get(reverse("team-edit", kwargs={"slug": "software"})) assert (r.context["team_leaders_order_component"]["ordering"] == Team.LeadersOrdering.ALPHABETICAL) members = r.context["team_leaders_order_component"]["members"] assert len(members) == 2 assert members[0]["pk"] == gold_leader_role.pk assert members[1]["pk"] == red_leader_role.pk r = self.client.post( reverse("team-edit", kwargs={"slug": "software"}), data={ "name": software_team.name, "abbreviation": software_team.abbreviation or "", "description": software_team.description, "parent_team": (TeamService().get_immediate_parent_team(software_team).pk), "leaders_ordering": Team.LeadersOrdering.CUSTOM, "leaders_positions": ",".join(map(str, [red_leader_role.pk, gold_leader_role.pk])), }, follow=True, ) assert r.status_code == 200 red_leader_role.refresh_from_db() gold_leader_role.refresh_from_db() assert red_leader_role.leaders_position == 0 assert gold_leader_role.leaders_position == 1