Skip to content

Commit

Permalink
fix test for latest django-rest-framework; allow flexible unique cons…
Browse files Browse the repository at this point in the history
…traint in trajectory
  • Loading branch information
mayofaulkner committed Mar 21, 2024
1 parent bfcd921 commit 61193db
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 1 addition & 2 deletions alyx/alyx/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sys
import pytz
import uuid
from collections import OrderedDict
import one.alf.spec
from datetime import datetime
import traceback
Expand Down Expand Up @@ -445,7 +444,7 @@ def ar(self, r, code=200):
"""
self.assertTrue(r.status_code == code, r.data)
pkeys = {'count', 'next', 'previous', 'results'}
if isinstance(r.data, OrderedDict) and set(r.data.keys()) == pkeys:
if isinstance(r.data, dict) and set(r.data.keys()) == pkeys:
return r.data['results']
else:
return r.data
Expand Down
6 changes: 5 additions & 1 deletion alyx/experiments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,12 @@ class TrajectoryEstimate(models.Model):

class Meta:
constraints = [
models.UniqueConstraint(fields=['provenance', 'chronic_insertion'],
condition=models.Q(probe_insertion__isnull=True),
name='unique_trajectory_per_chronic_provenance'),
models.UniqueConstraint(fields=['provenance', 'probe_insertion'],
name='unique_trajectory_per_provenance')
condition=models.Q(probe_insertion__isnull=False),
name='unique_trajectory_per_provenance'),
]

def __str__(self):
Expand Down
12 changes: 11 additions & 1 deletion alyx/experiments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ class Meta:

class TrajectoryEstimateSerializer(serializers.ModelSerializer):
probe_insertion = serializers.SlugRelatedField(
read_only=False, required=False, slug_field='id', many=False,
read_only=False, required=False, slug_field='id', many=False, allow_null=True,
queryset=ProbeInsertion.objects.all(),
)

x = serializers.FloatField(required=True, allow_null=True)
y = serializers.FloatField(required=True, allow_null=True)
z = serializers.FloatField(required=False, allow_null=True)
Expand All @@ -45,6 +46,15 @@ class TrajectoryEstimateSerializer(serializers.ModelSerializer):
queryset=CoordinateSystem.objects.all(),
)

def to_internal_value(self, data):
if data.get('chronic_insertion', None) is None:
data['chronic_insertion'] = None

if data.get('probe_insertion', None) is None:
data['probe_insertion'] = None

return super(TrajectoryEstimateSerializer, self).to_internal_value(data)

class Meta:
model = TrajectoryEstimate
fields = '__all__'
Expand Down
2 changes: 1 addition & 1 deletion alyx/experiments/tests_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def test_create_list_delete_fov(self):
url = reverse('fovlocation-list')
with transaction.atomic():
response = self.post(url, loc_dict)
self.ar(response, 500)
self.assertIn(response.status_code, (400, 500)) # In later versions status code is 400

url = reverse('fieldsofview-list')
# FOV location containing atlas ID 9 should no longer be default provenance and therefore
Expand Down

0 comments on commit 61193db

Please sign in to comment.