Пример #1
0
def with_resolwe_host(wrapped_method, instance, args, kwargs):
    """Decorate unit test to give it access to a live Resolwe host.

    Set ``RESOLWE_HOST_URL`` setting to the address where the testing
    live Resolwe host listens to.

    .. note::

        This decorator must be used with a (sub)class of
        :class:`~django.test.LiveServerTestCase` which starts a live
        Django server in the background.

    """
    from resolwe.flow.managers import manager  # To prevent circular imports.

    if not hasattr(instance, 'server_thread'):
        raise AttributeError(
            "with_resolwe_host decorator must be used with a "
            "(sub)class of LiveServerTestCase that has the "
            "'server_thread' attribute"
        )
    resolwe_host_url = 'http://{host}:{port}'.format(
        host=instance.server_thread.host, port=instance.server_thread.port)
    with override_settings(RESOLWE_HOST_URL=resolwe_host_url):
        with manager.override_settings(RESOLWE_HOST_URL=resolwe_host_url):
            # Run the actual unit test method.
            return with_custom_executor(NETWORK='host')(wrapped_method)(*args, **kwargs)
Пример #2
0
def with_resolwe_host(wrapped_method, instance, args, kwargs):
    """Decorate unit test to give it access to a live Resolwe host.

    Set ``RESOLWE_HOST_URL`` setting to the address where the testing
    live Resolwe host listens to.

    .. note::

        This decorator must be used with a (sub)class of
        :class:`~django.test.LiveServerTestCase` which starts a live
        Django server in the background.

    """
    from resolwe.flow.managers import manager  # To prevent circular imports.

    if not hasattr(instance, "server_thread"):
        raise AttributeError("with_resolwe_host decorator must be used with a "
                             "(sub)class of LiveServerTestCase that has the "
                             "'server_thread' attribute")
    host = instance.server_thread.host
    if platform not in ["linux", "linux2"]:
        host = "host.docker.internal"
    resolwe_host_url = "http://{host}:{port}".format(
        host=host, port=instance.server_thread.port)
    with override_settings(RESOLWE_HOST_URL=resolwe_host_url):
        with manager.override_settings(RESOLWE_HOST_URL=resolwe_host_url):
            # Run the actual unit test method.
            return with_custom_executor(NETWORK="host")(wrapped_method)(
                *args, **kwargs)
Пример #3
0
    def test_envvars(self):
        flow_executor = copy.copy(getattr(settings, "FLOW_EXECUTOR", {}))
        flow_executor["SET_ENV"] = {
            "SET_ENV_TEST": "test_var",
        }

        with manager.override_settings(FLOW_EXECUTOR=flow_executor,
                                       RESOLWE_HOST_URL="some.special.host"):
            process = Process.objects.create(
                name="Test environment variables",
                requirements={"expression-engine": "jinja"},
                contributor=self.contributor,
                type="test:data:envvars:",
                input_schema=[],
                output_schema=[
                    {
                        "name": "resolweapihost",
                        "type": "basic:string:"
                    },
                    {
                        "name": "setenvtest",
                        "type": "basic:string:"
                    },
                    {
                        "name": "tmpdir",
                        "type": "basic:string:"
                    },
                ],
                run={
                    "language":
                    "bash",
                    "program":
                    """
re-save resolweapihost $RESOLWE_HOST_URL
re-save setenvtest $SET_ENV_TEST
re-save tmpdir $TMPDIR
""",
                },
            )

            data = Data.objects.create(
                name="Data object",
                contributor=self.contributor,
                process=process,
                input={},
            )

            # update output
            data = Data.objects.get(pk=data.pk)

            self.assertEqual(data.output["resolweapihost"],
                             "some.special.host")
            self.assertEqual(data.output["setenvtest"], "test_var")
            self.assertEqual(data.output["tmpdir"], "/data/.tmp")
Пример #4
0
    def test_envvars(self):
        flow_executor = copy.copy(getattr(settings, 'FLOW_EXECUTOR', {}))
        flow_executor['SET_ENV'] = {
            'SET_ENV_TEST': 'test_var',
        }

        with manager.override_settings(FLOW_EXECUTOR=flow_executor,
                                       RESOLWE_HOST_URL='some.special.host'):
            process = Process.objects.create(
                name='Test environment variables',
                requirements={'expression-engine': 'jinja'},
                contributor=self.contributor,
                type='test:data:envvars:',
                input_schema=[],
                output_schema=[
                    {
                        'name': 'resolweapihost',
                        'type': 'basic:string:'
                    },
                    {
                        'name': 'setenvtest',
                        'type': 'basic:string:'
                    },
                    {
                        'name': 'tmpdir',
                        'type': 'basic:string:'
                    },
                ],
                run={
                    'language':
                    'bash',
                    'program':
                    """
re-save resolweapihost $RESOLWE_HOST_URL
re-save setenvtest $SET_ENV_TEST
re-save tmpdir $TMPDIR
"""
                })

            data = Data.objects.create(
                name='Data object',
                contributor=self.contributor,
                process=process,
                input={},
            )

            # update output
            data = Data.objects.get(pk=data.pk)

            self.assertEqual(data.output['resolweapihost'],
                             'some.special.host')
            self.assertEqual(data.output['setenvtest'], 'test_var')
            self.assertEqual(data.output['tmpdir'], '/data/.tmp')
