Beispiel #1
0
    def test_that_if_we_start_different_flavours_of_the_same_card_we_get_seperate_project_instances_CONTINUE_REPO(
            self, add_collaborator, Api):
        assignee = SocialProfileFactory().user
        reviewer = SocialProfileFactory().user
        card_js = self.create_continue_repo_card(
            content_flavours=[TYPESCRIPT, JAVASCRIPT],
            card_flavours=[JAVASCRIPT],
            assignee=assignee,
            reviewer=reviewer,
        )

        content_item = card_js.content_item
        pre_content_item = content_item.continue_from_repo

        card_ts = self.create_continue_repo_card(
            content_flavours=[TYPESCRIPT, JAVASCRIPT],
            card_flavours=[TYPESCRIPT],
            assignee=assignee,
            reviewer=reviewer,
            pre_content_item=pre_content_item,
            content_item=content_item,
        )

        card_js.start_project()
        card_ts.start_project()

        projects = RecruitProject.objects.filter(recruit_users__in=[assignee])
        self.assertEqual(projects.count(), 4)

        self.assertTrue(card_js.recruit_project.flavours_match([JAVASCRIPT]))
        self.assertTrue(card_ts.recruit_project.flavours_match([TYPESCRIPT]))
        self.assertEqual(card_ts.recruit_project.content_item,
                         card_js.recruit_project.content_item)
Beispiel #2
0
    def test_that_project_submission_type_REPOSITORY_creates_a_repo_with_flavourful_name(
        self, create_repo_and_assign_contributer, get_repo, add_collaborator, Api
    ):
        content_item = factories.ProjectContentItemFactory(
            flavours=[TYPESCRIPT, JAVASCRIPT]
        )

        card_ts = factories.AgileCardFactory(
            status=AgileCard.READY,
            recruit_project=None,
            content_item=content_item,
            flavours=[TYPESCRIPT],
        )
        card_ts.assignees.add(SocialProfileFactory().user)

        card_js = factories.AgileCardFactory(
            status=AgileCard.READY,
            recruit_project=None,
            content_item=content_item,
            flavours=[JAVASCRIPT],
        )
        card_js.assignees.add(SocialProfileFactory().user)

        self.assertIsNone(card_js.recruit_project)

        def get_repo_mock(
            github_auth_login, repo_full_name, api=None, response404=None
        ):
            return {
                "full_name": f"me/{repo_full_name}",
                "owner": {"login": "******"},
                "ssh_url": f"https://{repo_full_name}.git",
                "private": True,
                "created_at": datetime.now().strftime(GITHUB_DATETIME_FORMAT),
                "archived": False,
            }

        get_repo.side_effect = get_repo_mock

        card_ts.start_project()
        card_js.start_project()

        self.assertNotEqual(card_ts.recruit_project, card_js.recruit_project)
        self.assertNotEqual(
            card_ts.recruit_project.repository, card_js.recruit_project.repository
        )

        ts_project_flavours = [o.name for o in card_ts.recruit_project.flavours.all()]
        self.assertEqual(ts_project_flavours, [TYPESCRIPT])

        js_project_flavours = [o.name for o in card_js.recruit_project.flavours.all()]
        self.assertEqual(js_project_flavours, [JAVASCRIPT])

        self.assertIn(JAVASCRIPT, card_js.recruit_project.repository.ssh_url)
        self.assertIn(JAVASCRIPT, card_js.recruit_project.repository.full_name)
        self.assertIn(TYPESCRIPT, card_ts.recruit_project.repository.ssh_url)
        self.assertIn(TYPESCRIPT, card_ts.recruit_project.repository.full_name)
Beispiel #3
0
    def test_that_if_project_progress_instance_exists_then_collaborators_added_to_repo_REPOSITORY(
            self, create_repo, add_collaborator, get_repo):
        def get_repo_mock(github_auth_login,
                          repo_full_name,
                          api=None,
                          response404=None):
            return {
                "full_name": f"me/{repo_full_name}",
                "owner": {
                    "login": "******"
                },
                "ssh_url": f"https://{repo_full_name}.git",
                "private": True,
                "created_at": datetime.now().strftime(GITHUB_DATETIME_FORMAT),
                "archived": False,
            }

        get_repo.side_effect = get_repo_mock

        assignee = SocialProfileFactory().user
        reviewer = SocialProfileFactory().user

        card = factories.AgileCardFactory(
            content_item=factories.ContentItemFactory(
                content_type=ContentItem.PROJECT,
                project_submission_type=ContentItem.REPOSITORY,
            ),
            status=AgileCard.READY,
            recruit_project=None,
        )
        card.assignees.set([assignee])
        card.reviewers.set([reviewer])

        card.start_project()

        card.refresh_from_db()
        project = card.recruit_project

        self.assert_users_same(card, project)

        self.assertTrue(create_repo.called)
        github_collaborator_names = [
            t[0][-1] for t in add_collaborator.call_args_list
        ]

        self.assertTrue(
            assignee.social_profile.github_name in github_collaborator_names)
        self.assertTrue(
            reviewer.social_profile.github_name in github_collaborator_names)
