Commit a8aaab76 by Oleg Marshev

Add test.

parent b8349632
...@@ -298,3 +298,25 @@ class AnnotationViewTests(APITestCase): ...@@ -298,3 +298,25 @@ class AnnotationViewTests(APITestCase):
result = self._get_search_results('offset=foobar') result = self._get_search_results('offset=foobar')
self.assertEqual(len(result['rows']), 20) self.assertEqual(len(result['rows']), 20)
self.assertEqual(result['rows'][0], first) self.assertEqual(result['rows'][0], first)
def test_read_all_no_annotations(self):
"""
Tests list all annotations endpoint when no annotions are present in elasticsearch.
"""
url = reverse('api:v1:annotations')
response = self.client.get(url, **self.headers)
self.assertEqual(len(response.data), 0, "no annotation should be returned in response")
def test_read_all(self):
"""
Tests list all annotations.
"""
for i in xrange(5):
kwargs = {'text': 'Foo_{}'.format(i), 'id': str(i)}
self._create_annotation(refresh=False, **kwargs)
es.conn.indices.refresh(es.index)
url = reverse('api:v1:annotations')
response = self.client.get(url, **self.headers)
self.assertEqual(len(response.data), 5, "five annotations should be returned in response")
...@@ -2,4 +2,5 @@ from .common import * ...@@ -2,4 +2,5 @@ from .common import *
DEBUG = True DEBUG = True
INSTALLED_APPS = ('django_nose',) ELASTICSEARCH_URL = 'http://127.0.0.1:9200'
ELASTICSEARCH_INDEX = 'edx-notes-dev'
...@@ -12,7 +12,7 @@ DATABASES = { ...@@ -12,7 +12,7 @@ DATABASES = {
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
INSTALLED_APPS = ('django_nose',) INSTALLED_APPS += ('django_nose',)
ELASTICSEARCH_URL = 'http://127.0.0.1:9200' ELASTICSEARCH_URL = 'http://127.0.0.1:9200'
ELASTICSEARCH_INDEX = 'edx-notes-test' ELASTICSEARCH_INDEX = 'edx-notes-test'
...@@ -10,5 +10,19 @@ class OperationalEndpointsTest(APITestCase): ...@@ -10,5 +10,19 @@ class OperationalEndpointsTest(APITestCase):
""" """
Test if server is alive. Test if server is alive.
""" """
response = self.client.get('/status', follow=True) response = self.client.get(reverse('status'))
self.assertEquals(response.status_code, 200) self.assertEquals(response.status_code, 200)
def test_root(self):
"""
Test root endpoint.
"""
response = self.client.get(reverse('root'))
self.assertEquals(response.status_code, 200)
self.assertEquals(
response.data,
{
"name": "edX Notes API",
"version": "1"
}
)
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