Beispiel #1
0
 def test_project_created(self):
     project_created.send(project=self.project,
                          user=self.owner,
                          sender=type(self.project))
     feature_complete = FeatureAdoption.objects.get_by_slug(
         organization=self.organization, slug="first_project")
     assert feature_complete
    def test_first_event_received(self):
        project = self.create_project(first_event=timezone.now())
        project_created.send(project=project, user=self.user, sender=type(project))
        group = self.create_group(project=project, platform='javascript', message='javascript error message')
        first_event_received.send(project=project, group=group, sender=type(project))

        task = OrganizationOnboardingTask.objects.get(
            organization=project.organization,
            task=OnboardingTask.FIRST_EVENT,
            status=OnboardingTaskStatus.COMPLETE,
        )
        assert task is not None
        assert 'platform' in task.data
        assert task.data['platform'] == 'javascript'

        second_project = self.create_project(first_event=timezone.now())
        project_created.send(project=second_project, user=self.user, sender=type(second_project))
        second_task = OrganizationOnboardingTask.objects.get(
            organization=second_project.organization,
            task=OnboardingTask.SECOND_PLATFORM,
            status=OnboardingTaskStatus.PENDING,
        )
        assert second_task is not None

        second_group = self.create_group(project=second_project, platform='python', message='python error message')
        first_event_received.send(project=second_project, group=second_group, sender=type(second_project))
        second_task = OrganizationOnboardingTask.objects.get(
            organization=second_project.organization,
            task=OnboardingTask.SECOND_PLATFORM,
            status=OnboardingTaskStatus.COMPLETE,
        )
        assert second_task is not None
        assert 'platform' in second_task.data
        assert second_task.data['platform'] == 'python'
        assert task.data['platform'] != second_task.data['platform']
Beispiel #3
0
    def post(self, request, team):
        """
        Create a New Project
        ````````````````````

        Create a new project bound to a team.

        :pparam string organization_slug: the slug of the organization the
                                          team belongs to.
        :pparam string team_slug: the slug of the team to create a new project
                                  for.
        :param string name: the name for the new project.
        :param string slug: optionally a slug for the new project.  If it's
                            not provided a slug is generated from the name.
        :param bool default_rules: create default rules (defaults to True)
        :auth: required
        """
        serializer = ProjectSerializer(data=request.data)

        if serializer.is_valid():
            result = serializer.validated_data

            with transaction.atomic():
                try:
                    with transaction.atomic():
                        project = Project.objects.create(
                            name=result["name"],
                            slug=result.get("slug"),
                            organization=team.organization,
                            platform=result.get("platform"),
                        )
                except IntegrityError:
                    return Response(
                        {"detail": "A project with this slug already exists."},
                        status=409)
                else:
                    project.add_team(team)

                # XXX: create sample event?

                self.create_audit_entry(
                    request=request,
                    organization=team.organization,
                    target_object=project.id,
                    event=AuditLogEntryEvent.PROJECT_ADD,
                    data=project.get_audit_log_data(),
                )

                project_created.send(
                    project=project,
                    user=request.user,
                    default_rules=result.get("default_rules", True),
                    sender=self,
                )

            return Response(serialize(project, request.user), status=201)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #4
