Exemple #1
0
    def test_creating_pref_bugzilla_ticket_returns_ticket_id(self):
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_DRAFT, name="An Experiment")

        response_data = create_experiment_bug(experiment)

        self.assertEqual(response_data, self.bugzilla_id)

        self.mock_bugzilla_requests_post.assert_called_with(
            settings.BUGZILLA_CREATE_URL,
            {
                "product":
                "Shield",
                "component":
                "Shield Experiment",
                "version":
                "unspecified",
                "summary":
                "[Shield] {experiment}".format(experiment=experiment),
                "description":
                experiment.BUGZILLA_OVERVIEW_TEMPLATE.format(
                    experiment=experiment),
                "assigned_to":
                experiment.owner.email,
                "cc":
                settings.BUGZILLA_CC_LIST,
            },
        )
Exemple #2
0
def create_experiment_bug_task(user_id, experiment_id):
    metrics.incr("create_experiment_bug.started")

    experiment = Experiment.objects.get(id=experiment_id)

    logger.info("Creating Bugzilla ticket")
    try:
        bugzilla_id = bugzilla.create_experiment_bug(experiment)
        logger.info("Bugzilla ticket created")
        experiment.bugzilla_id = bugzilla_id
        experiment.save()

        Notification.objects.create(
            user_id=user_id,
            message=NOTIFICATION_MESSAGE_CREATE_BUG.format(
                bug_url=experiment.bugzilla_url),
        )
        metrics.incr("create_experiment_bug.completed")
        logger.info("Bugzilla ticket notification sent")
    except bugzilla.BugzillaError as e:
        metrics.incr("create_experiment_bug.failed")
        logger.info("Bugzilla ticket creation failed")

        Notification.objects.create(
            user_id=user_id, message=NOTIFICATION_MESSAGE_CREATE_BUG_FAILED)
        logger.info("Bugzilla ticket notification sent")
        raise e
    def test_creating_pref_bugzilla_ticket_returns_ticket_id(self):
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_DRAFT,
            name="An Experiment",
            firefox_min_version="56.0",
            firefox_max_version="57.0",
        )

        response_data = create_experiment_bug(experiment)

        self.assertEqual(response_data, self.bugzilla_id)

        self.mock_bugzilla_requests_post.assert_called_with(
            settings.BUGZILLA_CREATE_URL,
            {
                "product": "Shield",
                "component": "Shield Study",
                "version": "unspecified",
                "summary": "[Experiment]: {experiment}".format(
                    experiment=experiment
                ),
                "description": experiment.BUGZILLA_OVERVIEW_TEMPLATE.format(
                    experiment=experiment
                ),
                "cc": settings.BUGZILLA_CC_LIST,
                "type": "task",
                "priority": "P3",
                "assigned_to": experiment.owner.email,
                "see_also": [12345],
                "blocks": [12345],
                "url": experiment.experiment_url,
            },
        )
Exemple #4
0
    def save(self, *args, **kwargs):
        experiment = super().save(*args, **kwargs)

        if (self.old_status == Experiment.STATUS_DRAFT
                and self.new_status == Experiment.STATUS_REVIEW
                and not experiment.bugzilla_id):
            needs_attention = len(self.cleaned_data.get("attention", "")) > 0
            send_review_email(experiment, needs_attention)
            messages.add_message(
                self.request,
                messages.INFO,
                "An email was sent to {email} about this experiment".format(
                    email=settings.EMAIL_REVIEW),
            )

            bugzilla_id = bugzilla.create_experiment_bug(experiment)
            if bugzilla_id is not None:
                experiment.bugzilla_id = bugzilla_id
                experiment.save()
                messages.add_message(
                    self.request,
                    messages.INFO,
                    mark_safe(
                        ('A <a target="_blank" href="{bug_url}">Bugzilla '
                         "Ticket</a> was created for this experiment").format(
                             bug_url=experiment.bugzilla_url)),
                )

        return experiment
Exemple #5
0
def create_experiment_bug_task(user_id, experiment_id):
    experiment = Experiment.objects.get(id=experiment_id)

    logger.info("Creating Bugzilla ticket")
    bugzilla_id = bugzilla.create_experiment_bug(experiment)

    if bugzilla_id is not None:
        logger.info("Bugzilla ticket created")
        experiment.bugzilla_id = bugzilla_id
        experiment.save()

        Notification.objects.create(
            user_id=user_id,
            message=NOTIFICATION_MESSAGE_CREATE_BUG.format(
                bug_url=experiment.bugzilla_url),
        )
        logger.info("Bugzilla ticket notification sent")
    def test_create_bugzilla_ticket_creation_with_blocks_bad_val(self):
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_DRAFT, name="An Experiment")

        self.mock_bugzilla_requests_get.side_effect = [
            self.buildMockSuccessUserResponse(),
            self.buildMockSuccessBugResponse(),
            self.buildMockFailureResponse(),
        ]

        response_data = create_experiment_bug(experiment)

        self.assertEqual(response_data, self.bugzilla_id)

        expected_call_data = {
            "product":
            "Shield",
            "component":
            "Shield Study",
            "version":
            "unspecified",
            "summary":
            "[Experiment]: {experiment}".format(experiment=experiment),
            "description":
            experiment.BUGZILLA_OVERVIEW_TEMPLATE.format(
                experiment=experiment),
            "assigned_to":
            experiment.owner.email,
            "cc":
            settings.BUGZILLA_CC_LIST,
            "type":
            "task",
            "priority":
            "P3",
            "url":
            experiment.experiment_url,
            "see_also": [12345],
            "blocks":
            None,
        }

        self.mock_bugzilla_requests_post.assert_called_with(
            settings.BUGZILLA_CREATE_URL, expected_call_data)
Exemple #7
0
    def test_create_bugzilla_ticket_retries_with_no_assignee(self):
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_DRAFT, name="An Experiment")

        self.setUpMockBugzillaInvalidUser()

        response_data = create_experiment_bug(experiment)

        self.assertEqual(response_data, self.bugzilla_id)
        self.assertEqual(self.mock_bugzilla_requests_post.call_count, 2)

        expected_call_data = {
            "product":
            "Shield",
            "component":
            "Shield Experiment",
            "version":
            "unspecified",
            "summary":
            "[Shield] {experiment}".format(experiment=experiment),
            "description":
            experiment.BUGZILLA_OVERVIEW_TEMPLATE.format(
                experiment=experiment),
            "assigned_to":
            experiment.owner.email,
            "cc":
            settings.BUGZILLA_CC_LIST,
        }

        self.mock_bugzilla_requests_post.assert_any_call(
            settings.BUGZILLA_CREATE_URL, expected_call_data)

        del expected_call_data["assigned_to"]

        self.mock_bugzilla_requests_post.assert_any_call(
            settings.BUGZILLA_CREATE_URL, expected_call_data)