def setUp(self):
        jira_backend = 'waldur_mastermind.support.backend.atlassian:ServiceDeskBackend'
        settings.WALDUR_SUPPORT['ENABLED'] = True
        settings.WALDUR_SUPPORT['ACTIVE_BACKEND'] = jira_backend
        settings.task_always_eager = True
        self.issue = factories.IssueFactory()

        backend_issue_raw = json.loads(load_resource('jira_issue_raw.json'))
        self.backend_issue = jira.resources.Issue({'server': 'example.com'}, None, backend_issue_raw)
        self.backend = ServiceDeskBackend()
        self.impact_field_id = 'customfield_10116'

        path = mock.patch.object(ServiceDeskBackend, 'get_backend_issue',
                                 new=mock.Mock(return_value=self.backend_issue))
        path.start()

        self.first_response_sla = timezone.now()
        path = mock.patch.object(ServiceDeskBackend, '_get_first_sla_field',
                                 new=mock.Mock(return_value=self.first_response_sla))
        path.start()

        def side_effect(arg):
            if arg == 'Impact':
                return self.impact_field_id

        path = mock.patch.object(ServiceDeskBackend, 'get_field_id_by_name',
                                 new=mock.Mock(side_effect=side_effect))
        path.start()
    def setUp(self):
        jira_backend = 'waldur_mastermind.support.backend.atlassian:ServiceDeskBackend'
        settings.WALDUR_SUPPORT['ENABLED'] = True
        settings.WALDUR_SUPPORT['ACTIVE_BACKEND'] = jira_backend
        self.issue = factories.IssueFactory()

        backend_issue_raw = json.loads(load_resource('jira_issue_raw.json'))
        self.backend_issue = jira.resources.Issue({'server': 'example.com'}, None, backend_issue_raw)

        backend_attachment_raw = json.loads(load_resource('jira_attachment_raw.json'))
        self.backend_attachment = jira.resources.Attachment({'server': 'example.com'}, None, backend_attachment_raw)
        self.backend_issue.fields.attachment.append(self.backend_attachment)

        self.backend = ServiceDeskBackend()

        path = mock.patch.object(ServiceDeskBackend, 'get_backend_issue',
                                 new=mock.Mock(return_value=self.backend_issue))
        path.start()

        path = mock.patch.object(ServiceDeskBackend, 'get_backend_attachment',
                                 new=mock.Mock(return_value=self.backend_attachment))
        path.start()

        GIF = 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
        file_content = six.BytesIO(GIF.decode('base64'))
        path = mock.patch.object(AttachmentSynchronizer, '_download_file',
                                 new=mock.Mock(return_value=file_content))
        path.start()
Esempio n. 3
0
    def test_email_notification_is_not_sent_if_issue_status_is_ignored(self):
        issue = factories.IssueFactory()

        issue.status = factories.IgnoredIssueStatusFactory().name
        issue.save()

        self.assertEqual(len(mail.outbox), 0)
Esempio n. 4
0
 def create_issue(self):
     self.issue = support_factories.IssueFactory(backend_id='', key='')
     support_offering = support_factories.OfferingFactory(issue=self.issue)
     resource = marketplace_factories.ResourceFactory(scope=support_offering)
     self.order_item = marketplace_factories.OrderItemFactory(resource=resource, offering=self.offering)
     self.issue.backend_id = 'TST-1'
     self.issue.save()
Esempio n. 5
0
    def test_email_notification_is_not_sent_if_issue_just_has_been_created_on_backend(
        self, ):
        issue = factories.IssueFactory(backend_id='')
        issue.backend_id = 'new_backend_id'
        issue.save()

        self.assertEqual(len(mail.outbox), 0)
Esempio n. 6
0
    def test_email_notification_is_sent_when_issue_is_updated(self):
        issue = factories.IssueFactory()

        issue.summary = 'new_summary'
        issue.save()

        self.assertEqual(len(mail.outbox), 1)
