Beispiel #1
0
    def _test_decline_legacy_request(self):
        test_data = {
            'approval_notes': 'Declining request where status code was L'}

        view = DeclineRequestViewSet.as_view(
            {'get': 'retrieve', 'put': 'update'})
        # Decline request where id == 3
        request = self.factory.put('api/decline_request/3', test_data)
        request.user = self.user
        response = view(request, pk="3")

        # HTTP 200
        self.assertEqual(response.status_code,
                         status.HTTP_200_OK, response.data)
        # expecting new request id
        self.assertNotEqual(response.data.get('id'), 3, response.data)
        # check status has been changed to declined
        self.assertEqual(response.data.get('request_status'),
                         'Legacy Rejected', response.data)
        # check approval notes
        self.assertEqual(response.data.get('approval_notes'),
                         test_data['approval_notes'], response.data)
        # check the database for status code == 'O'
        request_obj = Request.objects.get(pk=int(response.data.get('id')))
        self.assertEqual(request_obj.request_status.code, 'O', response.data)
Beispiel #2
0
    def test_decline_submitted_request(self):
        test_data = {
            'approval_notes': 'Declining request where status code was E'}

        view = DeclineRequestViewSet.as_view(
            {'get': 'retrieve', 'put': 'update'})
        # Decline request where id == 1 with test_data
        request = self.factory.put('api/decline_request', test_data)
        request.user = self.user
        response = view(request, pk=self.request_1.id)

        # HTTP 200
        self.assertEqual(response.status_code,
                         status.HTTP_200_OK, response.data)
        # expecting new request id
        self.assertNotEqual(response.data.get(
            "id"), self.request_1.id, response.data)
        # check status has been changed to declined
        self.assertEqual(response.data.get('request_status'),
                         "Declined", response.data)
        # check approval notes
        self.assertEqual(response.data.get('approval_notes'),
                         test_data['approval_notes'], response.data)
        # check the database for status code == 'R'
        request_obj = Request.objects.get(pk=int(response.data.get('id')))
        self.assertEqual(request_obj.request_status.code, 'R', response.data)
Beispiel #3
0
    def _test_decline_legacy_request(self):
        test_data = {
            'approval_notes': 'Declining request where status code was L'
        }

        view = DeclineRequestViewSet.as_view({
            'get': 'retrieve',
            'put': 'update'
        })
        # Decline request where id == 3
        request = self.factory.put('api/decline_request/3', test_data)
        request.user = self.user
        response = view(request, pk="3")

        # HTTP 200
        self.assertEqual(response.status_code, status.HTTP_200_OK,
                         response.data)
        # expecting new request id
        self.assertNotEqual(response.data.get('id'), 3, response.data)
        # check status has been changed to declined
        self.assertEqual(response.data.get('request_status'),
                         'Legacy Rejected', response.data)
        # check approval notes
        self.assertEqual(response.data.get('approval_notes'),
                         test_data['approval_notes'], response.data)
        # check the database for status code == 'O'
        request_obj = Request.objects.get(pk=int(response.data.get('id')))
        self.assertEqual(request_obj.request_status.code, 'O', response.data)
Beispiel #4
0
    def test_decline_update_extend_request(self):
        test_data = {
            'approval_notes': 'Declining request where status code was X'
        }

        view = DeclineRequestViewSet.as_view({
            'get': 'retrieve',
            'put': 'update'
        })
        # Decline request where id == 2 with test_data
        request = self.factory.put('api/decline_request', test_data)
        request.user = self.user
        response = view(request, pk=self.request_2.id)

        # HTTP 200
        self.assertEqual(response.status_code, status.HTTP_200_OK,
                         response.data)
        # expecting new request id
        self.assertNotEqual(response.data.get('id'), self.request_2.id,
                            response.data)
        # check status has been changed to declined
        self.assertEqual(response.data.get('request_status'),
                         "Update/Extension Declined", response.data)
        # check approval notes
        self.assertEqual(response.data.get('approval_notes'),
                         test_data['approval_notes'], response.data)
        # check the database for status code == 'J'
        request_obj = Request.objects.get(pk=int(response.data.get('id')))
        self.assertEqual(request_obj.request_status.code, 'J', response.data)
Beispiel #5
0
    def test_decline_request_get(self):
        view = DeclineRequestViewSet.as_view({'get': 'list'})
        request = self.factory.get('api/decline_request')
        request.user = self.user
        response = view(request)

        # HTTP 200
        self.assertEqual(response.status_code,
                         status.HTTP_405_METHOD_NOT_ALLOWED, response.data)
