Beispiel #1
0
    def test_get_pr_by_number_404(self):
        """
        Get PR object for non-existing PR
        """
        responses.add(
            responses.GET, 'https://api.github.com/repos/edx/edx-platform/pulls/1234567890',
            body=json.dumps({'message': 'Not Found'}),
            content_type='application/json; charset=utf8',
            status=404)

        with self.assertRaises(github.ObjectDoesNotExist):
            github.get_pr_by_number('edx/edx-platform', 1234567890)
Beispiel #2
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')
Beispiel #3
0
    def update_instance(self, request, pk):
        """
        Update the instance associated with this PR, creating it if necessary.

        This will update the instance's settings, but will not provision a new AppServer.
        """
        obj = self.get_object()
        # TODO: Make update_from_pr() fetch the PR, rather than us having to do it first, then
        # that method making a redundant second call to fetch the branch tip.
        pr = github.get_pr_by_number(obj.target_fork_name, obj.github_pr_number)
        try:
            obj.update_instance_from_pr(pr)
        except github.ObjectDoesNotExist:
            # The branch has been deleted from GitHub. This exception won't be needed once the
            # refactor mentioned above is implemented.
            return Response(
                {'error': 'Could not fetch updated details from GitHub.'}, status=status.HTTP_400_BAD_REQUEST
            )
        return Response({'status': 'Instance updated.'})
Beispiel #4
0
    def update_instance(self, request, pk):
        """
        Update the instance associated with this PR, creating it if necessary.

        This will update the instance's settings, but will not provision a new AppServer.
        """
        obj = self.get_object()
        # TODO: Make update_from_pr() fetch the PR, rather than us having to do it first, then
        # that method making a redundant second call to fetch the branch tip.
        pr = github.get_pr_by_number(obj.target_fork_name,
                                     obj.github_pr_number)
        try:
            obj.update_instance_from_pr(pr)
        except github.ObjectDoesNotExist:
            # The branch has been deleted from GitHub. This exception won't be needed once the
            # refactor mentioned above is implemented.
            return Response(
                {'error': 'Could not fetch updated details from GitHub.'},
                status=status.HTTP_400_BAD_REQUEST)
        return Response({'status': 'Instance updated.'})