Commit 782ed102 by Oleg Marshev

Fix tests.

parent 0ef2b13c
......@@ -126,25 +126,25 @@ class AnnotationViewTests(APITestCase):
self.assertEqual(annotation_1['name'], 'foo')
self.assertEqual(annotation_2['name'], 'bar')
@unittest.skip("TODO")
@patch('notesapi.v1.views.Annotation')
def test_create_refresh(self, ann_mock):
@patch('notesapi.v1.views.Annotation', autospec=Annotation)
def test_create_refresh(self, mocked_annotation):
"""
Ensure save was with refresh.
"""
mocked_annotation.return_value.__getitem__ = lambda x, y: 'test_id'
url = reverse('api:v1:annotations') + '?refresh=true'
response = self.client.post(url, {}, format='json', **self.headers)
ann_mock.return_value.save.assert_called_once_with(refresh=True)
mocked_annotation.return_value.save.assert_called_once_with(refresh=True)
@unittest.skip("TODO")
@patch('annotator.store.Annotation')
def test_create_disable_refresh(self, ann_mock):
@patch('notesapi.v1.views.Annotation', autospec=Annotation)
def test_create_disable_refresh(self, mocked_annotation):
"""
Ensure save was without refresh.
"""
mocked_annotation.return_value.__getitem__ = lambda x, y: 'test_id'
url = reverse('api:v1:annotations') + '?refresh=false'
response = self.client.post(url, {}, format='json', **self.headers)
ann_mock.return_value.save.assert_called_once_with(refresh=False)
mocked_annotation.return_value.save.assert_called_once_with(refresh=False)
def test_read(self):
"""
......
......@@ -54,7 +54,7 @@ class AnnotationListView(APIView):
"""
Get a list of all annotations.
"""
# TODO: get user.
# TODO: get user when auth will be done.
user = None
annotations = Annotation.search(user)
......@@ -65,12 +65,12 @@ class AnnotationListView(APIView):
"""
Create a new annotation.
"""
if request.DATA is not None:
annotation = Annotation(_filter_input(request.DATA, CREATE_FILTER_FIELDS))
annotation = Annotation(_filter_input(request.DATA, CREATE_FILTER_FIELDS))
refresh = request.QUERY_PARAMS.get('refresh') != u'false'
annotation.save(refresh=refresh)
location = reverse('api:v1:annotations_detail', kwargs={'annotation_id': annotation['id']})
return Response(annotation, status=status.HTTP_201_CREATED, headers={'Location': location})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment