def test_update_column_not_in_schema(self): """ Test that if we introduce a column not in the the dataset it will not validate :return: """ record = self.record_1 incorrect_data = clone(record.data) incorrect_data['Extra Column'] = "Extra Value" data = { "dataset": record.dataset.pk, "data": incorrect_data } url = reverse('api:record-detail', kwargs={"pk": record.pk}) # set strict mode url = helpers.set_strict_mode(url) client = self.custodian_1_client count = Record.objects.count() self.assertEqual( client.put(url, data, format='json').status_code, status.HTTP_400_BAD_REQUEST ) self.assertEqual(Record.objects.count(), count) self.assertEqual( client.patch(url, data, format='json').status_code, status.HTTP_400_BAD_REQUEST ) self.assertEqual(Record.objects.count(), count)
def test_headers_not_trimmed_with_api(self): """ Contrary to the upload csv or xlsx when using the API in strict mode, it should not accept fields with header or trailing space see notes on https://decbugs.com/view.php?id=6863 """ fields = ['What', 'When', 'Who'] dataset = self._create_dataset_from_rows([ fields ]) schema = dataset.schema self.assertEqual(schema.headers, fields) # create record with trailing and heading space data = { 'What ': 'Something', ' When': '2018-02-10', ' Who ': 'me' } payload = { 'dataset': dataset.pk, 'data': data } client = self.custodian_1_client url = helpers.set_strict_mode(reverse('api:record-list')) resp = client.post(url, payload, format='json') self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
def test_empty_not_allowed(self): record = self.record_1 data = {"dataset": record.dataset.pk, "data": {}} url = reverse('api:record-list') # set strict mode url = helpers.set_strict_mode(url) client = self.custodian_1_client count = Record.objects.count() self.assertEqual( client.post(url, data, format='json').status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(Record.objects.count(), count)