Beispiel #4
0
    def test_cards_in_the_review_column_waiting_for_a_review(self):

        # Two cards in the IN_REVIEW column
        content_item_3 = ContentItemFactory(
            content_type=ContentItem.TOPIC,
            project_submission_type=ContentItem.REPOSITORY,
        )

        card_3 = AgileCardFactory(
            content_item=content_item_3,
            status=AgileCard.IN_REVIEW,
            recruit_project=None,
        )

        card_4 = AgileCardFactory(
            content_item=content_item_3,
            status=AgileCard.IN_REVIEW,
            recruit_project=None,
        )

        assigned_person = SocialProfileFactory().user
        card_3.assignees.set([assigned_person])
        card_4.assignees.set([assigned_person])

        # We should get two cards in the review column waiting for a review
        self.assertEqual(
            self.stats_serializer.get_cards_in_review_column_as_assignee(
                user=assigned_person), 2)
    def test_adding_a_pr_review(self, has_permission):
        has_permission.return_value = True

        # self.assertEqual(PullRequest.objects.all().count(), 0)
        self.assertEqual(PullRequestReview.objects.all().count(), 0)

        body, headers = get_body_and_headers("pull_request_review_submitted")
        review_data = body["review"]
        social_profile = SocialProfileFactory(
            github_name=review_data["user"]["login"])

        url = reverse(views.github_webhook)

        repo = RepositoryFactory(full_name=body["repository"]["full_name"])

        self.client.post(url, format="json", data=body, extra=headers)

        # self.assertEqual(PullRequest.objects.all().count(), 1)
        self.assertEqual(PullRequestReview.objects.all().count(), 1)

        # pr = PullRequest.objects.first()
        pr_review = PullRequestReview.objects.first()

        self.assertEqual(LogEntry.objects.count(), 1)
        entry = LogEntry.objects.first()

        self.assertEqual(entry.actor_user, social_profile.user)
        self.assertEqual(entry.effected_user, repo.user)
        self.assertEqual(entry.object_1, pr_review)
        self.assertEqual(entry.object_2, repo)
        self.assertEqual(entry.event_type.name, creators.PR_REVIEWED)
Beispiel #6
0
    def test_one_card_in_complete_column(self):

        content_item_2 = ContentItemFactory(
            content_type=ContentItem.TOPIC,
            project_submission_type=ContentItem.REPOSITORY,
        )
        card_2 = AgileCardFactory(
            content_item=content_item_2,
            status=AgileCard.COMPLETE,
        )
        assigned_person = SocialProfileFactory().user
        card_2.assignees.set([assigned_person])

        # We should have at least one card in the completed column and since it went there within the last seven days
        # the function 'get_cards_completed_last_7_days_as_assignee' should also return at least one card
        self.assertEqual(
            UserDetailedStatsSerializer.
            get_cards_assigned_with_status_complete(
                UserDetailedStatsSerializer, user=assigned_person),
            1,
        )
        self.assertEqual(
            UserDetailedStatsSerializer.
            get_cards_completed_last_7_days_as_assignee(
                UserDetailedStatsSerializer, user=assigned_person),
            1,
        )
Beispiel #7
0
    def test_start_project_works_even_if_project_instance_exists(self, *_):
        card = factories.AgileCardFactory(
            status=AgileCard.READY,
            recruit_project=None,
            content_item=factories.ProjectContentItemFactory(),
            assignees=[SocialProfileFactory().user],
        )
        self.assertIsNone(card.recruit_project)

        card.set_due_time(timezone.now())
        self.assertEqual(card.status, AgileCard.READY)

        self.assertIsNotNone(card.recruit_project)
        card.start_project()

        project = card.recruit_project

        card.refresh_from_db()
        project.refresh_from_db()

        self.assert_users_same(card=card, project=project)
        self.assertEqual(project.content_item, card.content_item)
        self.assertTrue(project.setup_repository.called)
        self.assertEqual(card.status, AgileCard.IN_PROGRESS)
        self.assertIsNotNone(project.start_time)
