コード例 #1
0
 def setUp(self):
     super().setUp()
     self.service = XQueueService(
         url=settings.XQUEUE_INTERFACE['url'],
         django_auth=settings.XQUEUE_INTERFACE['django_auth'],
         basic_auth=settings.XQUEUE_INTERFACE['basic_auth'],
         construct_callback=self.construct_callback,
         default_queuename='my-very-own-queue',
         waittime=settings.XQUEUE_WAITTIME_BETWEEN_REQUESTS,
     )
コード例 #2
0
class XQueueServiceTest(TestCase):
    """
    Tests the XQueue service methods.
    """
    @staticmethod
    def construct_callback(*args, **kwargs):
        return 'https://lms.url/callback'

    def setUp(self):
        super().setUp()
        self.service = XQueueService(
            url=settings.XQUEUE_INTERFACE['url'],
            django_auth=settings.XQUEUE_INTERFACE['django_auth'],
            basic_auth=settings.XQUEUE_INTERFACE['basic_auth'],
            construct_callback=self.construct_callback,
            default_queuename='my-very-own-queue',
            waittime=settings.XQUEUE_WAITTIME_BETWEEN_REQUESTS,
        )

    def test_interface(self):
        assert isinstance(self.service.interface, XQueueInterface)

    def test_construct_callback(self):
        assert self.service.construct_callback() == 'https://lms.url/callback'

    def test_default_queuename(self):
        assert self.service.default_queuename == 'my-very-own-queue'

    def test_waittime(self):
        assert self.service.waittime == 5
コード例 #3
0
def get_test_system(
    course_id=CourseKey.from_string('/'.join(['org', 'course', 'run'])),
    user=None,
    user_is_staff=False,
    user_location=None,
    render_template=None,
):
    """
    Construct a test ModuleSystem instance.

    By default, the descriptor system's render_template() method simply returns the repr of the
    context it is passed.  You can override this by passing in a different render_template argument.
    """
    if not user:
        user = Mock(name='get_test_system.user', is_staff=False)
    if not user_location:
        user_location = Mock(name='get_test_system.user_location')
    user_service = StubUserService(
        user=user,
        anonymous_user_id='student',
        user_is_staff=user_is_staff,
        user_role='student',
        request_country_code=user_location,
    )

    mako_service = StubMakoService(render_template=render_template)

    replace_url_service = StubReplaceURLService()

    descriptor_system = get_test_descriptor_system()

    def get_module(descriptor):
        """Mocks module_system get_module function"""

        # Unlike XBlock Runtimes or DescriptorSystems,
        # each XModule is provided with a new ModuleSystem.
        # Construct one for the new XModule.
        module_system = get_test_system()

        # Descriptors can all share a single DescriptorSystem.
        # So, bind to the same one as the current descriptor.
        module_system.descriptor_runtime = descriptor._runtime  # pylint: disable=protected-access

        descriptor.bind_for_student(module_system, user.id)

        return descriptor

    return TestModuleSystem(
        static_url='/static',
        track_function=Mock(name='get_test_system.track_function'),
        get_module=get_module,
        debug=True,
        hostname="edx.org",
        services={
            'user': user_service,
            'mako': mako_service,
            'xqueue': XQueueService(
                url='http://xqueue.url',
                django_auth={},
                basic_auth=[],
                default_queuename='testqueue',
                waittime=10,
                construct_callback=Mock(name='get_test_system.xqueue.construct_callback', side_effect="/"),
            ),
            'replace_urls': replace_url_service
        },
        node_path=os.environ.get("NODE_PATH", "/usr/local/lib/node_modules"),
        course_id=course_id,
        error_descriptor_class=ErrorBlock,
        descriptor_runtime=descriptor_system,
    )