Example #1
0
    def test_get_pr_by_number(self):
        """
        Get PR object for existing PR number
        """
        responses.add(
            responses.GET,
            'https://api.github.com/repos/edx/edx-platform/pulls/8474',
            body=get_raw_fixture('github/api_pr.json'),
            content_type='application/json; charset=utf8',
            status=200)

        pr = github.get_pr_by_number('edx/edx-platform', 8474)
        self.assertEqual(
            pr.title,
            'Add feature flag to allow hiding the discussion tab for individual courses.'
        )
        self.assertEqual(
            pr.body,
            '**Description**\r\n\r\nHello!\nDesc with unicode «ταБЬℓσ»\r\n'
            '- - -\r\n**Settings**\r\n```yaml\r\nEDXAPP_FEATURES:\r\n  ALLOW: true\r\n```'
        )
        self.assertEqual(pr.number, 8474)
        self.assertEqual(pr.fork_name, 'open-craft/edx-platform')
        self.assertEqual(pr.repo_name, 'edx/edx-platform')
        self.assertEqual(pr.branch_name, 'smarnach/hide-discussion-tab')
        self.assertEqual(pr.extra_settings,
                         'EDXAPP_FEATURES:\r\n  ALLOW: true\r\n')
        self.assertEqual(pr.username, 'smarnach')
Example #2
0
    def test_get_pr_list_from_usernames(self, mock_get_pr_by_number):
        """
        Get list of open PR for a list of users
        """
        # Verify we get no PRs when invoking the function with an empty username list.
        self.assertEqual(
            github.get_pr_list_from_usernames([], 'edx/edx-platform'), [])

        responses.add(
            responses.GET,
            'https://api.github.com/search/issues?sort=created&q=is:open '
            'is:pr author:itsjeyd author:haikuginger repo:edx/edx-platform',
            match_querystring=True,
            body=get_raw_fixture(
                'github/api_search_open_prs_multiple_users.json'),
            content_type='application/json; charset=utf8',
            status=200)

        mock_get_pr_by_number.side_effect = lambda fork_name, pr_number: [
            fork_name, pr_number
        ]

        self.assertEqual(
            github.get_pr_list_from_usernames(['itsjeyd', 'haikuginger'],
                                              'edx/edx-platform'),
            [['edx/edx-platform', 9147], ['edx/edx-platform', 9146],
             ['edx/edx-platform', 15921]])
Example #3
0
    def test_get_pr_by_number(self):
        """
        Get PR object for existing PR number
        """
        responses.add(
            responses.GET, 'https://api.github.com/repos/edx/edx-platform/pulls/8474',
            body=get_raw_fixture('github/api_pr.json'),
            content_type='application/json; charset=utf8',
            status=200
        )

        pr = github.get_pr_by_number('edx/edx-platform', 8474)
        self.assertEqual(
            pr.title,
            'Add feature flag to allow hiding the discussion tab for individual courses.')
        self.assertEqual(
            pr.body,
            '**Description**\r\n\r\nHello!\nDesc with unicode «ταБЬℓσ»\r\n'
            '- - -\r\n**Settings**\r\n```yaml\r\nEDXAPP_FEATURES:\r\n  ALLOW: true\r\n```')
        self.assertEqual(pr.number, 8474)
        self.assertEqual(pr.fork_name, 'open-craft/edx-platform')
        self.assertEqual(pr.repo_name, 'edx/edx-platform')
        self.assertEqual(pr.branch_name, 'smarnach/hide-discussion-tab')
        self.assertEqual(pr.extra_settings, 'EDXAPP_FEATURES:\r\n  ALLOW: true\r\n')
        self.assertEqual(pr.username, 'smarnach')
Example #4
0
    def test_get_username_list_from_team(self):
        """
        Get list of members in a team
        """
        responses.add(responses.GET,
                      'https://api.github.com/orgs/open-craft/teams',
                      body=get_raw_fixture('github/api_teams.json'),
                      content_type='application/json; charset=utf8',
                      status=200)
        responses.add(responses.GET,
                      'https://api.github.com/teams/799617/members',
                      body=get_raw_fixture('github/api_members.json'),
                      content_type='application/json; charset=utf8',
                      status=200)

        self.assertEqual(github.get_username_list_from_team('open-craft'), [
            'antoviaque', 'bradenmacdonald', 'e-kolpakov', 'itsjeyd',
            'Kelketek', 'mtyaka', 'smarnach'
        ])
Example #5
0
    def test_get_username_list_from_team(self):
        """
        Get list of members in a team
        """
        responses.add(
            responses.GET, 'https://api.github.com/orgs/open-craft/teams',
            body=get_raw_fixture('github/api_teams.json'),
            content_type='application/json; charset=utf8',
            status=200)
        responses.add(
            responses.GET, 'https://api.github.com/teams/799617/members',
            body=get_raw_fixture('github/api_members.json'),
            content_type='application/json; charset=utf8',
            status=200)

        self.assertEqual(
            github.get_username_list_from_team('open-craft'),
            ['antoviaque', 'bradenmacdonald', 'e-kolpakov', 'itsjeyd', 'Kelketek', 'mtyaka', 'smarnach']
        )
Example #6
0
    def test_get_username_list_from_team_404(self):
        """
        Get list of open PR for non-existent team
        """
        responses.add(
            responses.GET, 'https://api.github.com/orgs/open-craft/teams',
            body=get_raw_fixture('github/api_teams.json'),
            content_type='application/json; charset=utf8',
            status=200)

        with self.assertRaises(KeyError, msg='non-existent'):
            github.get_username_list_from_team('open-craft', team_name='non-existent')