Beispiel #8
0
    def test_that_if_project_progress_instance_exists_then_collaborators_added_to_repo_CONTINUE_REPO(
            self, add_collaborator, Api):

        assignee = SocialProfileFactory().user
        reviewer = SocialProfileFactory().user
        card = self.create_continue_repo_card([], [], assignee, reviewer)

        card.start_project()

        github_collaborator_names = [
            t[0][-1] for t in add_collaborator.call_args_list
        ]

        self.assertTrue(
            assignee.social_profile.github_name in github_collaborator_names)
        self.assertTrue(
            reviewer.social_profile.github_name in github_collaborator_names)
Beispiel #9
0
    def test_that_if_we_start_different_flavours_of_the_same_card_we_get_seperate_project_instances_REPOSITORY(
            self, create_repo_and_assign_contributer, get_repo,
            add_collaborator, Api):
        def get_repo_mock(github_auth_login,
                          repo_full_name,
                          api=None,
                          response404=None):
            return {
                "full_name": f"me/{repo_full_name}",
                "owner": {
                    "login": "******"
                },
                "ssh_url": f"https://{repo_full_name}.git",
                "private": True,
                "created_at": datetime.now().strftime(GITHUB_DATETIME_FORMAT),
                "archived": False,
            }

        get_repo.side_effect = get_repo_mock
        content_item = factories.ContentItemFactory(
            content_type=ContentItem.PROJECT,
            project_submission_type=ContentItem.REPOSITORY,
            available_flavours=[TYPESCRIPT, JAVASCRIPT],
        )

        card_js = factories.AgileCardFactory(
            content_item=content_item,
            content_flavours=[JAVASCRIPT],
            status=AgileCard.READY,
            recruit_project=None,
        )
        card_ts = factories.AgileCardFactory(
            content_item=content_item,
            content_flavours=[TYPESCRIPT],
            status=AgileCard.READY,
            recruit_project=None,
        )
        assignee = SocialProfileFactory().user
        card_js.assignees.set([assignee])
        card_ts.assignees.set([assignee])

        card_js.start_project()
        card_ts.start_project()

        projects = RecruitProject.objects.filter(recruit_users__in=[assignee])
        self.assertEqual(projects.count(), 2)

        self.assertTrue(card_js.recruit_project.flavours_match([JAVASCRIPT]))
        self.assertTrue(card_ts.recruit_project.flavours_match([TYPESCRIPT]))
        self.assertEqual(card_ts.recruit_project.content_item,
                         card_js.recruit_project.content_item)
        self.assertIsNotNone(card_js.recruit_project.repository)
    def test_that_pr_review_event_doesnt_duplicate_pr_review_object(
            self, has_permission):
        has_permission.return_value = True

        self.assertEqual(PullRequest.objects.all().count(), 0)
        self.assertEqual(PullRequestReview.objects.all().count(), 0)

        body, headers = get_body_and_headers("pull_request_review_submitted")
        review_data = body["review"]
        social_profile = SocialProfileFactory(
            github_name=review_data["user"]["login"])

        url = reverse(views.github_webhook)

        repo = RepositoryFactory(full_name=body["repository"]["full_name"])

        self.client.post(url, format="json", data=body, extra=headers)

        self.assertEqual(PullRequest.objects.all().count(), 1)
        self.assertEqual(PullRequestReview.objects.all().count(), 1)

        # mess up all the fields except html_url
        review = PullRequestReview.objects.first()
        review.author_github_name = ""
        review.submitted_at = timezone.now()
        review.body = ""
        review.commit_id = ""
        review.state = ""
        review.user = None
        review.save()

        self.client.post(url, format="json", data=body, extra=headers)

        pr = PullRequest.objects.first()
        review = PullRequestReview.objects.first()

        self.assertEqual(review.html_url, review_data["html_url"])
        self.assertEqual(review.pull_request, pr)
        self.assertEqual(review.author_github_name, social_profile.github_name)
        self.assertEqual(review.body, review_data["body"])
        self.assertEqual(review.commit_id, review_data["commit_id"])
        self.assertEqual(review.state, review_data["state"])
        self.assertEqual(review.user, social_profile.user)

        self.assertEqual(
            review.submitted_at,
            strp_github_standard_time(review_data["submitted_at"]))

        self.client.post(url, format="json", data=body, extra=headers)
        self.assertEqual(PullRequest.objects.all().count(), 1)
        self.assertEqual(PullRequestReview.objects.all().count(), 1)