0
    def test_first_event_received(self):
        now = timezone.now()
        project = self.create_project(first_event=now)
        project_created.send(project=project,
                             user=self.user,
                             sender=type(project))
        event = self.store_event(
            data={
                "platform": "javascript",
                "message": "javascript error message"
            },
            project_id=project.id,
        )
        first_event_received.send(project=project,
                                  event=event,
                                  sender=type(project))

        task = OrganizationOnboardingTask.objects.get(
            organization=project.organization,
            task=OnboardingTask.FIRST_EVENT,
            status=OnboardingTaskStatus.COMPLETE,
        )
        assert task is not None
        assert "platform" in task.data
        assert task.data["platform"] == "javascript"

        second_project = self.create_project(first_event=now)
        project_created.send(project=second_project,
                             user=self.user,
                             sender=type(second_project))
        second_task = OrganizationOnboardingTask.objects.get(
            organization=second_project.organization,
            task=OnboardingTask.SECOND_PLATFORM,
            status=OnboardingTaskStatus.PENDING,
        )
        assert second_task is not None

        second_event = self.store_event(
            data={
                "platform": "python",
                "message": "python error message"
            },
            project_id=second_project.id,
        )
        first_event_received.send(project=second_project,
                                  event=second_event,
                                  sender=type(second_project))
        second_task = OrganizationOnboardingTask.objects.get(
            organization=second_project.organization,
            task=OnboardingTask.SECOND_PLATFORM,
            status=OnboardingTaskStatus.COMPLETE,
        )
        assert second_task is not None
        assert "platform" in second_task.data
        assert second_task.data["platform"] == "python"
        assert task.data["platform"] != second_task.data["platform"]
    def test_project_created(self):
        project = self.create_project(first_event=timezone.now())
        project_created.send(project=project, user=self.user, sender=type(project))

        task = OrganizationOnboardingTask.objects.get(
            organization=project.organization,
            task=OnboardingTask.FIRST_PROJECT,
            status=OnboardingTaskStatus.COMPLETE,
        )
        assert task is not None
Beispiel #6
0
    def test_project_created(self):
        now = timezone.now()
        project = self.create_project(first_event=now)
        project_created.send(project=project, user=self.user, sender=type(project))

        task = OrganizationOnboardingTask.objects.get(
            organization=project.organization,
            task=OnboardingTask.FIRST_PROJECT,
            status=OnboardingTaskStatus.COMPLETE,
        )
        assert task is not None
    def post(self, request, team):
        """
        Create a New Project
        ````````````````````

        Create a new project bound to a team.

        :pparam string organization_slug: the slug of the organization the
                                          team belongs to.
        :pparam string team_slug: the slug of the team to create a new project
                                  for.
        :param string name: the name for the new project.
        :param string slug: optionally a slug for the new project.  If it's
                            not provided a slug is generated from the name.
        :auth: required
        """
        serializer = ProjectSerializer(data=request.DATA)

        if serializer.is_valid():
            result = serializer.object

            try:
                with transaction.atomic():
                    project = Project.objects.create(
                        name=result['name'],
                        slug=result.get('slug'),
                        organization=team.organization,
                        team=team,
                        platform=result.get('platform')
                    )
            except IntegrityError:
                return Response(
                    {
                        'detail': 'A project with this slug already exists.'
                    },
                    status=409,
                )
            else:
                project.add_team(team)

            # XXX: create sample event?

            self.create_audit_entry(
                request=request,
                organization=team.organization,
                target_object=project.id,
                event=AuditLogEntryEvent.PROJECT_ADD,
                data=project.get_audit_log_data(),
            )

            project_created.send(project=project, user=request.user, sender=self)

            return Response(serialize(project, request.user), status=201)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    def test_onboarding_tasks(self):
        response = self.get_success_response(self.organization.slug)
        assert response.data["onboardingTasks"] == []
        assert response.data["id"] == str(self.organization.id)

        project = self.create_project(organization=self.organization)
        project_created.send(project=project, user=self.user, sender=type(project))

        response = self.get_success_response(self.organization.slug)
        assert len(response.data["onboardingTasks"]) == 1
        assert response.data["onboardingTasks"][0]["task"] == "create_project"
