added test and fixed bug for retrieve by device_local_id
diff --git a/crashreports/models.py b/crashreports/models.py
index 96507b0..be44b57 100644
--- a/crashreports/models.py
+++ b/crashreports/models.py
@@ -34,7 +34,7 @@
@transaction.atomic
def get_heartbeat_key(self):
ret = self.next_per_heartbeat_key
- self.next_per_crashreport_key = self.next_per_heartbeat_key + 1
+ self.next_per_heartbeat_key = self.next_per_heartbeat_key + 1
self.save()
return ret
diff --git a/crashreports/rest_api_crashreports.py b/crashreports/rest_api_crashreports.py
index f70dbab..606e2b7 100644
--- a/crashreports/rest_api_crashreports.py
+++ b/crashreports/rest_api_crashreports.py
@@ -25,7 +25,7 @@
queryset = Crashreport.objects.all()
permission_classes = (HasRightsOrIsDeviceOwnerDeviceCreation, )
serializer_class = CrashReportSerializer
- multiple_lookup_fields = {'id', 'uuid', 'device_local_id'}
+ multiple_lookup_fields = {'id', 'device__uuid', 'device_local_id'}
def get_object(self):
queryset = self.get_queryset()
diff --git a/crashreports/rest_api_heartbeats.py b/crashreports/rest_api_heartbeats.py
index 9842d2c..d6ab289 100644
--- a/crashreports/rest_api_heartbeats.py
+++ b/crashreports/rest_api_heartbeats.py
@@ -25,7 +25,7 @@
queryset = HeartBeat.objects.all()
permission_classes = (HasRightsOrIsDeviceOwnerDeviceCreation, )
serializer_class = HeartBeatSerializer
- multiple_lookup_fields = {'id', 'uuid', 'device_local_id'}
+ multiple_lookup_fields = {'id', 'device__uuid', 'device_local_id'}
def get_object(self):
queryset = self.get_queryset()
diff --git a/crashreports/tests.py b/crashreports/tests.py
index dc74b83..aee66d2 100644
--- a/crashreports/tests.py
+++ b/crashreports/tests.py
@@ -164,6 +164,23 @@
def test_retrieve_single_device_owner(self):
self.test_retrieve_single(self.noauth_client, 401)
+ def test_retrieve_single_by_device(self, user=None, expected_result=200):
+ count = 5
+ if user is None:
+ user = self.admin
+ self.post_multiple(self.user, self.data, count)
+ url = "{}1/".format(self.url_by_uuid.format(self.uuid))
+ print(url)
+ request = user.get(url)
+ self.assertEqual(request.status_code, expected_result)
+
+ def test_retrieve_single_by_device_noauth(self):
+ self.test_retrieve_single_by_device(user=self.user,
+ expected_result=403)
+
+ def test_retrieve_single_by_device_device_owner(self):
+ self.test_retrieve_single_by_device(self.noauth_client, 401)
+
def test_list_by_uuid(self):
count = 5
self.post_multiple(self.user, self.data, count)
diff --git a/crashreports/urls.py b/crashreports/urls.py
index 535bc0d..55a8b38 100644
--- a/crashreports/urls.py
+++ b/crashreports/urls.py
@@ -15,7 +15,7 @@
url(r'^api/v1/crashreports/(?P<id>[0-9]+)/$',
rest_api_crashreports.RetrieveUpdateDestroyView.as_view(),
name='api_v1_crashreport'),
- url(r'^api/v1/devices/(?P<uuid>[a-f0-9-]+)/crashreports/' +
+ url(r'^api/v1/devices/(?P<device__uuid>[a-f0-9-]+)/crashreports/' +
'(?P<device_local_id>[0-9]+)/$',
rest_api_crashreports.RetrieveUpdateDestroyView.as_view(),
name='api_v1_crashreports_by_uuid'),
@@ -33,7 +33,7 @@
url(r'^api/v1/heartbeats/(?P<id>[0-9]+)/$',
rest_api_heartbeats.RetrieveUpdateDestroyView.as_view(),
name='api_v1_heatbeat'),
- url(r'^api/v1/devices/(?P<uuid>[a-f0-9-]+)/heartbeats/' +
+ url(r'^api/v1/devices/(?P<device__uuid>[a-f0-9-]+)/heartbeats/' +
'(?P<device_local_id>[0-9]+)/$',
rest_api_heartbeats.RetrieveUpdateDestroyView.as_view(),
name='api_v1_heartbeat_by_uuid'),