Пример #5
0
    def wrapper(wrapped_method, instance, args, kwargs):
        executor_settings = settings.FLOW_EXECUTOR.copy()
        executor_settings.update(custom_executor_settings)

        try:
            with override_settings(FLOW_EXECUTOR=executor_settings):
                with manager.override_settings(
                        FLOW_EXECUTOR=executor_settings):
                    # Re-run engine discovery as the settings have changed.
                    manager.discover_engines()

                    # Re-run the post_register_hook
                    manager.get_executor().post_register_hook()

                    # Run the actual unit test method.
                    return wrapped_method(*args, **kwargs)
        finally:
            # Re-run engine discovery as the settings have changed.
            manager.discover_engines()
Пример #6
0
    def wrapper(wrapped_method, instance, args, kwargs):
        from resolwe.flow.managers import manager  # To prevent circular imports.

        executor_settings = settings.FLOW_EXECUTOR.copy()
        executor_settings.update(custom_executor_settings)

        try:
            with override_settings(FLOW_EXECUTOR=executor_settings):
                with manager.override_settings(FLOW_EXECUTOR=executor_settings):
                    # Re-run engine discovery as the settings have changed.
                    manager.discover_engines()

                    # Re-run the post_register_hook
                    manager.get_executor().post_register_hook(verbosity=0)

                    # Run the actual unit test method.
                    return wrapped_method(*args, **kwargs)
        finally:
            # Re-run engine discovery as the settings have changed.
            manager.discover_engines()
Пример #7
0
    def wrapper(wrapped_method, instance, args, kwargs):
        from resolwe.flow.managers import manager  # To prevent circular imports.

        executor_settings = settings.FLOW_EXECUTOR.copy()
        executor_settings.update(custom_executor_settings)

        try:
            with override_settings(FLOW_EXECUTOR=executor_settings):
                with manager.override_settings(FLOW_EXECUTOR=executor_settings):
                    # Re-run engine discovery as the settings have changed.
                    manager.discover_engines()

                    # Re-run the post_register_hook
                    manager.get_executor().post_register_hook(verbosity=0)

                    # Run the actual unit test method.
                    return wrapped_method(*args, **kwargs)
        finally:
            # Re-run engine discovery as the settings have changed.
            manager.discover_engines()
Пример #8
0
    def test_envvars(self):
        flow_executor = copy.copy(getattr(settings, 'FLOW_EXECUTOR', {}))
        flow_executor['SET_ENV'] = {
            'SET_ENV_TEST': 'test_var',
        }

        with manager.override_settings(FLOW_EXECUTOR=flow_executor, RESOLWE_HOST_URL='some.special.host'):
            process = Process.objects.create(
                name='Test environment variables',
                requirements={'expression-engine': 'jinja'},
                contributor=self.contributor,
                type='test:data:envvars:',
                input_schema=[],
                output_schema=[
                    {'name': 'resolweapihost', 'type': 'basic:string:'},
                    {'name': 'setenvtest', 'type': 'basic:string:'},
                    {'name': 'tmpdir', 'type': 'basic:string:'},
                ],
                run={
                    'language': 'bash',
                    'program': """
re-save resolweapihost $RESOLWE_HOST_URL
re-save setenvtest $SET_ENV_TEST
re-save tmpdir $TMPDIR
"""
                }
            )

            data = Data.objects.create(
                name='Data object',
                contributor=self.contributor,
                process=process,
                input={},
            )

            # update output
            data = Data.objects.get(pk=data.pk)

            self.assertEqual(data.output['resolweapihost'], 'some.special.host')
            self.assertEqual(data.output['setenvtest'], 'test_var')
            self.assertEqual(data.output['tmpdir'], '/data/.tmp')
Пример #9
0
def with_resolwe_host(wrapped_method, instance, args, kwargs):
    """Decorate unit test to give it access to a live Resolwe host.

    Set ``RESOLWE_HOST_URL`` setting to the address where the testing
    live Resolwe host listens to.

    .. note::

        This decorator must be used with a (sub)class of
        :class:`~django.test.LiveServerTestCase` which starts a live
        Django server in the background.

    """
    if not hasattr(instance, 'server_thread'):
        raise AttributeError("with_resolwe_host decorator must be used with a "
                             "(sub)class of LiveServerTestCase that has the "
                             "'server_thread' attribute")
    resolwe_host_url = 'http://{host}:{port}'.format(
        host=instance.server_thread.host, port=instance.server_thread.port)
    with override_settings(RESOLWE_HOST_URL=resolwe_host_url):
        with manager.override_settings(RESOLWE_HOST_URL=resolwe_host_url):
            # Run the actual unit test method.
            return with_custom_executor(NETWORK='host')(wrapped_method)(
                *args, **kwargs)