Beispiel #9
0
    def test_project_created(self):
        # Drop microsecond value for MySQL
        now = timezone.now().replace(microsecond=0)
        project = self.create_project(first_event=now)
        project_created.send(project=project, user=self.user, sender=type(project))

        task = OrganizationOnboardingTask.objects.get(
            organization=project.organization,
            task=OnboardingTask.FIRST_PROJECT,
            status=OnboardingTaskStatus.COMPLETE,
        )
        assert task is not None
    def post(self, request, team):
        """
        Create a New Project
        ````````````````````

        Create a new project bound to a team.

        :pparam string organization_slug: the slug of the organization the
                                          team belongs to.
        :pparam string team_slug: the slug of the team to create a new project
                                  for.
        :param string name: the name for the new project.
        :param string slug: optionally a slug for the new project.  If it's
                            not provided a slug is generated from the name.
        :auth: required
        """
        serializer = ProjectSerializer(data=request.DATA)

        if serializer.is_valid():
            result = serializer.object

            try:
                with transaction.atomic():
                    project = Project.objects.create(
                        name=result['name'],
                        slug=result.get('slug'),
                        organization=team.organization,
                        team=team,
                        platform=result.get('platform'))
            except IntegrityError:
                return Response(
                    {'detail': 'A project with this slug already exists.'},
                    status=409,
                )

            # XXX: create sample event?

            self.create_audit_entry(
                request=request,
                organization=team.organization,
                target_object=project.id,
                event=AuditLogEntryEvent.PROJECT_ADD,
                data=project.get_audit_log_data(),
            )

            project_created.send(project=project,
                                 user=request.user,
                                 sender=self)

            create_sample_event(project, platform='javascript')

            return Response(serialize(project, request.user), status=201)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #11
0
def create_default_project(id, name, slug, verbosity=2, **kwargs):
    if Project.objects.filter(id=id).exists():
        return

    try:
        user = User.objects.filter(is_superuser=True)[0]
    except IndexError:
        user = None

    org, _ = Organization.objects.get_or_create(slug="sentry",
                                                defaults={"name": "Sentry"})

    if user:
        OrganizationMember.objects.get_or_create(user=user,
                                                 organization=org,
                                                 role="owner")

    team, _ = Team.objects.get_or_create(organization=org,
                                         slug="sentry",
                                         defaults={"name": "Sentry"})

    with transaction.atomic():
        project = Project.objects.create(id=id,
                                         public=False,
                                         name=name,
                                         slug=slug,
                                         organization=team.organization,
                                         **kwargs)
        project.add_team(team)

        project_created.send(
            project=project,
            user=user or AnonymousUser(),
            default_rules=True,
            sender=create_default_project,
        )

        # HACK: manually update the ID after insert due to Postgres
        # sequence issues. Seriously, f**k everything about this.
        connection = connections[project._state.db]
        cursor = connection.cursor()
        cursor.execute(PROJECT_SEQUENCE_FIX)

    project.update_option("sentry:origins", ["*"])

    if verbosity > 0:
        echo(
            f"Created internal Sentry project (slug={project.slug}, id={project.id})"
        )

    return project
Beispiel #12
0
    def test_onboarding_complete(self):
        now = timezone.now()
        user = self.create_user(email="*****@*****.**")
        project = self.create_project(first_event=now)
        second_project = self.create_project(first_event=now)
        second_event = self.create_event(project=second_project,
                                         platform="python",
                                         message="python error message")
        event = self.create_full_event(project=project)
        member = self.create_member(organization=self.organization,
                                    teams=[self.team],
                                    user=user)

        event_processed.send(project=project,
                             event=event,
                             sender=type(project))
        project_created.send(project=project, user=user, sender=type(project))
        project_created.send(project=second_project,
                             user=user,
                             sender=type(second_project))

        first_event_received.send(project=project,
                                  event=event,
                                  sender=type(project))
        first_event_received.send(project=second_project,
                                  event=second_event,
                                  sender=type(second_project))
        member_joined.send(member=member,
                           organization=self.organization,
                           sender=type(member))
        plugin_enabled.send(
            plugin=IssueTrackingPlugin(),
            project=project,
            user=user,
            sender=type(IssueTrackingPlugin),
        )
        issue_tracker_used.send(
            plugin=IssueTrackingPlugin(),
            project=project,
            user=user,
            sender=type(IssueTrackingPlugin),
        )
        plugin_enabled.send(plugin=NotificationPlugin(),
                            project=project,
                            user=user,
                            sender=type(NotificationPlugin))

        assert (OrganizationOption.objects.filter(
            organization=self.organization,
            key="onboarding:complete").count() == 1)