Esempio n. 7
0
    def test_email_notification_is_not_sent_if_assignee_changes(self):
        issue = factories.IssueFactory()

        issue.assignee = factories.SupportUserFactory()
        issue.save()

        self.assertEqual(len(mail.outbox), 0)
Esempio n. 8
0
    def test_user_can_access_customer_issue_if_he_has_customer_level_permission(
            self, user):
        self.client.force_authenticate(getattr(self.fixture, user))
        issue = factories.IssueFactory(customer=self.fixture.customer)

        response = self.client.get(factories.IssueFactory.get_url(issue))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Esempio n. 9
0
    def test_pull_request_types(self):
        self._mock_jira()
        self.mock_jira().request_types.return_value = [
            RequestType(
                {'server': ''},
                None,
                raw={
                    'name': 'Help',
                    'id': '1',
                    'issueTypeId': '10101'
                },
            )
        ]
        self.mock_jira().issue_type.return_value = IssueType(
            {'server': ''}, None, raw={
                'name': 'Service Request',
                'id': '1'
            })

        issue_type = settings.WALDUR_SUPPORT['ISSUE']['types'][0]
        factories.RequestTypeFactory(issue_type_name=issue_type)
        issue = factories.IssueFactory(reporter=None,
                                       backend_id=None,
                                       type=issue_type)
        factories.SupportCustomerFactory(user=issue.caller)
        ServiceDeskBackend().create_issue(issue)
        self.assertEqual(models.RequestType.objects.count(), 1)
Esempio n. 10
0
    def test_web_hook_does_not_trigger_issue_update_email_if_the_issue_was_not_updated(
            self):
        fields = self.request_data['issue']['fields']
        reporter = factories.SupportUserFactory(
            backend_id=fields['reporter']['key'])
        assignee = factories.SupportUserFactory(
            backend_id=fields['assignee']['key'])
        first_response_sla = fields['customfield_10006']['ongoingCycle'][
            'breachTime']['epochMillis'] / 1000.0

        factories.IssueFactory(
            resolution=fields['resolution']['name'],
            backend_id=self.request_data['issue']['key'],
            status=fields['status']['name'],
            link=self.request_data['issue']['self'],
            summary=fields['summary'],
            priority=fields['priority']['name'],
            description=fields['description'],
            type=fields['issuetype']['name'],
            assignee=assignee,
            reporter=reporter,
            caller=reporter.user,
            first_response_sla=datetime.fromtimestamp(first_response_sla),
        )

        response = self.client.post(self.url, self.request_data)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(mail.outbox), 1)
        new_comment_added_subject = render_to_string(
            'support/notification_comment_added_subject.txt').strip()
        self.assertEqual(mail.outbox[0].subject, new_comment_added_subject)
Esempio n. 11
0
 def test_get_logger_scope_if_issue_resource_is_order_item(self):
     order_item = marketplace_factories.OrderItemFactory()
     issue = support_factories.IssueFactory()
     issue.resource = order_item
     issue.save()
     logger = IssueEventLogger
     scope = logger.get_scopes({'issue': issue})
     self.assertTrue(order_item.order.project in scope)
Esempio n. 12
0
    def test_user_can_see_link_to_jira_if_he_is_staff_or_support(self, user):
        self.client.force_authenticate(getattr(self.fixture, user))
        issue = factories.IssueFactory(caller=getattr(self.fixture, user))
        url = factories.IssueFactory.get_url(issue=issue)

        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIn('link', response.data)
Esempio n. 13
0
 def test_of_author_when_create_comment_from_jira(self):
     issue = factories.IssueFactory()
     backend_comment_raw = json.loads(load_resource('jira_comment_raw.json'))
     self.backend_comment = jira.resources.Comment({'server': 'example.com'}, None, backend_comment_raw)
     self.mocked_jira.comment.return_value = self.backend_comment
     self.backend.create_comment_from_jira(issue, self.backend_comment.id)
     comment = models.Comment.objects.get(issue=issue)
     self.assertEqual(comment.author.backend_id, 'user')
