コード例 #1
0
    def test_env_variables(self, resauth_mock):
        # Ensure environmental variables are not set.
        os.environ.pop('RESOLWE_API_HOST', None)
        os.environ.pop('RESOLWE_API_USERNAME', None)
        os.environ.pop('RESOLWE_API_PASSWORD', None)

        # Default URL should be used by default.
        resolwe_api = Resolwe()
        self.assertEqual(resolwe_api.url, 'http://localhost:8000')
        self.assertEqual(resauth_mock.call_args[0][0], None)
        self.assertEqual(resauth_mock.call_args[0][1], None)

        # If environment variable is set, it overrides the default URL.
        os.environ['RESOLWE_API_USERNAME'] = '******'
        os.environ['RESOLWE_API_PASSWORD'] = '******'

        os.environ['RESOLWE_HOST_URL'] = 'http://resolwe-api:8000'
        resolwe_api = Resolwe()
        self.assertEqual(resolwe_api.url, 'http://resolwe-api:8000')
        self.assertEqual(resauth_mock.call_args[0][0], 'foo')
        self.assertEqual(resauth_mock.call_args[0][1], 'bar')

        # `RESOLWE_HOST_URL` takes precedence
        os.environ['RESOLWE_API_HOST'] = 'http://resolwe-api:9000'
        resolwe_api = Resolwe()
        self.assertEqual(resolwe_api.url, 'http://resolwe-api:8000')
        self.assertEqual(resauth_mock.call_args[0][0], 'foo')
        self.assertEqual(resauth_mock.call_args[0][1], 'bar')

        os.environ.pop('RESOLWE_HOST_URL')
        resolwe_api = Resolwe()
        self.assertEqual(resolwe_api.url, 'http://resolwe-api:9000')
        self.assertEqual(resauth_mock.call_args[0][0], 'foo')
        self.assertEqual(resauth_mock.call_args[0][1], 'bar')
コード例 #2
0
    def __init__(self):
        self.url = environ.get('RESOLWE_HOST_URL', DEFAULT_URL)
        self.username = environ.get('RESOLWE_API_USERNAME', DEFAULT_USERNAME)
        self.password = environ.get('RESOLWE_API_PASSWORD', DEFAULT_PASSWORD)

        try:
            self.res = Resolwe(self.username, self.password, self.url)
        except Exception:
            # TODO: raise proper exceptions and handle in GUI
            raise
コード例 #3
0
    def test_env_variables(self, resauth_mock, requests_mock):
        # Ensure environmental variables are not set.
        os.environ.pop("RESOLWE_HOST_URL", None)
        os.environ.pop("RESOLWE_API_USERNAME", None)
        os.environ.pop("RESOLWE_API_PASSWORD", None)

        # Default URL should be used by default.
        resolwe_api = Resolwe()
        self.assertEqual(resolwe_api.url, "http://localhost:8000")
        self.assertEqual(resauth_mock.call_args[0][0], None)
        self.assertEqual(resauth_mock.call_args[0][1], None)

        # If environment variable is set, it overrides the default URL.
        os.environ["RESOLWE_API_USERNAME"] = "******"
        os.environ["RESOLWE_API_PASSWORD"] = "******"
        os.environ["RESOLWE_HOST_URL"] = "http://resolwe-api:8000"
        resolwe_api = Resolwe()
        self.assertEqual(resolwe_api.url, "http://resolwe-api:8000")
        self.assertEqual(resauth_mock.call_args[0][0], "foo")
        self.assertEqual(resauth_mock.call_args[0][1], "bar")