Commit 5fd3ff8c by Tim Babych Committed by Oleg Marshev

fixing tests

parent b61f0652
...@@ -37,7 +37,8 @@ class Note(models.Model): ...@@ -37,7 +37,8 @@ class Note(models.Model):
try: try:
self.course_id = note['course_id'] self.course_id = note['course_id']
self.usage_id = note['usage_id'] self.usage_id = note['usage_id']
self.user_id = note['user'] if not self.user_id:
self.user_id = note['user']
except KeyError as error: except KeyError as error:
raise ValidationError('Note must have a course_id and usage_id and user_id.') raise ValidationError('Note must have a course_id and usage_id and user_id.')
...@@ -97,6 +98,7 @@ class NoteMappingType(MappingType, Indexable): ...@@ -97,6 +98,7 @@ class NoteMappingType(MappingType, Indexable):
return { return {
'properties': { 'properties': {
'id': charfield, 'id': charfield,
'user': charfield,
'course_id': charfield, 'course_id': charfield,
'usage_id': charfield, 'usage_id': charfield,
'text': {'type': 'string', 'index': 'snowball', 'store': True}, 'text': {'type': 'string', 'index': 'snowball', 'store': True},
...@@ -119,7 +121,7 @@ class NoteMappingType(MappingType, Indexable): ...@@ -119,7 +121,7 @@ class NoteMappingType(MappingType, Indexable):
for i, item in enumerate(data): for i, item in enumerate(data):
if isinstance(item, dict): if isinstance(item, dict):
for k, v in item.items(): for k, v in item.items():
if isinstance(v, list) and len(v) > 0: if k != 'ranges' and isinstance(v, list) and len(v) > 0:
data[i][k] = v[0] data[i][k] = v[0]
return data return data
......
...@@ -110,7 +110,8 @@ class AnnotationDetailView(APIView): ...@@ -110,7 +110,8 @@ class AnnotationDetailView(APIView):
except Note.DoesNotExist: except Note.DoesNotExist:
return Response('Annotation not found! No update performed.', status=status.HTTP_404_NOT_FOUND) return Response('Annotation not found! No update performed.', status=status.HTTP_404_NOT_FOUND)
if note.user_id != es_note['user_id']: # changing user_id is not permitted
if note.user_id != self.request.DATA['user']:
return Response(status=status.HTTP_400_BAD_REQUEST) return Response(status=status.HTTP_400_BAD_REQUEST)
filtered_payload = _filter_input(self.request.DATA, UPDATE_FILTER_FIELDS) filtered_payload = _filter_input(self.request.DATA, UPDATE_FILTER_FIELDS)
......
...@@ -4,7 +4,7 @@ import sys ...@@ -4,7 +4,7 @@ import sys
DEBUG = False DEBUG = False
TEMPLATE_DEBUG = False TEMPLATE_DEBUG = False
DISABLE_TOKEN_CHECK = True DISABLE_TOKEN_CHECK = False
USE_TZ = True USE_TZ = True
TIME_ZONE = 'UTC' TIME_ZONE = 'UTC'
...@@ -20,7 +20,7 @@ ELASTICSEARCH_URL = 'http://127.0.0.1:9200' ...@@ -20,7 +20,7 @@ ELASTICSEARCH_URL = 'http://127.0.0.1:9200'
ELASTICSEARCH_INDEX = 'edx-notes' ELASTICSEARCH_INDEX = 'edx-notes'
ES_URLS = ['http://localhost:9200'] ES_URLS = ['http://localhost:9200']
ES_INDEXES = {'default': 'main_index'} ES_INDEXES = {'default': 'notes_index'}
ES_DISABLED = False ES_DISABLED = False
# Number of rows to return by default in result. # Number of rows to return by default in result.
......
...@@ -19,8 +19,4 @@ DATABASES = { ...@@ -19,8 +19,4 @@ DATABASES = {
es.host = ELASTICSEARCH_URL es.host = ELASTICSEARCH_URL
es.index = ELASTICSEARCH_INDEX es.index = ELASTICSEARCH_INDEX
annotator.elasticsearch.RESULTS_MAX_SIZE = RESULTS_MAX_SIZE annotator.elasticsearch.RESULTS_MAX_SIZE = RESULTS_MAX_SIZE
ES_URLS = ['http://localhost:9200']
ES_INDEXES = {'default': 'main_index'}
ES_DISABLED = False
############################################################################### ###############################################################################
...@@ -9,10 +9,9 @@ DATABASES = { ...@@ -9,10 +9,9 @@ DATABASES = {
} }
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
DISABLE_TOKEN_CHECK = False
INSTALLED_APPS += ('django_nose',) INSTALLED_APPS += ('django_nose',)
ELASTICSEARCH_INDEX = 'edx-notes-test'
############################################################################### ###############################################################################
# Override default annotator-store elasticsearch settings. # Override default annotator-store elasticsearch settings.
...@@ -22,6 +21,8 @@ es.index = ELASTICSEARCH_INDEX ...@@ -22,6 +21,8 @@ es.index = ELASTICSEARCH_INDEX
annotator.elasticsearch.RESULTS_MAX_SIZE = RESULTS_MAX_SIZE annotator.elasticsearch.RESULTS_MAX_SIZE = RESULTS_MAX_SIZE
############################################################################### ###############################################################################
ES_INDEXES = {'default': 'notes_index_test'}
LOGGING = { LOGGING = {
'version': 1, '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