Browse Source

Fix tests and ignore media files in git

master
Joshua Rubingh 12 months ago
parent
commit
bb23767a70
  1. 1
      .gitignore
  2. 14
      VRE/apps/study/serializers.py
  3. 56
      VRE/apps/study/tests.py

1
.gitignore vendored

@ -144,4 +144,5 @@ cython_debug/ @@ -144,4 +144,5 @@ cython_debug/
VRE/test.py
VRE/db.sqlite3.org
VRE/media/*
.idea

14
VRE/apps/study/serializers.py

@ -65,13 +65,17 @@ class StudySerializer(serializers.ModelSerializer): @@ -65,13 +65,17 @@ class StudySerializer(serializers.ModelSerializer):
except KeyError:
contributors_data = []
# Save the study
# We save in two steps, as we want to use the Study ID for storage path which is only available after creating
avatar = validated_data.pop('avatar')
try:
avatar = validated_data.pop('avatar')
except Exception:
avatar = None
study = Study.objects.create(**validated_data)
# Now attach the image to the study which has an Auto ID value now
study.avatar = avatar
study.save()
if avatar is not None:
# Now attach the image to the study which has an Auto ID value now
study.avatar = avatar
study.save()
# Add any optional contributors to the study
for contributor in contributors_data:

56
VRE/apps/study/tests.py

@ -102,6 +102,62 @@ class StudyCreateTest(TestCase): @@ -102,6 +102,62 @@ class StudyCreateTest(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json()['results']), 1)
def test_create_study_with_image(self):
endpoint = 'http://testserver' + reverse('api:v1:study-list')
response = self.client.get(endpoint)
# First step, make sure we do not have any studies
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json()['results']), 0)
# Now we create a new study
# Need a study field based on faculty
study_field = StudyField.objects.filter(faculty=self.faculty).first()
endpoint = 'http://testserver' + reverse('api:v1:study-list')
data = {
"name": "Test Onderzoek",
"description": "Doe maar een lange onderzoek",
"code": "12345",
"human_subject": False,
"field": study_field.id,
"avatar": "iVBORw0KGgoAAAANSUhEUgAAADIAAAAxCAYAAACYq/ofAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9btVIrHewg4pChOlkQFXHUKhShQqgVWnUwufQLmjQkKS6OgmvBwY/FqoOLs64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JikW7Jx9M6e1bYjPE6J9o/T0dGyNO/eQoHybIFj9s5R4JXvWjRwAjqY0aB5xJUvyByYClmSfU5zCZ2caLu8PpDdkzez2D9huuJFCUJz07eAQfv88Zsd+ADCbzQGDkAXi3N1yKXwRB6+TvThTb+6lGgPOObRabUBva2Tdouj1egDAjtkX7ipZJ5mHJbuaFVee6+/oGhCQsrIyR4iZ4i5nAMoi72Elptu9GQyRfa+VkpKC8+fPP68QbBmRYHHfU9H9CX3m7gqWN3y+DuKcIzIyEnfu3MHSA68k2/jTRNeXCdq1WYaK5EBXKr9vGokIlZWVAACdOHATo7AqF689hdQ5M5je8BnE+cO+jj1iFkmz5sV2Wr07a9avj4KVG36DOJ8t22Ze/Ekg9dnmP7JtwfaG3yDOrbiC6VY9m5kAhrDitwYvLUU7CLUWBAAS8gesJ1LFE9jqLEN5YTCTvG1GVzd5EOz8aDMY+4f7c1/cVvIf4gXpYORVdaMAAAAASUVORK5CYII="
}
response = self.client.post(endpoint, json=data)
# Make sure we get a 201 result back
self.assertEqual(response.status_code, 201)
study = response.json()
# At least something should be there
self.assertNotEqual(study['avatar'], '')
def test_create_study_with_invalid_image(self):
endpoint = 'http://testserver' + reverse('api:v1:study-list')
response = self.client.get(endpoint)
# First step, make sure we do not have any studies
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json()['results']), 0)
# Now we create a new study
# Need a study field based on faculty
study_field = StudyField.objects.filter(faculty=self.faculty).first()
endpoint = 'http://testserver' + reverse('api:v1:study-list')
data = {
"name": "Test Onderzoek",
"description": "Doe maar een lange onderzoek",
"code": "12345",
"human_subject": False,
"field": study_field.id,
"avatar": "W0Rlc2t0b3AgRW50cnldDQpFeGVjPXgyZ29jbGllbnQgLS1zZXNzaW9uaWQ9MjAyMTA5MDkxMDE5MDk5NzANCkljb249L2hvbWUvam9zaHVhL1BpY3R1cmVzL0hQQ19NYXRlX0Rlc2t0b3AucG5nDQpOYW1lPUhQQyBEZXNrdG9wDQpTdGFydHVwTm90aWZ5PXRydWUNClRlcm1pbmFsPWZhbHNlDQpUeXBlPUFwcGxpY2F0aW9uDQpYLUtERS1TdWJzdGl0dXRlVUlEPWZhbHNl"
}
response = self.client.post(endpoint, json=data)
# We should get back a 400 error.
self.assertEqual(response.status_code, 400)
result = response.json()
self.assertEqual(result[0]['dataPath'], '.avatar')
self.assertEqual(result[0]['keyword'], 'invalid')
def test_create_study_invalid_study_field(self):
# Now we create a new study
# Need a study field based on faculty

Loading…
Cancel
Save