Beispiel #13
0
    def test_first_event_received(self):
        # Drop microsecond value for MySQL
        now = timezone.now().replace(microsecond=0)
        project = self.create_project(first_event=now)
        project_created.send(project=project,
                             user=self.user,
                             sender=type(project))
        group = self.create_group(project=project,
                                  platform='javascript',
                                  message='javascript error message')
        first_event_received.send(project=project,
                                  group=group,
                                  sender=type(project))

        task = OrganizationOnboardingTask.objects.get(
            organization=project.organization,
            task=OnboardingTask.FIRST_EVENT,
            status=OnboardingTaskStatus.COMPLETE,
        )
        assert task is not None
        assert 'platform' in task.data
        assert task.data['platform'] == 'javascript'

        second_project = self.create_project(first_event=now)
        project_created.send(project=second_project,
                             user=self.user,
                             sender=type(second_project))
        second_task = OrganizationOnboardingTask.objects.get(
            organization=second_project.organization,
            task=OnboardingTask.SECOND_PLATFORM,
            status=OnboardingTaskStatus.PENDING,
        )
        assert second_task is not None

        second_group = self.create_group(project=second_project,
                                         platform='python',
                                         message='python error message')
        first_event_received.send(project=second_project,
                                  group=second_group,
                                  sender=type(second_project))
        second_task = OrganizationOnboardingTask.objects.get(
            organization=second_project.organization,
            task=OnboardingTask.SECOND_PLATFORM,
            status=OnboardingTaskStatus.COMPLETE,
        )
        assert second_task is not None
        assert 'platform' in second_task.data
        assert second_task.data['platform'] == 'python'
        assert task.data['platform'] != second_task.data['platform']
    def test_onboarding_tasks(self):
        org = self.create_organization(owner=self.user)
        self.login_as(user=self.user)
        url = reverse("sentry-api-0-organization-details", kwargs={"organization_slug": org.slug})
        response = self.client.get(url, format="json")
        assert response.data["onboardingTasks"] == []
        assert response.status_code == 200, response.content
        assert response.data["id"] == six.text_type(org.id)

        project = self.create_project(organization=org)
        project_created.send(project=project, user=self.user, sender=type(project))

        url = reverse("sentry-api-0-organization-details", kwargs={"organization_slug": org.slug})
        response = self.client.get(url, format="json")
        assert len(response.data["onboardingTasks"]) == 1
        assert response.data["onboardingTasks"][0]["task"] == "create_project"
Beispiel #15
0
    def test_onboarding_complete(self):
        # Drop microsecond value for MySQL
        now = timezone.now().replace(microsecond=0)
        user = self.create_user(email='*****@*****.**')
        project = self.create_project(first_event=now)
        second_project = self.create_project(first_event=now)
        second_group = self.create_group(project=second_project,
                                         platform='python',
                                         message='python error message')
        event = self.create_full_event()
        member = self.create_member(organization=self.organization,
                                    teams=[self.team],
                                    user=user)

        event_processed.send(project=project,
                             group=self.group,
                             event=event,
                             sender=type(project))
        project_created.send(project=project, user=user, sender=type(project))
        project_created.send(project=second_project,
                             user=user,
                             sender=type(second_project))

        first_event_received.send(project=project,
                                  group=self.group,
                                  sender=type(project))
        first_event_received.send(project=second_project,
                                  group=second_group,
                                  sender=type(second_project))
        member_joined.send(member=member, sender=type(member))
        plugin_enabled.send(plugin=IssueTrackingPlugin(),
                            project=project,
                            user=user,
                            sender=type(IssueTrackingPlugin))
        issue_tracker_used.send(plugin=IssueTrackingPlugin(),
                                project=project,
                                user=user,
                                sender=type(IssueTrackingPlugin))
        plugin_enabled.send(plugin=NotificationPlugin(),
                            project=project,
                            user=user,
                            sender=type(NotificationPlugin))

        assert OrganizationOption.objects.filter(
            organization=self.organization,
            key="onboarding:complete").count() == 1
