From a05eefa821a8605d0741f58015cfe8dbf43e8897 Mon Sep 17 00:00:00 2001 From: Piotr Zalewa Date: Fri, 3 May 2013 11:57:32 +0200 Subject: [PATCH] device filtering and some fixes --- docs/development.rst | 17 ++++++++++++++++ kitchensink/collection/api.py | 6 +++++- kitchensink/collection/models.py | 2 ++ kitchensink/collection/tests/test_api.py | 25 ++++++++++++++++++++++++ kitchensink/device/api.py | 4 ++-- 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/docs/development.rst b/docs/development.rst index 37d04ce..cdfd1e1 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -63,3 +63,20 @@ PUSH Stored in non relational database Result will connect phone, device and will contain test data We should be able to retrieve statistical information by device, time + +Test result format: + +.. code-block:: json + + { + {api_name}: { + "preparation": (-1/0/1), # -1: no preparation needed + # 0: not prepared (and it should) + # 1: prepared + "tests": [ + [{testName}: (0/1)], # 0: failed + # 1: passed + ... + ] + } + } diff --git a/kitchensink/collection/api.py b/kitchensink/collection/api.py index 67be043..2558adf 100644 --- a/kitchensink/collection/api.py +++ b/kitchensink/collection/api.py @@ -17,6 +17,10 @@ class ResultResource(ModelResource): class Meta: queryset = Result.objects.all() - allowed_methods = ('post',) + allowed_methods = ('get', 'post') authorization = Authorization() always_return_data = True + filtering = { + 'device': ALL_WITH_RELATIONS, + 'phone': ALL_WITH_RELATIONS + } diff --git a/kitchensink/collection/models.py b/kitchensink/collection/models.py index 3ba2434..b4f1c5c 100644 --- a/kitchensink/collection/models.py +++ b/kitchensink/collection/models.py @@ -22,6 +22,8 @@ class Result(BaseModel): phone = models.ForeignKey(Phone) #: Phone model device = models.ForeignKey(Device, related_name='results') + #: version of the kitchecnsink app + app_version = models.CharField(max_length=10) #: value of ``navigator.userAgent`` user_agent = models.CharField(max_length=255) #: results of the tests in JSON form diff --git a/kitchensink/collection/tests/test_api.py b/kitchensink/collection/tests/test_api.py index 4136119..cb997ce 100644 --- a/kitchensink/collection/tests/test_api.py +++ b/kitchensink/collection/tests/test_api.py @@ -36,3 +36,28 @@ def test_add_result(self): eq_(post_response.status_code, 201) eq_(Result.objects.count(), 1) eq_(self.device.results.count(), 1) + + def test_list_results_by_model(self): + test_result = { + "device": self.device, + "phone": self.phone, + "user_agent": "user agent 1", + "test_result": simplejson.dumps({ + "api-name-1": { + "preparation": 1, + "tests": [["test-name-1", 1], ["test-name-2", 1],] + } + }) + } + Result.objects.create(**test_result) + url = '%s?device__model=%s&device__make__slug=%s' % ( + Result.get_api_uri('v1'), + self.device.model, + self.make.slug) + response = self.client.get(url, content_type='application/json') + eq_(response.status_code, 200) + data = simplejson.loads(response.content) + eq_(len(data['objects']), 1) + returned_test_result = simplejson.loads( + data['objects'][0]['test_result']) + eq_(returned_test_result['api-name-1']['preparation'], 1) diff --git a/kitchensink/device/api.py b/kitchensink/device/api.py index 4a526c7..4d731ff 100644 --- a/kitchensink/device/api.py +++ b/kitchensink/device/api.py @@ -15,8 +15,7 @@ class Meta: allowed_methods = ('get',) always_return_data = True filtering = { - 'pk': ALL, - 'slug': ALL, + 'slug': ALL } @@ -30,4 +29,5 @@ class Meta: always_return_data = True filtering = { 'make': ALL_WITH_RELATIONS, + 'model': ALL }