Beispiel #11
0
    def test_that_project_submission_type_REPOSITORY_creates_a_repo_with_flavourful_name(
            self, get_repo, *_):
        content_item = factories.ProjectContentItemFactory(
            flavours=[TYPESCRIPT, JAVASCRIPT])

        card_ts = factories.AgileCardFactory(
            status=AgileCard.READY,
            recruit_project=None,
            content_item=content_item,
            flavours=[TYPESCRIPT],
            assignees=[SocialProfileFactory().user],
        )

        card_js = factories.AgileCardFactory(
            status=AgileCard.READY,
            recruit_project=None,
            content_item=content_item,
            flavours=[JAVASCRIPT],
            assignees=[SocialProfileFactory().user],
        )

        self.assertIsNone(card_js.recruit_project)

        card_ts.start_project()
        card_js.start_project()

        self.assertNotEqual(card_ts.recruit_project, card_js.recruit_project)

        ts_project_flavours = [
            o.name for o in card_ts.recruit_project.flavours.all()
        ]
        self.assertEqual(ts_project_flavours, [TYPESCRIPT])

        js_project_flavours = [
            o.name for o in card_js.recruit_project.flavours.all()
        ]
        self.assertEqual(js_project_flavours, [JAVASCRIPT])
Beispiel #12
0
    def test_start_project_works_even_if_project_instance_exists(
            self, create_repo_and_assign_contributer, get_repo,
            add_collaborator, Api):
        card = factories.AgileCardFactory(
            status=AgileCard.READY,
            recruit_project=None,
            content_item=factories.ProjectContentItemFactory(),
        )
        card.assignees.add(SocialProfileFactory().user)
        self.assertIsNone(card.recruit_project)

        get_repo.return_value = {
            "full_name": "me/kiff",
            "owner": {
                "login": "******"
            },
            "ssh_url": "https://whatever.git",
            "private": True,
            "created_at": datetime.now().strftime(GITHUB_DATETIME_FORMAT),
            "archived": False,
        }

        card.set_due_time(timezone.now())
        self.assertEqual(card.status, AgileCard.READY)

        self.assertIsNotNone(card.recruit_project)
        card.start_project()

        project = card.recruit_project

        card.refresh_from_db()
        project.refresh_from_db()

        self.assert_users_same(card=card, project=project)
        self.assertEqual(project.content_item, card.content_item)
        self.assertTrue(create_repo_and_assign_contributer.called)
        self.assertIsNotNone(project.repository)
        self.assertEqual(card.status, AgileCard.IN_PROGRESS)
        self.assertIsNotNone(project.start_time)
Beispiel #13
0
    def test_start_project_creates_project_if_not_exists(self, get_repo, *_):

        card = factories.AgileCardFactory(
            status=AgileCard.READY,
            recruit_project=None,
            content_item=factories.ProjectContentItemFactory(
                project_submission_type=ContentItem.REPOSITORY),
            assignees=[SocialProfileFactory().user],
        )

        self.assertIsNone(card.recruit_project)

        get_repo.return_value = {
            "full_name": "me/kiff",
            "owner": {
                "login": "******"
            },
            "ssh_url": "https://whatever.git",
            "private": True,
            "created_at": timezone.now().strftime(GITHUB_DATETIME_FORMAT),
            "archived": False,
        }

        card.start_project()

        self.assertIsNotNone(card.recruit_project)
        project = card.recruit_project

        card.refresh_from_db()
        project.refresh_from_db()

        self.assert_users_same(card=card, project=project)
        self.assertEqual(project.content_item, card.content_item)
        self.assertTrue(project.setup_repository.called)
        self.assertEqual(card.status, AgileCard.IN_PROGRESS)
        self.assertIsNotNone(project.start_time)
Beispiel #14
0
    def setUp(self):
        bot = SocialProfileFactory(github_name=GITHUB_BOT_USERNAME)

        GithubOAuthTokenFactory(user=bot.user)