The existing pattern of using `override_settings(MODULESTORE=...)` prevented
us from having more than one layer of subclassing in modulestore tests.
In a structure like:
@override_settings(MODULESTORE=store_a)
class BaseTestCase(ModuleStoreTestCase):
def setUp(self):
# use store
@override_settings(MODULESTORE=store_b)
class ChildTestCase(BaseTestCase):
def setUp(self):
# use store
In this case, the store actions performed in `BaseTestCase` on behalf of
`ChildTestCase` would still use `store_a`, even though the `ChildTestCase`
had specified to use `store_b`. This is because the `override_settings`
decorator would be the innermost wrapper around the `BaseTestCase.setUp` method,
no matter what `ChildTestCase` does.
To remedy this, we move the call to `override_settings` into the
`ModuleStoreTestCase.setUp` method, and use a cleanup to remove the override.
Subclasses can just defined the `MODULESTORE` class attribute to specify which
modulestore to use _for the entire `setUp` chain_.
[PLAT-419]
58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""
|
|
Tests the logical Python API layer of the Course About API.
|
|
"""
|
|
|
|
import ddt
|
|
import json
|
|
import unittest
|
|
|
|
from django.test.utils import override_settings
|
|
from django.core.urlresolvers import reverse
|
|
from rest_framework.test import APITestCase
|
|
from rest_framework import status
|
|
from django.conf import settings
|
|
from xmodule.modulestore.tests.django_utils import (
|
|
ModuleStoreTestCase, mixed_store_config
|
|
)
|
|
from xmodule.modulestore.tests.factories import CourseFactory, CourseAboutFactory
|
|
from student.tests.factories import UserFactory
|
|
|
|
|
|
@ddt.ddt
|
|
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
|
|
class CourseInfoTest(ModuleStoreTestCase, APITestCase):
|
|
"""
|
|
Test course information.
|
|
"""
|
|
USERNAME = "Bob"
|
|
EMAIL = "bob@example.com"
|
|
PASSWORD = "edx"
|
|
|
|
def setUp(self):
|
|
""" Create a course"""
|
|
super(CourseInfoTest, self).setUp()
|
|
|
|
self.course = CourseFactory.create()
|
|
self.user = UserFactory.create(username=self.USERNAME, email=self.EMAIL, password=self.PASSWORD)
|
|
self.client.login(username=self.USERNAME, password=self.PASSWORD)
|
|
|
|
def test_get_course_details_from_cache(self):
|
|
kwargs = dict()
|
|
kwargs["course_id"] = self.course.id
|
|
kwargs["course_runtime"] = self.course.runtime
|
|
kwargs["user_id"] = self.user.id
|
|
CourseAboutFactory.create(**kwargs)
|
|
resp = self.client.get(
|
|
reverse('courseabout', kwargs={"course_id": unicode(self.course.id)})
|
|
)
|
|
self.assertEqual(resp.status_code, status.HTTP_200_OK)
|
|
resp_data = json.loads(resp.content)
|
|
self.assertIsNotNone(resp_data)
|
|
|
|
resp = self.client.get(
|
|
reverse('courseabout', kwargs={"course_id": unicode(self.course.id)})
|
|
)
|
|
self.assertEqual(resp.status_code, status.HTTP_200_OK)
|
|
resp_data = json.loads(resp.content)
|
|
self.assertIsNotNone(resp_data)
|