Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
device filtering and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zalun committed May 3, 2013
1 parent fc63462 commit a05eefa
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
17 changes: 17 additions & 0 deletions docs/development.rst
Expand Up @@ -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
...
]
}
}
6 changes: 5 additions & 1 deletion kitchensink/collection/api.py
Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions kitchensink/collection/models.py
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions kitchensink/collection/tests/test_api.py
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions kitchensink/device/api.py
Expand Up @@ -15,8 +15,7 @@ class Meta:
allowed_methods = ('get',)
always_return_data = True
filtering = {
'pk': ALL,
'slug': ALL,
'slug': ALL
}


Expand All @@ -30,4 +29,5 @@ class Meta:
always_return_data = True
filtering = {
'make': ALL_WITH_RELATIONS,
'model': ALL
}

0 comments on commit a05eefa

Please sign in to comment.