def setUp(self): self.user = UserFactory() self.user2 = UserFactory(is_staff=True) self.user3 = UserFactory(username="******", is_staff=True) adminGrp, created = Group.objects.get_or_create(name="admin") self.user2.groups.add(adminGrp) self.ticket = TicketFactory(submitted_by=self.user)
def setUp(self): self.user = UserFactory() self.user2 = UserFactory(is_staff=True) self.user3 = UserFactory(username="******") adminGrp, created = Group.objects.get_or_create(name="admin") self.user2.groups.add(adminGrp) self.ticket = TicketFactory() self.ticket2 = TicketFactory(description="This is a duplicate")
def handle(self, *args, **options): self.stdout.write(self.style.SUCCESS('Process startes')) User = get_user_model() admin_user = User.objects.create_superuser(email="*****@*****.**", password="******") self.stdout.write(self.style.SUCCESS('User created')) TicketFactory.create_batch(5) TicketFactory.create_batch(5, user=admin_user) self.stdout.write(self.style.SUCCESS('Tickets successfully created'))
def setUp(self): self.user = UserFactory(username="******", first_name="Bart", last_name="Simpson") # self.user2 = UserFactory(is_staff=True) self.user2 = UserFactory( username="******", first_name="Barney", last_name="Gumble", password="******", is_staff=True, ) self.user3 = UserFactory(username="******", first_name="Homer", last_name="Simpson") adminGrp, created = Group.objects.get_or_create(name="admin") self.user2.groups.add(adminGrp) self.status = "new" self.ticket_type = "bug" self.description = "There is something wrong." self.priority = 3 self.ticket = TicketFactory( submitted_by=self.user, status=self.status, ticket_type=self.ticket_type, description=self.description, priority=self.priority, )
def test_create_ticket(self): api_client = APIClient() user = UserFactory() payload = { 'category_id': 1, } api_client.force_authenticate(user=user) ticket = TicketFactory() with \ patch.object( PermissionsService, 'get_category_permissions', return_value=Permissions.with_mutate_permissions(), ) as mocked_get_permissions, \ patch.object(TicketService, 'create_ticket', return_value=ticket) as mocked_create_ticket: response = api_client.post('/api/v1/tickets', data=payload, format='json') self.assertEqual(response.status_code, 201) mocked_get_permissions.assert_called_with( user_id=user.id, category_id=payload['category_id'], ) mocked_create_ticket.assert_called_with( category_id=payload['category_id'], ) expected_response = { 'id': str(ticket.id), 'category_id': str(ticket.category_id), 'priority': ticket.priority, } self.assertDictEqual(response.data, expected_response)
def setUp(self): self.user = UserFactory() desc = "This is the first ticket" self.ticket = TicketFactory(submitted_by=self.user, description=desc) desc = "This is a duplicate of ticket1" self.ticket2 = TicketFactory(description=desc) desc = "This will be the 1st child of ticket1" self.ticket3 = TicketFactory(submitted_by=self.user, description=desc, parent=self.ticket) # flag ticket 2 as a duplicate of the first self.ticket2.duplicate_of(self.ticket.id)
def setUp(self): """we will need some users, a ticket, and some private and public comments. """ self.user1 = UserFactory(username="******") self.user2 = UserFactory(username="******") self.user3 = UserFactory(username="******") # make user 2 an administrator adminGrp, created = Group.objects.get_or_create(name="admin") self.user2.groups.add(adminGrp) self.ticket = TicketFactory(submitted_by=self.user1) self.msg1 = "This is a public message posted by George" self.comment1 = FollowUpFactory( ticket=self.ticket, submitted_by=self.user1, comment=self.msg1 ) self.msg2 = "This is a public message posted by Homer" self.comment2 = FollowUpFactory( ticket=self.ticket, submitted_by=self.user2, comment=self.msg2 ) self.msg3 = "This is a PRIVATE message posted by George" self.comment3 = FollowUpFactory( ticket=self.ticket, submitted_by=self.user1, comment=self.msg3, private=True ) self.msg4 = "This is a PRIVATE message posted by Homer" self.comment4 = FollowUpFactory( ticket=self.ticket, submitted_by=self.user2, comment=self.msg4, private=True )
def test_ticket_permissions_for_board_member(self): board_membership = BoardMembershipFactory() ticket = TicketFactory(category=CategoryFactory(board_id=board_membership.board_id)) permissions = PermissionsService.get_ticket_permissions( ticket_id=ticket.id, user_id=board_membership.organization_membership.user_id, ) self._assert_has_all_permissions(permissions)
def test_create_comment_board_membership_not_found(self): ticket = TicketFactory() with self.assertRaises(BoardMembershipNotFoundException): _ = CommentService.create_comment( ticket_id=ticket.id, user_id=-1, message='test_message', )
def setUp(self): self.user1 = UserFactory(first_name="Homer", last_name="Simpson") desc = "This ticket is new. findme." self.ticket1 = TicketFactory( status="new", submitted_by=self.user1, ticket_type="feature", title=desc, description=desc, ) desc = "This ticket is accepted." self.ticket2 = TicketFactory(status="accepted", submitted_by=self.user1, title=desc, description=desc) desc = "This ticket is assigned." self.ticket3 = TicketFactory( status="assigned", ticket_type="feature", title=desc, description=desc, assigned_to=self.user1, ) desc = "This ticket is reopened. findme." self.ticket4 = TicketFactory(status="reopened", title=desc, description=desc) desc = "This ticket is closed. findme" self.ticket5 = TicketFactory(status="closed", title=desc, description=desc) desc = "This ticket is a duplicate." self.ticket6 = TicketFactory(status="duplicate", title=desc, description=desc) desc = "This ticket is split." self.ticket7 = TicketFactory(status="split", title=desc, description=desc) # TODO - activate for inactive: desc = "This ticket is inactive. findme" self.ticket8 = TicketFactory(active=False, title=desc, description=desc)
def test_ticket_permissions_for_not_a_board_member(self): ticket = TicketFactory() organization_membership = OrganizationMembershipFactory( organization_id=ticket.category.board.organization_id, ) permissions = PermissionsService.get_ticket_permissions( ticket_id=ticket.id, user_id=organization_membership.user_id, ) self._assert_has_no_permissions(permissions)
def test_assign_member(self): board_membership = BoardMembershipFactory() ticket = TicketFactory(category__board_id=board_membership.board_id) ticket_assignment = TicketAssignmentService.create_ticket_assignment( ticket_id=ticket.id, board_membership_id=board_membership.id, ) self.assertIsNotNone(ticket_assignment) self.assertEqual(ticket_assignment.ticket_id, ticket.id) self.assertEqual(ticket_assignment.assignee_id, board_membership.id)
def setUp(self): """ """ """create a user, some languages and three snippets""" self.user1 = UserFactory(username="******") self.ticket1 = TicketFactory(submitted_by=self.user1) self.ticket2 = TicketFactory(submitted_by=self.user1) self.ticket3 = TicketFactory(submitted_by=self.user1)
def test_update_ticket(self): ticket = TicketFactory() data = { 'title': 'Hey, I`m a Ticket', 'body': 'Hey, I`m a Ticket`s body', 'due_date': datetime(2020, 12, 12), } updated_ticket = TicketService.update_ticket(ticket.id, data) self.assertEqual(updated_ticket.id, ticket.id) self.assertEqual(updated_ticket.category_id, ticket.category_id) self.assertEqual(updated_ticket.title, data['title']) self.assertEqual(updated_ticket.body, data['body']) self.assertEqual(updated_ticket.due_date, data['due_date'])
def setUp(self): self.user = UserFactory(username="******", first_name="Bart", last_name="Simpson") self.user2 = UserFactory(username="******", first_name="Barney", last_name="Gumble", is_staff=True) adminGrp, created = Group.objects.get_or_create(name="admin") self.user2.groups.add(adminGrp) self.ticket = TicketFactory()
def test_create_comment(self): ticket = TicketFactory() board_membership = BoardMembershipFactory( board_id=ticket.category.board_id) comment = CommentService.create_comment( ticket_id=ticket.id, user_id=board_membership.organization_membership.user_id, message='test_message', ) self.assertIsNotNone(comment) self.assertEqual(comment.message, 'test_message') self.assertEqual(comment.ticket_id, ticket.id) self.assertEqual(comment.author_id, board_membership.id)
def test_update_ticket(self): api_client = APIClient() user = UserFactory() payload = { 'title': 'Some Title', 'body': 'Some Body', 'due_date': '2021-01-01', } api_client.force_authenticate(user=user) ticket = TicketFactory() with \ patch.object( PermissionsService, 'get_ticket_permissions', return_value=Permissions.with_mutate_permissions(), ) as mocked_get_ticket_permissions, \ patch.object(TicketService, 'update_ticket', return_value=ticket) as mocked_update_ticket: response = api_client.patch('/api/v1/tickets/1', data=payload, format='json') self.assertEqual(response.status_code, 200) mocked_get_ticket_permissions.assert_called_with( user_id=user.id, ticket_id=1, ) mocked_update_ticket.assert_called_with(ticket_id=1, validated_data={ 'title': payload['title'], 'body': payload['body'], 'due_date': date.fromisoformat( payload['due_date']), }) expected_response = { 'id': str(ticket.id), 'title': ticket.title, 'body': ticket.body, 'due_date': ticket.due_date.isoformat(), 'priority': ticket.priority, 'category_id': str(ticket.category_id), } self.assertDictEqual(response.data, expected_response)
def handle(self, *args, **options): self.stdout.write(self.style.SUCCESS('Process started')) count = options['count'][0] TicketFactory.create_batch(count) self.stdout.write(self.style.SUCCESS('Tickets successfully created'))
def setUp(self): self.user = UserFactory(username="******", password="******") self.ticket = TicketFactory()
class TicketTestCase(TestCase): """Verify that the ticket detail view renders all of the required information inlcuding links to parent and child tickets as well as any duplicates/original. """ def setUp(self): self.user = UserFactory() desc = "This is the first ticket" self.ticket = TicketFactory(submitted_by=self.user, description=desc) desc = "This is a duplicate of ticket1" self.ticket2 = TicketFactory(description=desc) desc = "This will be the 1st child of ticket1" self.ticket3 = TicketFactory(submitted_by=self.user, description=desc, parent=self.ticket) # flag ticket 2 as a duplicate of the first self.ticket2.duplicate_of(self.ticket.id) def test_ticket_detail(self): """make sure that all of the relevant details appear on the basic detail page """ url = reverse("tickets:ticket_detail", kwargs={"pk": self.ticket.id}) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") self.assertContains(response, self.ticket.description) self.assertContains(response, self.ticket.priority) self.assertContains(response, self.ticket.votes) self.assertContains(response, self.user.username) self.assertContains(response, "Priority:") self.assertContains(response, "Opened:") self.assertContains(response, "Last modified:") self.assertContains(response, "Submitted by:") self.assertContains(response, "Assigned to:") self.assertContains(response, "Comments:") self.assertNotContains(response, "Parent Ticket:") def test_ticket_detail_includes_parent_id(self): """if a ticket has a parent, make sure that the view includes a link back to its parent """ # ticket ticket is the parent of ticket 1 url = reverse("tickets:ticket_detail", kwargs={"pk": self.ticket3.id}) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") self.assertContains(response, "Parent Ticket") # there should be a link to the parent ticket in the response url = reverse("tickets:ticket_detail", kwargs={"pk": self.ticket.id}) linktext = '<a href="{0}">{1}... (ticket #{2})</a>' linktext = linktext.format(url, self.ticket, self.ticket.id) self.assertContains(response, linktext, html=True) def test_ticket_detail_includes_child_info(self): """if a ticket has a child, make sure that the view includes a link back to its the child """ # ticket ticket is the parent of ticket 1 url = reverse("tickets:ticket_detail", kwargs={"pk": self.ticket.id}) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") self.assertContains(response, "Child Ticket(s)") # there should be a link to the child ticket in the response url = reverse("tickets:ticket_detail", kwargs={"pk": self.ticket3.id}) linktext = '<a href="{0}">{1} (ticket #{2})</a>' linktext = linktext.format(url, self.ticket3, self.ticket3.id) self.assertContains(response, linktext, html=True) def test_ticket_detail_duplicate_id(self): """if a ticket has duplicates associated with it, make sure that the view includes a linke back to them. """ # ticket had has a duplicate url = reverse("tickets:ticket_detail", kwargs={"pk": self.ticket.id}) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") self.assertContains(response, "This ticket has been duplicated by") # there should be a link to the duplicate ticket in the response url = reverse("tickets:ticket_detail", kwargs={"pk": self.ticket2.id}) linktext = '<a href="{0}">{1} (ticket #{2})</a>' linktext = linktext.format(url, self.ticket2, self.ticket2.id) self.assertContains(response, linktext, html=True) def test_ticket_detail_original_id(self): """if a ticket has been flagged as a duplicate, make sure that the view includes a link back to the orginal ticket """ # this ticket has been flagged as a duplicate url = reverse("tickets:ticket_detail", kwargs={"pk": self.ticket2.id}) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") self.assertContains(response, "This ticket duplicates ticket(s):") # there should be a link to the child ticket in the response url = reverse("tickets:ticket_detail", kwargs={"pk": self.ticket.id}) linktext = '<a href="{0}">{1} (ticket #{2})</a>' linktext = linktext.format(url, self.ticket, self.ticket.id) self.assertContains(response, linktext, html=True)
def test_is_closed(self): obj = TicketFactory() self.assertFalse(obj.is_closed()) obj.status = 4 self.assertTrue(obj.is_closed())
class CloseTicketTestCase(WebTest): """ """ def setUp(self): self.user = UserFactory() self.user2 = UserFactory(is_staff=True) self.user3 = UserFactory(username="******") adminGrp, created = Group.objects.get_or_create(name="admin") self.user2.groups.add(adminGrp) self.ticket = TicketFactory() self.ticket2 = TicketFactory(description="This is a duplicate") def test_close_ticket_admin(self): """if you're an administator, you should be able to close a ticket """ login = self.client.login(username=self.user2.username, password="******") self.assertTrue(login) url = reverse("tickets:close_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=self.user2) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/close_reopen_ticket_form.html") form = response.forms["comment"] form["comment"] = "This feature has been implemented" response = form.submit().follow() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") self.assertContains(response, "This feature has been implemented") ticket = Ticket.objects.get(id=self.ticket.id) self.assertEqual(ticket.status, "closed") def test_close_ticket_non_admin(self): """if you're an not administator, you should NOT be able to close a ticket. Instead, you will be re-directed to the ticket list. """ myuser = self.user login = self.client.login(username=myuser.username, password="******") self.assertTrue(login) url = reverse("tickets:close_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=myuser).follow() self.assertTemplateUsed(response, "tickets/ticket_detail.html") self.assertEqual(response.status_code, 200) def test_reopen_ticket_admin(self): """if you're an administator, you should be able to reopen a ticket """ # make sure that the ticket is closed before we do anything self.ticket = Ticket.objects.get(id=self.ticket.id) self.ticket.status = "closed" self.ticket.save() self.assertEqual(self.ticket.status, "closed") login = self.client.login(username=self.user2.username, password="******") self.assertTrue(login) url = reverse("tickets:reopen_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=self.user2) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/close_reopen_ticket_form.html") form = response.forms["comment"] msg = "This ticket needs to be reopened" form["comment"] = msg response = form.submit().follow() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") self.assertContains(response, msg) ticket = Ticket.objects.get(id=self.ticket.id) self.assertEqual(ticket.status, "reopened") def test_reopen_ticket_non_admin(self): """if you're an not administator, you should NOT be able to reopen a ticket. You will be re-directed to its detail page. """ # make sure that the ticket is closed before we do anything self.ticket = Ticket.objects.get(id=self.ticket.id) self.ticket.status = "closed" self.ticket.save() self.assertEqual(self.ticket.status, "closed") myuser = self.user login = self.client.login(username=myuser.username, password="******") self.assertTrue(login) url = reverse("tickets:reopen_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=myuser).follow() self.assertTemplateUsed(response, "tickets/ticket_detail.html") self.assertEqual(response.status_code, 200) # make sure that the ticket is still closed self.ticket = Ticket.objects.get(id=self.ticket.id) self.ticket.status = "closed" self.ticket.save() self.assertEqual(self.ticket.status, "closed") def test_close_ticket_as_duplicate_admin(self): """if you're an administator, you should be able to close a ticket as a duplicate """ # verify that a comment was created and that the status of the # original ticket has been updated accordingly login = self.client.login(username=self.user2.username, password="******") self.assertTrue(login) url = reverse("tickets:close_ticket", kwargs=({"pk": self.ticket2.id})) response = self.app.get(url, user=self.user2) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/close_reopen_ticket_form.html") form = response.forms["comment"] msg = "This ticket is a duplicate of an earlier ticket" form["comment"] = msg form["duplicate"].checked = True form["same_as_ticket"] = self.ticket.id response = form.submit().follow() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") # verify that the message appears in the response: self.assertContains(response, msg) self.assertContains(response, "This ticket duplicates ticket(s):") # check that the status of ticket 2 has been updated ticket = Ticket.objects.get(id=self.ticket2.id) self.assertEqual(ticket.status, "duplicate") # get the original ticket for ticket 2 and verify that it is ticket 1 original = ticket.get_originals() self.assertEqual(self.ticket, original[0].original) def test_close_ticket_as_duplicate_to_self(self): """If the ticket number entered in same_as_ticket is the same as the current ticket, the form should throw an error """ login = self.client.login(username=self.user2.username, password="******") self.assertTrue(login) url = reverse("tickets:close_ticket", kwargs=({"pk": self.ticket2.id})) response = self.app.get(url, user=self.user2) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/close_reopen_ticket_form.html") form = response.forms["comment"] msg = "This ticket is a duplicate of an earlier ticket" form["comment"] = msg form["duplicate"].checked = True form["same_as_ticket"] = self.ticket2.id response = form.submit() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/close_reopen_ticket_form.html") errmsg = "Invalid ticket number. A ticket cannot duplicate itself." self.assertContains(response, msg) self.assertContains(response, errmsg) ticket = Ticket.objects.get(id=self.ticket2.id) self.assertEqual(ticket.status, "new") def test_close_ticket_as_duplicate_missing_ticket(self): """If you forget to provide a duplicate ticket, the form should throw an error """ login = self.client.login(username=self.user2.username, password="******") self.assertTrue(login) url = reverse("tickets:close_ticket", kwargs=({"pk": self.ticket2.id})) response = self.app.get(url, user=self.user2) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/close_reopen_ticket_form.html") form = response.forms["comment"] msg = "This ticket is a duplicate of an earlier ticket" form["comment"] = msg form["duplicate"].checked = True response = form.submit() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/close_reopen_ticket_form.html") errmsg = "Duplicate is true but no ticket number is provided." self.assertContains(response, msg) self.assertContains(response, errmsg) ticket = Ticket.objects.get(id=self.ticket2.id) self.assertEqual(ticket.status, "new") def test_close_ticket_as_duplicate_missing_check(self): """If you forget to check the duplicate box but provide a number, the form should throw an error """ # verify that a comment was created and that the status of the # original ticket has been updated accordingly login = self.client.login(username=self.user2.username, password="******") self.assertTrue(login) url = reverse("tickets:close_ticket", kwargs=({"pk": self.ticket2.id})) response = self.app.get(url, user=self.user2) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/close_reopen_ticket_form.html") form = response.forms["comment"] msg = "This ticket is a duplicate of an earlier ticket" form["comment"] = msg form["same_as_ticket"] = 1 response = form.submit() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/close_reopen_ticket_form.html") errmsg = "Duplicate is false and a ticket number was provided." self.assertContains(response, msg) self.assertContains(response, errmsg) # verify that the status of ticket2 has not been changed. ticket = Ticket.objects.get(id=self.ticket2.id) self.assertEqual(ticket.status, "new") def test_close_non_existent_ticket(self): """if you try to comment on an non-existent ticket, you will be re-directed to ticket list. """ myuser = self.user2 login = self.client.login(username=myuser.username, password="******") self.assertTrue(login) url = reverse("tickets:close_ticket", kwargs=({"pk": 999})) response = self.app.get(url, user=myuser).follow() self.assertTemplateUsed(response, "tickets/ticket_list.html") self.assertEqual(response.status_code, 200)
def test_model(self): obj = TicketFactory() self.assertTrue(obj.pk)
class CommentTicketTestCase(WebTest): """TicketCommentView is used to provide comments, but is also used to accept, assign and re-assign tickets. anybod should be able to accept tickets, only admins should be able to assign and re-assign tickets. """ def setUp(self): self.user = UserFactory() self.user2 = UserFactory(is_staff=True) self.user3 = UserFactory(username="******", is_staff=True) adminGrp, created = Group.objects.get_or_create(name="admin") self.user2.groups.add(adminGrp) self.ticket = TicketFactory(submitted_by=self.user) def test_comment_non_existent_ticket(self): """if we try to comment on a ticket that does not exist, we should be re-directed to the ticket list. """ myuser = self.user2 login = self.client.login(username=myuser.username, password="******") self.assertTrue(login) url = reverse("tickets:comment_ticket", kwargs=({"pk": 99})) response = self.app.get(url, user=myuser).follow() self.assertTemplateUsed(response, "tickets/ticket_list.html") self.assertEqual(response.status_code, 200) def test_comment_not_logged_in(self): """if you're not logged in you shouldn't be able to comment on a ticket """ url = reverse("tickets:comment_ticket", kwargs=({ "pk": self.ticket.id })) response = self.app.get(url) location = response["Location"] new_url = "{0}?next={1}".format(reverse("login"), url) self.assertRedirects(response, new_url) self.assertIn(new_url, location) def test_comment_logged_in_not_admin(self): """you don't have to be an admin to comment on a ticket - just logged in """ login = self.client.login(username=self.user.username, password="******") self.assertTrue(login) url = reverse("tickets:comment_ticket", kwargs=({ "pk": self.ticket.id })) response = self.app.get(url, user=self.user) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/comment_form.html") form = response.forms["comment"] form["comment"] = "What a great idea" response = form.submit().follow() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") self.assertContains(response, "What a great idea") def test_private_comment_logged_in_not_admin_or_creator(self): """you can't leave a private comment if you are not an admin or the ticket creator """ myuser = self.user3 login = self.client.login(username=myuser, password="******") self.assertTrue(login) url = reverse("tickets:comment_ticket", kwargs=({ "pk": self.ticket.id })) response = self.app.get(url, user=myuser) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/comment_form.html") form = response.forms["comment"] # private should not be on of the available fields. self.assertNotIn("private", form.fields.keys()) def test_private_comment_logged_in_admin(self): """you can leave a private comment if you are an admin """ myuser = self.user2 login = self.client.login(username=myuser, password="******") self.assertTrue(login) url = reverse("tickets:comment_ticket", kwargs=({ "pk": self.ticket.id })) response = self.app.get(url, user=myuser) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/comment_form.html") form = response.forms["comment"] form["comment"] = "What a great idea" form["private"] = True response = form.submit().follow() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") self.assertContains(response, "What a great idea") self.assertContains(response, "private") comment = FollowUp.all_comments.filter(ticket=self.ticket) self.assertEqual(comment.count(), 1) self.assertTrue(comment[0].private) def test_private_comment_logged_in_creator(self): """you can leave a private comment if you are the ticket creator """ myuser = self.user login = self.client.login(username=myuser, password="******") self.assertTrue(login) url = reverse("tickets:comment_ticket", kwargs=({ "pk": self.ticket.id })) response = self.app.get(url, user=myuser) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/comment_form.html") form = response.forms["comment"] form["comment"] = "What a great idea" form["private"] = True response = form.submit().follow() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") self.assertContains(response, "What a great idea") self.assertContains(response, "private") comment = FollowUp.all_comments.filter(ticket=self.ticket) self.assertEqual(comment.count(), 1) self.assertTrue(comment[0].private) def test_comment_bad_data_logged_in(self): """you comment is a manditory field. An error will be thown if you don't provide one. """ login = self.client.login(username=self.user.username, password="******") self.assertTrue(login) url = reverse("tickets:comment_ticket", kwargs=({ "pk": self.ticket.id })) response = self.app.get(url, user=self.user) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/comment_form.html") form = response.forms["comment"] response = form.submit() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/comment_form.html") errmsg = "This field is required." self.assertContains(response, errmsg) def test_accept_ticket_unlogged_user(self): """ A user who is not logged in should not be able to accept a ticket. If they try, they should be re-directed to the ticket detail page and the ticket should remain unassigned. Arguments: - `self`: """ assert self.ticket.assigned_to is None assert self.ticket.status == "new" url = reverse("tickets:accept_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=self.user).follow() self.assertEqual(response.status_code, 200) url = reverse("tickets:ticket_detail", kwargs=({"pk": self.ticket.id})) self.assertTemplateUsed(response, "tickets/ticket_detail.html") assert self.ticket.assigned_to is None assert self.ticket.status == "new" def test_assign_ticket_unlogged_user(self): """ A user who is not logged in should not be able to assign a ticket. If they try, they should be re-directed to the ticket detail page and the ticket should remain unassigned. Arguments: - `self`: """ assert self.ticket.assigned_to is None assert self.ticket.status == "new" url = reverse("tickets:assign_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=self.user).follow() self.assertEqual(response.status_code, 200) url = reverse("tickets:ticket_detail", kwargs=({"pk": self.ticket.id})) self.assertTemplateUsed(response, "tickets/ticket_detail.html") assert self.ticket.assigned_to is None assert self.ticket.status == "new" def test_reassign_ticket_unlogged_user(self): """ A user who is not logged in should not be able to re-assign a ticket. If they try, they should be re-directed to the ticket detail page and the ticket should remain assigned to the original user. Arguments: - `self`: """ self.ticket.assigned_to = self.user3 self.ticket.status = "assigned" self.ticket.save() assert self.ticket.assigned_to == self.user3 assert self.ticket.status == "assigned" url = reverse("tickets:assign_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=self.user).follow() self.assertEqual(response.status_code, 200) url = reverse("tickets:ticket_detail", kwargs=({"pk": self.ticket.id})) self.assertTemplateUsed(response, "tickets/ticket_detail.html") # nothing has changed assert self.ticket.assigned_to == self.user3 assert self.ticket.status == "assigned" def test_accept_ticket_user(self): """ If someone who is not an admin tries to accept a ticket A logged in user should be able to accept a ticket. Once accepted, the ticket should be assigned to them. When the form loads, it should not contain the 'Assign To' dropdown box. Arguments: - `self`: """ # verify that our ticket is not assigned to anyone yet assert self.ticket.assigned_to is None assert self.ticket.status == "new" login = self.client.login(username=self.user.username, password="******") self.assertTrue(login) url = reverse("tickets:accept_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=self.user).follow() self.assertEqual(response.status_code, 200) url = reverse("tickets:ticket_detail", kwargs=({"pk": self.ticket.id})) self.assertTemplateUsed(response, "tickets/ticket_detail.html") assert self.ticket.assigned_to is None assert self.ticket.status == "new" def test_accept_ticket_admin(self): """ An admin user should be able to accept a ticket. Once accepted, the status of the ticket will be 'accepted' but it will not be assigned to anyone. Arguments: - `self`: """ # verify that our ticket is not assigned to anyone yet assert self.ticket.assigned_to is None assert self.ticket.status == "new" login = self.client.login(username=self.user.username, password="******") self.assertTrue(login) url = reverse("tickets:accept_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=self.user2) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/comment_form.html") msg = "Accept Ticket #{}" self.assertContains(response, msg.format(self.ticket.id)) form = response.forms["comment"] form["comment"] = "I can do it." response = form.submit().follow() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") # our user should now be assigned to this ticket. ticket = Ticket.objects.get(id=self.ticket.id) assert ticket.assigned_to is None assert ticket.status == "accepted" def test_assign_ticket_user(self): """ A user who is not an administrator should not be able to assign a ticket. If they try, they should be re-directed to the ticket detail page, and the ticket should remain unassigned Arguments: - `self`: """ assert self.ticket.assigned_to is None assert self.ticket.status == "new" login = self.client.login(username=self.user.username, password="******") self.assertTrue(login) url = reverse("tickets:assign_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=self.user).follow() self.assertEqual(response.status_code, 200) url = reverse("tickets:ticket_detail", kwargs=({"pk": self.ticket.id})) self.assertTemplateUsed(response, "tickets/ticket_detail.html") assert self.ticket.assigned_to is None assert self.ticket.status == "new" def test_assign_ticket_admin(self): """ An administator should be able assign a ticket to another user. Arguments: - `self`: """ # verify that our ticket is not assigned to anyone yet assert self.ticket.assigned_to is None assert self.ticket.status == "new" login = self.client.login(username=self.user.username, password="******") self.assertTrue(login) url = reverse("tickets:assign_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=self.user2) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/comment_form.html") msg = "Assign Ticket #{}" self.assertContains(response, msg.format(self.ticket.id)) form = response.forms["comment"] form["comment"] = "I have just the person." form["assigned_to"] = self.user3.id response = form.submit().follow() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") # our user should now be assigned to this ticket. ticket = Ticket.objects.get(id=self.ticket.id) assert ticket.assigned_to == self.user3 assert ticket.status == "assigned" def test_reassign_ticket_user(self): """ A user who is not an administrator should not be able to re-assign a ticket. If they try, they should be re-directed to the ticket detail page, and the ticket should remain assigned to the original user. Arguments: - `self`: """ # assign our ticket to a user and change its status self.ticket.assigned_to = self.user3 self.ticket.status = "assigned" self.ticket.save() # verify that our chages worked assert self.ticket.assigned_to == self.user3 assert self.ticket.status == "assigned" login = self.client.login(username=self.user.username, password="******") self.assertTrue(login) url = reverse("tickets:assign_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=self.user).follow() self.assertEqual(response.status_code, 200) url = reverse("tickets:ticket_detail", kwargs=({"pk": self.ticket.id})) self.assertTemplateUsed(response, "tickets/ticket_detail.html") # nothing has changed assert self.ticket.assigned_to == self.user3 assert self.ticket.status == "assigned" def test_reassign_ticket_admin(self): """ An administator should be able reassign a ticket to another user. Arguments: - `self`: """ # assign our ticket to a user and change its status self.ticket.assigned_to = self.user2 self.ticket.status = "assigned" self.ticket.save() login = self.client.login(username=self.user.username, password="******") self.assertTrue(login) url = reverse("tickets:assign_ticket", kwargs=({"pk": self.ticket.id})) response = self.app.get(url, user=self.user2) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/comment_form.html") msg = "Assign Ticket #{}" self.assertContains(response, msg.format(self.ticket.id)) form = response.forms["comment"] form["comment"] = "I have just the person." form["assigned_to"] = self.user3.id response = form.submit().follow() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "tickets/ticket_detail.html") # our user should now be assigned to this ticket. ticket = Ticket.objects.get(id=self.ticket.id) assert ticket.assigned_to == self.user3 assert ticket.status == "assigned"
def test_assign_member_board_membership_not_found(self): ticket = TicketFactory() with self.assertRaises(BoardMembershipNotFoundException): _ = TicketAssignmentService.create_ticket_assignment( ticket_id=ticket.id, board_membership_id=-1)
def test_ticket_permissions_for_a_random_user(self): permissions = PermissionsService.get_ticket_permissions( ticket_id=TicketFactory().id, user_id=UserFactory().id, ) self._assert_has_no_permissions(permissions)
class ProjectTaggingTestCase(TestCase): """Verify that the projects can be tagged with keywords in the project form.""" def setUp(self): """ """ """create a user, some languages and three snippets""" self.user1 = UserFactory(username="******") self.ticket1 = TicketFactory(submitted_by=self.user1) self.ticket2 = TicketFactory(submitted_by=self.user1) self.ticket3 = TicketFactory(submitted_by=self.user1) def tearDown(self): """ """ self.ticket2.delete() self.ticket1.delete() self.user1.delete() def test_tags_in_snippet_details_view(self): """verify that the tags associated with a snippet appear on its details (and not on others)""" # assign some tags to project1 tags = ["red", "blue", "green", "yellow"] tags.sort() for tag in tags: self.ticket1.tags.add(tag) # ======================= # verify that the tags are associated with that project tags_back = self.ticket1.tags.all().order_by("name") self.assertQuerysetEqual(tags_back, tags, lambda a: str(a.name)) self.assertEqual(tags_back.count(), len(tags)) # verify that the tag appears as a hyperlink on the details # page for this project: response = self.client.get(reverse("tickets:ticket_detail", args=(self.ticket1.pk, )), user=self.user1) self.assertEqual(response.status_code, 200) linkstring_base = '<a href="{}">{}</a>' for tag in tags: tag_url = reverse("tickets:tickets_tagged_with", args=(tag, )) linkstring = linkstring_base.format(tag_url, tag) self.assertContains(response, linkstring) # ======================= # verify that the tags are NOT associated with project2 response = self.client.get(reverse("tickets:ticket_detail", args=(self.ticket2.pk, )), user=self.user1) self.assertEqual(response.status_code, 200) linkstring_base = '<a href="{}">{}</a>' for tag in tags: tag_url = reverse("tickets:tickets_tagged_with", args=(tag, )) linkstring = linkstring_base.format(tag_url, tag) self.assertNotContains(response, linkstring) def test_tags_ticket_list_view(self): """This test verifies that the url for 'tickets_tagged_with' returns just the tickets with that tag and includes an informative heading. Tags that do not have the specified tag, should not be included in the response. """ # tickets 1 and 2 will be tagged, ticket three is not: tags = ["red", "blue"] tags.sort() for tag in tags: self.ticket1.tags.add(tag) self.ticket2.tags.add(tag) # ======================= # verify that the tags are associated with that ticket tags_back = self.ticket1.tags.all().order_by("name") self.assertQuerysetEqual(tags_back, tags, lambda a: str(a.name)) tags_back = self.ticket2.tags.all().order_by("name") self.assertQuerysetEqual(tags_back, tags, lambda a: str(a.name)) # load the page associated with tag 1 and verify that it # contains records for tickett 1 and 2 (as hyperlinks), but # not ticket 3 response = self.client.get(reverse("tickets:tickets_tagged_with", args=(tags[0], )), user=self.user1) self.assertEqual(response.status_code, 200) self.assertTemplateUsed("tickets\ticket_list.html") msg = "Tickets Tagged with '{}'".format(tags[0]) self.assertContains(response, msg) link_base = '<td><a href="{}">{}</a></td>' ticket_list = [self.ticket1, self.ticket2, self.ticket3] for ticket in ticket_list[:2]: url = link_base.format(ticket.get_absolute_url(), ticket.id) self.assertContains(response, url, html=True) url = link_base.format(self.ticket3.get_absolute_url(), self.ticket3.id) self.assertNotContains(response, url, html=True) # ==================== # navigate to the whole ticket list and verify that it contain # records for all three tickets response = self.client.get(reverse("tickets:ticket_list"), user=self.user1) self.assertEqual(response.status_code, 200) for ticket in ticket_list: url = link_base.format(ticket.get_absolute_url(), ticket.id) self.assertContains(response, url, html=True)