diff --git a/tom_dataproducts/migrations/0012_alter_reduceddatum_data_product_and_more.py b/tom_dataproducts/migrations/0012_alter_reduceddatum_data_product_and_more.py new file mode 100644 index 000000000..5696653f4 --- /dev/null +++ b/tom_dataproducts/migrations/0012_alter_reduceddatum_data_product_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 4.2.1 on 2023-10-23 22:03 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('tom_dataproducts', '0011_reduceddatum_message'), + ] + + operations = [ + migrations.AlterField( + model_name='reduceddatum', + name='data_product', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='tom_dataproducts.dataproduct'), + ), + migrations.AlterField( + model_name='reduceddatum', + name='source_location', + field=models.CharField(blank=True, default='', max_length=200), + ), + migrations.AlterField( + model_name='reduceddatum', + name='source_name', + field=models.CharField(blank=True, default='', max_length=100), + ), + ] diff --git a/tom_dataproducts/models.py b/tom_dataproducts/models.py index 6e2664471..1aa3da09f 100644 --- a/tom_dataproducts/models.py +++ b/tom_dataproducts/models.py @@ -336,8 +336,8 @@ class ReducedDatum(models.Model): max_length=100, default='' ) - source_name = models.CharField(max_length=100, default='') - source_location = models.CharField(max_length=200, default='') + source_name = models.CharField(max_length=100, default='', blank=True) + source_location = models.CharField(max_length=200, default='', blank=True) timestamp = models.DateTimeField(null=False, blank=False, default=datetime.now, db_index=True) value = models.JSONField(null=False, blank=False) message = models.ManyToManyField(AlertStreamMessage) diff --git a/tom_dataproducts/tests/test_api.py b/tom_dataproducts/tests/test_api.py index 5bb39b4d8..2ad4bc694 100644 --- a/tom_dataproducts/tests/test_api.py +++ b/tom_dataproducts/tests/test_api.py @@ -141,3 +141,19 @@ def test_upload_same_reduced_datum_twice(self): self.client.post(reverse('api:reduceddatums-list'), self.rd_data, format='json') rd_queryset = ReducedDatum.objects.all() self.assertEqual(rd_queryset.count(), 2) + + def test_upload_reduced_datum_no_sharing_location(self): + """ + Test that a reduced datum can be uploaded without a source_location. + """ + del self.rd_data['source_location'] + response = self.client.post(reverse('api:reduceddatums-list'), self.rd_data, format='json') + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + + def test_upload_reduced_datum_no_sharing_name(self): + """ + Test that a reduced datum can be uploaded without a source_name. + """ + del self.rd_data['source_name'] + response = self.client.post(reverse('api:reduceddatums-list'), self.rd_data, format='json') + self.assertEqual(response.status_code, status.HTTP_201_CREATED)