def test_person_history_view(user, client, org_with_people): person = org_with_people.person_set.first() e1 = SingleDateTimeEventFactory.create(type_descriptor="MEETING", short_description="First Meeting") e2 = SingleDateTimeEventFactory.create(type_descriptor="MEETING", short_description="Second Meeting") e1.participants.add(person) e1.save() e2.participants.add(person) e2.save() client.force_login(user) response = client.get( reverse("organisations:person_contact_history", kwargs={"person_id": person.pk})) assert response.status_code == 200 html = response.content.decode("utf-8") assert "First Meeting" in html
def test_can_update_single_datetime_event_from_org(self, user, org_with_people, client): org_slug = org_with_people.slug people = org_with_people.person_set.all() e1 = SingleDateTimeEventFactory(type_descriptor="MEETING") _collected_p = [] for p in people: e1.participants.add(p) _collected_p.append((p.first_name, p.last_name)) e1.save() pk = e1.pk url = reverse("register:event_update_simple_event_from_org", args=[pk, org_slug]) client.force_login(user) response = client.get(url) assert response.status_code == 200 html = response.content.decode("utf-8") test_case.assertInHTML(" ".join(_collected_p[0]), html)
def test_meetings_in_organisation_detail_view(user, client, org_with_people): org_list_permission = Permission.objects.get(name="Can view organisation") assert user.user_permissions.count() == 0 user.user_permissions.add(org_list_permission) assert user.has_perm("organisations.view_organisation") user.save() person = org_with_people.person_set.first() e1 = SingleDateTimeEventFactory.create(type_descriptor="MEETING", short_description="First Meeting") e2 = SingleDateTimeEventFactory.create(type_descriptor="MEETING", short_description="Second Meeting") e1.participants.add(person) e1.save() e2.participants.add(person) e2.save() client.force_login(user) response = client.get( reverse("organisations:detail", kwargs={"slug": org_with_people.slug})) assert response.status_code == 200 html = response.content.decode("utf-8") assert "First Meeting" in html
def test_meeting_event_factory(): meeting = SingleDateTimeEventFactory.create(type_descriptor="MEETING") assert meeting.type_descriptor == "MEETING"
def test_can_get_all_single_datetime_events_involving_person(person): e = SingleDateTimeEventFactory.create(type_descriptor="MEETING", short_description="No desc") e.participants.add(person) events_involving_person = person.get_single_datetime_events() assert events_involving_person.first().short_description == "No desc"
def test_private_event_filter_for_contact_history_page(user, client, org_with_people): """ In this test we are creating five events, using two different users. Each event will be set to either private or not private. We are testing a function that will only allow private notes belonging to the logged in, or request.user user to be added to the view context. The context is not referred to here - only the utility function under test. The output from that filter function will go forward into the view context. """ person = org_with_people.person_set.first() e1_user = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="First Event with user", private=True, user=user, ) e2_user = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="Second Event with user", private=False, user=user, ) e3_user = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="Third Event with user", private=True, user=user, ) e1_user.participants.add(person) e1_user.save() e2_user.participants.add(person) e2_user.save() e3_user.participants.add(person) e3_user.save() user2 = get_user_model().objects.create(username="******", email="*****@*****.**", password="******") e1_user2 = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="First Event with USER2", private=False, user=user2, ) e2_user2 = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="Second Event with USER2", private=True, user=user2, ) e1_user2.participants.add(person) e1_user2.save() e2_user2.participants.add(person) e2_user2.save() client.force_login(user2) response = client.get( reverse("organisations:person_contact_history", kwargs={"person_id": person.pk})) assert response.status_code == 200 html = response.content.decode("utf-8") assert "First Event with user" not in html assert "Third Event with user" not in html
def test_logged_in_user_can_only_see_their_private_events( user, org_with_people, client): org_list_permission = Permission.objects.get(name="Can view organisation") assert user.user_permissions.count() == 0 user.user_permissions.add(org_list_permission) assert user.has_perm("organisations.view_organisation") user.save() person = org_with_people.person_set.first() # This user creates three events e1 = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="First Event", private=True, user=user, ) e2 = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="Second Event", private=False, user=user, ) e3 = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="Third Event", private=True, user=user, ) e1.participants.add(person) e1.save() e2.participants.add(person) e2.save() e3.participants.add(person) e3.save() response = client.get( reverse("organisations:detail", kwargs={"slug": org_with_people.slug})) assert response.status_code == 200 html = response.content.decode("utf-8") assert "First Event" in html assert "Second Event" in html assert "Third Event" in html assert "PRIVATE" in html # A second user adds events based on this person/organisation user2 = get_user_model().objects.create(username="******", email="*****@*****.**", password="******") user2.user_permissions.add(org_list_permission) assert user2.has_perm("organisations.view_organisation") user2.save() client.logout() client.force_login(user2) response2 = client.get( reverse("organisations:detail", kwargs={"slug": org_with_people.slug})) html2 = response2.content.decode("utf-8") assert response2.status_code == 200 # They should not be able to see First Event which was created by another # user and marked private. assert "First Event" not in html2 assert "Second Event" in html2 assert "Third Event" not in html2
def test_private_event_filter(user, org_with_people): """ In this test we are creating five events, using two different users. Each event will be set to either private or not private. We are testing a function that will only allow private notes belonging to the logged in, or request.user user to be added to the view context. The context is not referred to here - only the utility function under test. The output from that filter function will go forward into the view context. """ person = org_with_people.person_set.first() e1_user = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="First Event with user", private=True, user=user, ) e2_user = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="Second Event with user", private=False, user=user, ) e3_user = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="Third Event with user", private=True, user=user, ) e1_user.participants.add(person) e1_user.save() e2_user.participants.add(person) e2_user.save() e3_user.participants.add(person) e3_user.save() user2 = get_user_model().objects.create(username="******", email="*****@*****.**", password="******") e1_user2 = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="First Event with user2", private=False, user=user2, ) e2_user2 = SingleDateTimeEventFactory( type_descriptor="MEETING", short_description="Second Event with user2", private=True, user=user2, ) e1_user2.participants.add(person) e1_user2.save() e2_user2.participants.add(person) e2_user2.save() # This user needs permission to access the list view org_list_permission = Permission.objects.get(name="Can view organisation") assert user.user_permissions.count() == 0 user.user_permissions.add(org_list_permission) assert user.has_perm("organisations.view_organisation") user.save() factory = RequestFactory() request = factory.get( reverse("organisations:detail", args=[org_with_people.slug])) request.user = user response = OrganisationDetailView.as_view()(request, slug=org_with_people.slug) assert response.status_code == 200 events = person.get_single_datetime_events() assert events.count() == 5 assert len(filter_private_events(events, user2)) == 3