Esempio n. 14
0
    def test_email_notification_is_not_sent_if_feature_is_suppressed(self):
        with self.settings(SUPPRESS_NOTIFICATION_EMAILS=True):
            issue = factories.IssueFactory()

            issue.summary = 'new_summary'
            issue.save()

            self.assertEqual(len(mail.outbox), 0)
Esempio n. 15
0
    def test_1(self):
        settings.WALDUR_SUPPORT['ENABLED'] = True
        factories.IssueFactory(key='TST')
        factories.IssueFactory(key='TST-1')
        factories.IssueFactory(key='TST-11')
        factories.IssueFactory(key='TST-2')
        factories.IssueFactory(key='TST-21')
        staff = structure_factories.UserFactory(is_staff=True)

        self.client.force_authenticate(staff)

        response = self.client.get(factories.IssueFactory.get_list_url(),
                                   data={'o': 'key'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            ['TST', 'TST-1', 'TST-2', 'TST-11', 'TST-21'],
            [k['key'] for k in response.data],
        )
Esempio n. 16
0
    def test_email_notification_is_sent_if_assignee_was_changed_with_status(
            self):
        issue = factories.IssueFactory()

        issue.assignee = factories.SupportUserFactory()
        issue.status = 'new_status'
        issue.save()

        self.assertEqual(len(mail.outbox), 1)
Esempio n. 17
0
    def test_user_cannot_access_project_issue_if_he_has_no_project_level_permission(
            self, user):
        self.client.force_authenticate(getattr(self.fixture, user))
        issue = factories.IssueFactory(customer=self.fixture.customer,
                                       project=self.fixture.project)

        response = self.client.get(factories.IssueFactory.get_url(issue))

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Esempio n. 18
0
    def test_old_and_new_summary_is_rendered_in_email(self):
        issue = factories.IssueFactory(summary='old summary')

        issue.summary = 'new summary'
        issue.save()

        body = mail.outbox[0].body
        self.assertTrue('old summary' in body)
        self.assertTrue('new summary' in body)
Esempio n. 19
0
    def test_email_notification_subject_include_issue_summary(self):
        issue = factories.IssueFactory()

        new_summary = 'new_summary'
        issue.summary = new_summary
        issue.save()

        self.assertEqual(len(mail.outbox), 1)
        self.assertTrue(new_summary in mail.outbox[0].subject)
Esempio n. 20
0
    def test_subject_does_not_use_autoescape(self):
        issue = factories.IssueFactory()

        new_summary = "Request for 'Custom VPC'"
        issue.summary = new_summary
        issue.save()

        self.assertEqual(len(mail.outbox), 1)
        self.assertTrue(new_summary in mail.outbox[0].subject)
Esempio n. 21
0
    def test_if_issue_does_not_have_reporter_organisation_field_not_fill(self):
        self._mock_jira()

        issue = factories.IssueFactory(reporter=None, backend_id=None)
        factories.SupportCustomerFactory(user=issue.caller)
        factories.RequestTypeFactory(issue_type_name=issue.type)
        ServiceDeskBackend().create_issue(issue)
        kwargs = self.mock_jira(
        ).create_customer_request.return_value.update.call_args[1]
        self.assertTrue('field105' not in kwargs.keys())
Esempio n. 22
0
 def create_issue(self, **kwargs):
     resource = marketplace_factories.ResourceFactory()
     self.order_item = marketplace_factories.OrderItemFactory(
         resource=resource, offering=self.offering, **kwargs)
     self.issue = support_factories.IssueFactory(backend_id='',
                                                 key='',
                                                 resource=self.order_item)
     # Trigger handler
     self.issue.backend_id = 'TST-1'
     self.issue.save()
Esempio n. 23
0
    def test_user_can_not_comment_issue_if_support_extension_is_disabled(self):
        self.client.force_authenticate(self.fixture.staff)
        issue = factories.IssueFactory(customer=self.fixture.customer)
        payload = self._get_valid_payload()

        response = self.client.post(factories.IssueFactory.get_url(
            issue, action='comment'),
                                    data=payload)
        self.assertEqual(response.status_code,
                         status.HTTP_424_FAILED_DEPENDENCY)
Esempio n. 24
0
    def test_user_can_see_a_list_of_all_issues_where_user_is_a_caller(
            self, user):
        self.client.force_authenticate(getattr(self.fixture, user))
        issue = factories.IssueFactory(caller=getattr(self.fixture, user))
        url = factories.IssueFactory.get_list_url()

        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['key'], issue.key)