Beispiel #6
0
    def test_decline_request_get(self):
        view = DeclineRequestViewSet.as_view({'get': 'list'})
        request = self.factory.get('api/decline_request')
        request.user = self.user
        response = view(request)

        # HTTP 200
        self.assertEqual(response.status_code, status.HTTP_200_OK,
                         response.data)
        # Expecting 2 results from response
        # get submitted and update/extend requests
        projects = Project.objects.filter(
            Q(requests__request_status__code="E")
            | Q(requests__request_status__code="X"))
        self.assertEqual(len(response.data), len(projects))
        self.assertEqual(response.data[0]['project']['title'],
                         'Test Project 1', response.data)
        self.assertEqual(response.data[1]['project']['title'],
                         'Test Project 2', response.data)
Beispiel #7
0
    def _assert_decline_request(self,
                                projectId,
                                approval_notes="",
                                expected_http_status=status.HTTP_200_OK,
                                expected_req_status="Declined",
                                expected_status_code="D"):
        # setup tests data
        req = Request.objects.get(project_id=projectId, parent_request=None)
        test_data = {
            "compute_requests": get_compute_requests_for_request(req),
            "storage_requests": get_storage_requests_for_request(req),
            "approval_notes": approval_notes
        }

        view = DeclineRequestViewSet.as_view({
            'get': 'retrieve',
            'put': 'update'
        })
        # Approve request where id == req.id
        request = self.factory.put('api/decline_request/', test_data)
        request.user = self.user
        response = view(request, pk=str(req.id))

        # Expected HTTP status
        self.assertEquals(response.status_code, expected_http_status,
                          response.data)
        if response.status_code == status.HTTP_200_OK:
            # The following is valid if approve is successful
            # Expecting request ID to change
            self.assertNotEqual(response.data.get('id'), req.id, response.data)
            # Expected Approve status
            self.assertEqual(response.data.get('request_status'),
                             expected_req_status, response.data)
            # Expected approval notes
            self.assertEqual(response.data.get('approval_notes'),
                             approval_notes, response.data)
            # Expected status code in the databse
            request_obj = Request.objects.get(pk=int(response.data.get('id')))
            self.assertEqual(request_obj.request_status.code,
                             expected_status_code, response.data)

        return response
Beispiel #8
0
    def test_decline_o(self):
        self.project = Project.objects.create(
            title='Test Project',
            description="Test Project",
            notes="Test Project",
            creation_ts=datetime.date.today(),
            last_modified_ts=datetime.date.today(),
            created_by=self.user,
            updated_by=self.user)
        self.request_status = RequestStatus.objects.get(
            code='O', status='Legacy Rejected')
        self.request = Request.objects.create(
            project=self.project,
            request_status=self.request_status,
            funding_scheme=self.funding_scheme,
            start_date=datetime.date.today(),
            end_date=datetime.date.today(),
            creation_ts=datetime.date.today(),
            last_modified_ts=datetime.date.today(),
            created_by=self.user,
            updated_by=self.user)

        test_data = {
            'approval_notes': 'Declining request where status code was O'
        }

        view = DeclineRequestViewSet.as_view({
            'get': 'retrieve',
            'put': 'update'
        })
        # Decline request where id == 4
        request = self.factory.put('api/decline_request/4', test_data)
        request.user = self.user
        response = view(request, pk="4")

        # HTTP 404
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         response.data)
        # Expected error message
        self.assertEqual(response.data.get('detail'), 'Not found.',
                         response.data)
Beispiel #9
0
    def test_decline_o(self):
        self.project = Project.objects.create(
            title='Test Project',
            description="Test Project",
            notes="Test Project",
            creation_ts=datetime.date.today(),
            last_modified_ts=datetime.date.today(),
            created_by=self.user,
            updated_by=self.user)
        self.request_status = RequestStatus.objects.get(
            code='O', status='Legacy Rejected')
        self.request = Request.objects.create(
            project=self.project,
            request_status=self.request_status,
            funding_scheme=self.funding_scheme,
            start_date=datetime.date.today(),
            end_date=datetime.date.today(),
            creation_ts=datetime.date.today(),
            last_modified_ts=datetime.date.today(),
            created_by=self.user,
            updated_by=self.user)

        test_data = {
            'approval_notes': 'Declining request where status code was O'}

        view = DeclineRequestViewSet.as_view(
            {'get': 'retrieve', 'put': 'update'})
        # Decline request where id == 4
        request = self.factory.put('api/decline_request/4', test_data)
        request.user = self.user
        response = view(request, pk="4")

        # HTTP 404
        self.assertEqual(response.status_code,
                         status.HTTP_404_NOT_FOUND, response.data)
        # Expected error message
        self.assertEqual(response.data.get('detail'),
                         'Not found.', response.data)