Beispiel #16
0
    def save(self, actor, team, ip_address):
        project = super(AddProjectForm, self).save(commit=False)
        project.team = team
        project.organization = team.organization
        project.save()

        AuditLogEntry.objects.create(
            organization=project.organization,
            actor=actor,
            ip_address=ip_address,
            target_object=project.id,
            event=AuditLogEntryEvent.PROJECT_ADD,
            data=project.get_audit_log_data(),
        )

        project_created.send(project=project, user=actor, sender=self)

        return project
Beispiel #17
0
    def create_project(organization=None, teams=None, fire_project_created=False, **kwargs):
        if not kwargs.get("name"):
            kwargs["name"] = petname.Generate(2, " ", letters=10).title()
        if not kwargs.get("slug"):
            kwargs["slug"] = slugify(six.text_type(kwargs["name"]))
        if not organization and teams:
            organization = teams[0].organization

        with transaction.atomic():
            project = Project.objects.create(organization=organization, **kwargs)
            if teams:
                for team in teams:
                    project.add_team(team)
            if fire_project_created:
                project_created.send(
                    project=project, user=AnonymousUser(), default_rules=True, sender=Factories
                )
        return project
Beispiel #18
0
    def save(self, actor, team, ip_address):
        project = super(AddProjectForm, self).save(commit=False)
        project.team = team
        project.organization = team.organization
        project.save()

        AuditLogEntry.objects.create(
            organization=project.organization,
            actor=actor,
            ip_address=ip_address,
            target_object=project.id,
            event=AuditLogEntryEvent.PROJECT_ADD,
            data=project.get_audit_log_data(),
        )

        project_created.send(project=project, user=actor, sender=self)

        return project
Beispiel #19
0
    def test_onboarding_complete(self):
        user = self.create_user(email='*****@*****.**')
        project = self.create_project(first_event=timezone.now())
        second_project = self.create_project(first_event=timezone.now())
        second_group = self.create_group(project=second_project, platform='python', message='python error message')
        event = self.create_full_event()
        member = self.create_member(organization=self.organization, teams=[self.team], user=user)

        event_processed.send(project=project, group=self.group, event=event, sender=type(project))
        project_created.send(project=project, user=user, sender=type(project))
        project_created.send(project=second_project, user=user, sender=type(second_project))

        first_event_received.send(project=project, group=self.group, sender=type(project))
        first_event_received.send(project=second_project, group=second_group, sender=type(second_project))
        member_joined.send(member=member, sender=type(member))
        plugin_enabled.send(plugin=IssueTrackingPlugin(), project=project, user=user, sender=type(IssueTrackingPlugin))
        issue_tracker_used.send(plugin=IssueTrackingPlugin(), project=project, user=user, sender=type(IssueTrackingPlugin))
        plugin_enabled.send(plugin=NotificationPlugin(), project=project, user=user, sender=type(NotificationPlugin))

        assert OrganizationOption.objects.filter(organization=self.organization, key="onboarding:complete").count() == 1
    def test_simple(self):
        org = self.create_organization(owner=self.user)
        self.login_as(user=self.user)
        url = reverse('sentry-api-0-organization-details', kwargs={
            'organization_slug': org.slug,
        })
        response = self.client.get(url, format='json')
        assert response.data['onboardingTasks'] == []
        assert response.status_code == 200, response.content
        assert response.data['id'] == six.text_type(org.id)

        project = self.create_project(organization=org)
        project_created.send(project=project, user=self.user, sender=type(project))

        url = reverse('sentry-api-0-organization-details', kwargs={
            'organization_slug': org.slug,
        })
        response = self.client.get(url, format='json')
        assert len(response.data['onboardingTasks']) == 1
        assert response.data['onboardingTasks'][0]['task'] == 1
    def test_simple(self):
        org = self.create_organization(owner=self.user)
        self.login_as(user=self.user)
        url = reverse('sentry-api-0-organization-details', kwargs={
            'organization_slug': org.slug,
        })
        response = self.client.get(url, format='json')
        assert response.data['onboardingTasks'] == []
        assert response.status_code == 200, response.content
        assert response.data['id'] == six.text_type(org.id)

        project = self.create_project(organization=org)
        project_created.send(project=project, user=self.user, sender=type(project))

        url = reverse('sentry-api-0-organization-details', kwargs={
            'organization_slug': org.slug,
        })
        response = self.client.get(url, format='json')
        assert len(response.data['onboardingTasks']) == 1
        assert response.data['onboardingTasks'][0]['task'] == 1