Example #7
0
    def test_get_username_list_from_team_404(self):
        """
        Get list of open PR for non-existent team
        """
        responses.add(responses.GET,
                      'https://api.github.com/orgs/open-craft/teams',
                      body=get_raw_fixture('github/api_teams.json'),
                      content_type='application/json; charset=utf8',
                      status=200)

        with self.assertRaises(KeyError, msg='non-existent'):
            github.get_username_list_from_team('open-craft',
                                               team_name='non-existent')
Example #8
0
 def test_get_pr_info_by_number(self):
     """
     Get all available information about PR by PR number
     """
     pr_fixture = get_raw_fixture('github/api_pr.json')
     responses.add(
         responses.GET,
         'https://api.github.com/repos/edx/edx-platform/pulls/8474',
         body=pr_fixture,
         content_type='application/json; charset=utf8',
         status=200)
     pr_info = github.get_pr_info_by_number('edx/edx-platform', 8474)
     expected_pr_info = json.loads(pr_fixture)
     self.assertEqual(pr_info, expected_pr_info)
Example #9
0
 def test_get_pr_info_by_number(self):
     """
     Get all available information about PR by PR number
     """
     pr_fixture = get_raw_fixture('github/api_pr.json')
     responses.add(
         responses.GET, 'https://api.github.com/repos/edx/edx-platform/pulls/8474',
         body=pr_fixture,
         content_type='application/json; charset=utf8',
         status=200
     )
     pr_info = github.get_pr_info_by_number('edx/edx-platform', 8474)
     expected_pr_info = json.loads(pr_fixture)
     self.assertEqual(pr_info, expected_pr_info)
Example #10
0
    def test_get_username_list_from_team_404(self):
        """
        Get list of open PR for non-existent team
        """
        responses.add(
            responses.GET,
            "https://api.github.com/orgs/open-craft/teams",
            body=get_raw_fixture("github/api_teams.json"),
            content_type="application/json; charset=utf8",
            status=200,
        )

        with self.assertRaises(KeyError, msg="non-existent"):
            github.get_username_list_from_team("open-craft", team_name="non-existent")
Example #11
0
    def test_get_username_list_from_team(self):
        """
        Get list of members in a team
        """
        responses.add(
            responses.GET,
            "https://api.github.com/orgs/open-craft/teams",
            body=get_raw_fixture("github/api_teams.json"),
            content_type="application/json; charset=utf8",
            status=200,
        )
        responses.add(
            responses.GET,
            "https://api.github.com/teams/799617/members",
            body=get_raw_fixture("github/api_members.json"),
            content_type="application/json; charset=utf8",
            status=200,
        )

        self.assertEqual(
            github.get_username_list_from_team("open-craft"),
            ["antoviaque", "bradenmacdonald", "e-kolpakov", "itsjeyd", "Kelketek", "mtyaka", "smarnach"],
        )
Example #12
0
    def test_get_pr_list_from_username(self, mock_get_pr_by_number):
        """
        Get list of open PR for user
        """
        responses.add(
            responses.GET, 'https://api.github.com/search/issues?sort=created'
                           '&q=is:open is:pr author:itsjeyd repo:edx/edx-platform',
            match_querystring=True,
            body=get_raw_fixture('github/api_search_open_prs_user.json'),
            content_type='application/json; charset=utf8',
            status=200)

        mock_get_pr_by_number.side_effect = lambda fork_name, pr_number: [fork_name, pr_number]

        self.assertEqual(
            github.get_pr_list_from_username('itsjeyd', 'edx/edx-platform'),
            [['edx/edx-platform', 9147], ['edx/edx-platform', 9146]]
        )
Example #13
0
    def test_get_pr_list_from_username(self, mock_get_pr_by_number):
        """
        Get list of open PR for user
        """
        responses.add(
            responses.GET, 'https://api.github.com/search/issues?sort=created'
                           '&q=is:open is:pr author:itsjeyd repo:edx/edx-platform',
            match_querystring=True,
            body=get_raw_fixture('github/api_search_open_prs_user.json'),
            content_type='application/json; charset=utf8',
            status=200)

        mock_get_pr_by_number.side_effect = lambda fork_name, pr_number: [fork_name, pr_number]

        self.assertEqual(
            github.get_pr_list_from_username('itsjeyd', 'edx/edx-platform'),
            [['edx/edx-platform', 9147], ['edx/edx-platform', 9146]]
        )
Example #14
0
    def test_get_pr_by_number(self):
        """
        Get PR object for existing PR number
        """
        responses.add(
            responses.GET,
            "https://api.github.com/repos/edx/edx-platform/pulls/8474",
            body=get_raw_fixture("github/api_pr.json"),
            content_type="application/json; charset=utf8",
            status=200,
        )

        pr = github.get_pr_by_number("edx/edx-platform", 8474)
        self.assertEqual(pr.title, "Add feature flag to allow hiding the discussion tab for individual courses.")
        self.assertEqual(
            pr.body,
            "**Description**\r\n\r\nHello!\nDesc with unicode «ταБЬℓσ»\r\n"
            "- - -\r\n**Settings**\r\n```yaml\r\nEDXAPP_FEATURES:\r\n  ALLOW: true\r\n```",
        )
        self.assertEqual(pr.number, 8474)
        self.assertEqual(pr.fork_name, "open-craft/edx-platform")
        self.assertEqual(pr.branch_name, "smarnach/hide-discussion-tab")
        self.assertEqual(pr.extra_settings, "EDXAPP_FEATURES:\r\n  ALLOW: true\r\n")
        self.assertEqual(pr.username, "smarnach")