Commit 80613361 by Will Daly

Move user_service into user_api/api

parent 61dbd70c
""" """
Test the user service Test the user course tag API.
""" """
from django.test import TestCase from django.test import TestCase
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from user_api import user_service from user_api.api import course_tag as course_tag_api
from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey
...@@ -19,17 +19,17 @@ class TestUserService(TestCase): ...@@ -19,17 +19,17 @@ class TestUserService(TestCase):
def test_get_set_course_tag(self): def test_get_set_course_tag(self):
# get a tag that doesn't exist # get a tag that doesn't exist
tag = user_service.get_course_tag(self.user, self.course_id, self.test_key) tag = course_tag_api.get_course_tag(self.user, self.course_id, self.test_key)
self.assertIsNone(tag) self.assertIsNone(tag)
# test setting a new key # test setting a new key
test_value = 'value' test_value = 'value'
user_service.set_course_tag(self.user, self.course_id, self.test_key, test_value) course_tag_api.set_course_tag(self.user, self.course_id, self.test_key, test_value)
tag = user_service.get_course_tag(self.user, self.course_id, self.test_key) tag = course_tag_api.get_course_tag(self.user, self.course_id, self.test_key)
self.assertEqual(tag, test_value) self.assertEqual(tag, test_value)
#test overwriting an existing key #test overwriting an existing key
test_value = 'value2' test_value = 'value2'
user_service.set_course_tag(self.user, self.course_id, self.test_key, test_value) course_tag_api.set_course_tag(self.user, self.course_id, self.test_key, test_value)
tag = user_service.get_course_tag(self.user, self.course_id, self.test_key) tag = course_tag_api.get_course_tag(self.user, self.course_id, self.test_key)
self.assertEqual(tag, test_value) self.assertEqual(tag, test_value)
...@@ -7,7 +7,7 @@ import xblock.reference.plugins ...@@ -7,7 +7,7 @@ import xblock.reference.plugins
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.conf import settings from django.conf import settings
from user_api import user_service from user_api.api import course_tag as user_course_tag_api
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.x_module import ModuleSystem from xmodule.x_module import ModuleSystem
from xmodule.partitions.partitions_service import PartitionService from xmodule.partitions.partitions_service import PartitionService
...@@ -144,7 +144,7 @@ class UserTagsService(object): ...@@ -144,7 +144,7 @@ class UserTagsService(object):
the current course id and current user. the current course id and current user.
""" """
COURSE_SCOPE = user_service.COURSE_SCOPE COURSE_SCOPE = user_course_tag_api.COURSE_SCOPE
def __init__(self, runtime): def __init__(self, runtime):
self.runtime = runtime self.runtime = runtime
...@@ -161,11 +161,13 @@ class UserTagsService(object): ...@@ -161,11 +161,13 @@ class UserTagsService(object):
scope: the current scope of the runtime scope: the current scope of the runtime
key: the key for the value we want key: the key for the value we want
""" """
if scope != user_service.COURSE_SCOPE: if scope != user_course_tag_api.COURSE_SCOPE:
raise ValueError("unexpected scope {0}".format(scope)) raise ValueError("unexpected scope {0}".format(scope))
return user_service.get_course_tag(self._get_current_user(), return user_course_tag_api.get_course_tag(
self.runtime.course_id, key) self._get_current_user(),
self.runtime.course_id, key
)
def set_tag(self, scope, key, value): def set_tag(self, scope, key, value):
""" """
...@@ -175,11 +177,13 @@ class UserTagsService(object): ...@@ -175,11 +177,13 @@ class UserTagsService(object):
key: the key that to the value to be set key: the key that to the value to be set
value: the value to set value: the value to set
""" """
if scope != user_service.COURSE_SCOPE: if scope != user_course_tag_api.COURSE_SCOPE:
raise ValueError("unexpected scope {0}".format(scope)) raise ValueError("unexpected scope {0}".format(scope))
return user_service.set_course_tag(self._get_current_user(), return user_course_tag_api.set_course_tag(
self.runtime.course_id, key, value) self._get_current_user(),
self.runtime.course_id, key, value
)
class LmsModuleSystem(LmsHandlerUrls, ModuleSystem): # pylint: disable=abstract-method class LmsModuleSystem(LmsHandlerUrls, ModuleSystem): # pylint: disable=abstract-method
......
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