Esempio n. 25
0
    def test_user_can_create_feedback(self, user):
        url = factories.FeedbackFactory.get_list_url()
        issue = factories.IssueFactory()
        signer = signing.TimestampSigner()
        token = signer.sign(issue.uuid.hex)

        if user:
            self.client.force_authenticate(getattr(self.fixture, user))

        response = self.client.post(url, data={'evaluation': 10, 'token': token},)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Esempio n. 26
0
 def test_add_links_to_previous_issues(self):
     create_issue = support_factories.IssueFactory(
         resource=self.order_item
     )
     order_item = self.get_order_item(self.success_issue_status)
     self.assertEqual(self.mock_get_active_backend().create_issue.call_count, 1)
     self.assertEqual(self.mock_get_active_backend().create_issue_links.call_count, 1)
     update_issue = support_models.Issue.objects.get(resource_object_id=order_item.id)
     self.mock_get_active_backend().create_issue_links.assert_called_once_with(
         update_issue,
         list(support_models.Issue.objects.filter(id=create_issue.id)))
Esempio n. 27
0
    def test_email_notification_body_if_custom_template_not_exists(self):
        issue = factories.IssueFactory()
        factories.TemplateStatusNotificationFactory()

        new_summary = 'new_summary'
        body = 'Test template %s' % new_summary
        issue.summary = new_summary
        issue.save()

        self.assertEqual(len(mail.outbox), 1)
        self.assertNotEqual(body, mail.outbox[0].body)
    def test_invoice_is_not_created_for_pending_offering(self):
        issue = support_factories.IssueFactory(customer=self.fixture.customer, project=self.fixture.project)
        pending_offering = support_factories.OfferingFactory(issue=issue)

        offering = self.fixture.offering
        offering.state = offering.States.OK
        offering.save()

        self.assertEqual(models.Invoice.objects.count(), 1)
        invoice = models.Invoice.objects.first()
        self.assertTrue(invoice.offering_items.filter(offering=offering).exists())
        self.assertFalse(invoice.offering_items.filter(offering=pending_offering).exists())
Esempio n. 29
0
    def test_issue_update_callback_does_not_update_issue_link(self):
        backend_id = 'WAL-101'
        permalink = 'https://example.atlassian.net/browse/WAL-101'
        issue = factories.IssueFactory(backend_id=backend_id, link=permalink)
        self.request_data['issue']['key'] = backend_id

        # act
        response = self.client.post(self.url, self.request_data)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        issue.refresh_from_db()
        self.assertEqual(issue.link, permalink)
Esempio n. 30
0
    def test_user_without_access_to_instance_cannot_comment(self, user):
        self.client.force_authenticate(getattr(self.fixture, user))
        issue = factories.IssueFactory(customer=self.fixture.customer)
        payload = self._get_valid_payload()

        response = self.client.post(factories.IssueFactory.get_url(
            issue, action='comment'),
                                    data=payload)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertFalse(
            models.Comment.objects.filter(issue=issue,
                                          description=payload['description']))