Files
edx-platform/lms/djangoapps/course_api/blocks/tests/pacts/views.py
Michael Terry cb1bb7fa64 test: switch default test store to the split store
It's long past time that the default test modulestore was Split,
instead of Old Mongo. This commit switches the default store and
fixes some tests that now fail:
- Tests that didn't expect MFE to be enabled (because we don't
  enable MFE for Old Mongo) - opt out of MFE for those
- Tests that hardcoded old key string formats
- Lots of other random little differences

In many places, I didn't spend much time trying to figure out how to
properly fix the test, and instead just set the modulestore to Old
Mongo.

For those tests that I didn't spend time investigating, I've set
the modulestore to TEST_DATA_MONGO_AMNESTY_MODULESTORE - search for
that string to find further work.
2022-02-04 14:32:50 -05:00

66 lines
2.0 KiB
Python

"""
Provider state views needed by pact to setup Provider state for pact verification.
"""
import json
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from opaque_keys.edx.keys import CourseKey
from xmodule.modulestore.tests.django_utils import ModuleStoreIsolationMixin
from xmodule.modulestore.tests.factories import CourseFactory
from common.djangoapps.student.models import CourseEnrollment
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory
class ProviderState(ModuleStoreIsolationMixin):
""" Provider State Setup """
def clean_db(self, user, course_key):
""" Delete objects from SQL DB and clean mongodb instance """
CourseEnrollment.objects.filter(course_id=course_key, user=user).delete()
try:
self.end_modulestore_isolation()
except IndexError:
pass
def course_setup(self, request):
""" Setup course data """
course_key = CourseKey.from_string('course-v1:edX+DemoX+Demo_Course')
self.clean_db(request.user, course_key)
self.start_modulestore_isolation()
demo_course = CourseFactory.create(
org=course_key.org,
course=course_key.course,
run=course_key.run,
display_name="Demonstration Course",
modulestore=self.store
)
CourseEnrollmentFactory.create(user=request.user, course_id=demo_course.id)
@csrf_exempt
@require_POST
def provider_state(request):
"""
Provider state setup view needed by pact verifier.
"""
state_setup_mapping = {
'Blocks data exists for course_id course-v1:edX+DemoX+Demo_Course': ProviderState().course_setup,
}
request_body = json.loads(request.body)
state = request_body.get('state')
if state in state_setup_mapping:
print('Setting up provider state for state value: {}'.format(state))
state_setup_mapping[state](request)
return JsonResponse({'result': state})