Beispiel #22
0
 def test_project_created(self):
     project_created.send(project=self.project, user=self.owner, sender=type(self.project))
     feature_complete = FeatureAdoption.objects.get_by_slug(
         organization=self.organization, slug="first_project"
     )
     assert feature_complete
Beispiel #23
0
    def test_onboarding_complete(self):
        now = timezone.now()
        user = self.create_user(email="*****@*****.**")
        project = self.create_project(first_event=now)
        second_project = self.create_project(first_event=now)
        second_event = self.store_event(
            data={
                "platform": "python",
                "message": "python error message"
            },
            project_id=second_project.id,
        )
        event = self.store_event(
            data={
                "event_id": "a" * 32,
                "platform": "javascript",
                "timestamp": iso_format(before_now(minutes=1)),
                "tags": {
                    "sentry:release":
                    "e1b5d1900526feaf20fe2bc9cad83d392136030a",
                    "sentry:user": "******",
                },
                "user": {
                    "ip_address": "0.0.0.0",
                    "id": "41656",
                    "email": "*****@*****.**"
                },
                "exception": {
                    "values": [{
                        "stacktrace": {
                            "frames": [{
                                "data": {
                                    "sourcemap":
                                    "https://media.sentry.io/_static/29e365f8b0d923bc123e8afa38d890c3/sentry/dist/vendor.js.map"
                                }
                            }]
                        },
                        "type": "TypeError",
                    }]
                },
            },
            project_id=project.id,
        )

        event_data = load_data("transaction")
        min_ago = iso_format(before_now(minutes=1))
        event_data.update({"start_timestamp": min_ago, "timestamp": min_ago})

        transaction = self.store_event(data=event_data, project_id=project.id)

        first_event_received.send(project=project,
                                  event=transaction,
                                  sender=type(project))
        first_transaction_received.send(project=project,
                                        event=transaction,
                                        sender=type(project))

        member = self.create_member(organization=self.organization,
                                    teams=[self.team],
                                    user=user)

        event_processed.send(project=project,
                             event=event,
                             sender=type(project))
        project_created.send(project=project, user=user, sender=type(project))
        project_created.send(project=second_project,
                             user=user,
                             sender=type(second_project))

        first_event_received.send(project=project,
                                  event=event,
                                  sender=type(project))
        first_event_received.send(project=second_project,
                                  event=second_event,
                                  sender=type(second_project))
        member_joined.send(member=member,
                           organization=self.organization,
                           sender=type(member))
        plugin_enabled.send(
            plugin=IssueTrackingPlugin(),
            project=project,
            user=user,
            sender=type(IssueTrackingPlugin),
        )
        issue_tracker_used.send(
            plugin=IssueTrackingPlugin(),
            project=project,
            user=user,
            sender=type(IssueTrackingPlugin),
        )
        alert_rule_created.send(
            rule=Rule(id=1),
            project=self.project,
            user=self.user,
            rule_type="issue",
            sender=type(Rule),
            is_api_token=False,
        )

        assert (OrganizationOption.objects.filter(
            organization=self.organization,
            key="onboarding:complete").count() == 1)