Exemplo n.º 1
0
    def test_location_file_batch_upload(self, mock_api_client):
        self.setup_mock_get_authenticated_api_session(mock_api_client)

        file_data, expected_data = generate_testable_location_data(length=50)
        expected_calls = [
            expected_data[40:50],
            expected_data[30:40],
            expected_data[20:30],
            expected_data[10:20],
            expected_data[0:10]
        ]

        request = self.make_request(get_csv_data_as_file(file_data))

        with responses.RequestsMock() as rsps, silence_logger(level=logging.WARNING):
            mock_prison_response(rsps)
            form = LocationFileUploadForm(request.POST, request.FILES, request=request)
            self.assertTrue(form.is_valid())

            rsps.add(
                rsps.POST,
                api_url('/prisoner_locations/actions/delete_inactive/')
            )
            rsps.add(
                rsps.POST,
                api_url('/prisoner_locations/')
            )
            rsps.add(
                rsps.POST,
                api_url('/prisoner_locations/actions/delete_old/')
            )
            form.update_locations()

            for call in rsps.calls:
                if call.request.url == api_url('/prisoner_locations/'):
                    self.assertEqual(
                        json.loads(call.request.body.decode()),
                        expected_calls.pop()
                    )

        if expected_calls:
            self.fail('Not all location data was uploaded')
Exemplo n.º 2
0
    def test_location_file_with_ignored_prisons(self, mock_api_client):
        self.setup_mock_get_authenticated_api_session(mock_api_client)

        file_data, expected_data = generate_testable_location_data(length=20, extra_rows=[
            'A1234ZZ,Smith,John,2/9/1997,TRN',
            'A1235ZZ,Smith,Fred,2/9/1997,ZCH',
        ])
        expected_calls = [expected_data]

        request = self.make_request(get_csv_data_as_file(file_data))

        with responses.RequestsMock() as rsps, silence_logger(level=logging.WARNING):
            mock_prison_response(rsps)
            form = LocationFileUploadForm(request.POST, request.FILES, request=request)
            self.assertTrue(form.is_valid())

            rsps.add(
                rsps.POST,
                api_url('/prisoner_locations/actions/delete_inactive/')
            )
            rsps.add(
                rsps.POST,
                api_url('/prisoner_locations/')
            )
            rsps.add(
                rsps.POST,
                api_url('/prisoner_locations/actions/delete_old/')
            )
            form.update_locations()

            for call in rsps.calls:
                if call.request.url == api_url('/prisoner_locations/'):
                    self.assertEqual(
                        json.loads(call.request.body.decode()),
                        expected_calls.pop()
                    )

        if expected_calls:
            self.fail('Not all location data was uploaded')