diff --git a/tests/mockserver.py b/tests/mockserver.py index 43378b1c..0bf56cc9 100644 --- a/tests/mockserver.py +++ b/tests/mockserver.py @@ -18,14 +18,14 @@ def get_ephemeral_port(): class MockScrapydServer: - def __init__(self, authentication=None): - self.authentication = authentication + def __init__(self, username=None, password=None): + self.username = username + self.password = password - def __enter__(self, authentication=None): - """Launch Scrapyd application object with ephemeral port""" + def __enter__(self): command = [sys.executable, os.path.join(BASEDIR, "start_mock_app.py"), get_ephemeral_port()] - if self.authentication is not None: - command.append("--auth=" + self.authentication) + if self.username and self.password: + command.extend([f"--username={self.username}", f"--password={self.password}"]) self.process = Popen(command, stdout=PIPE) diff --git a/tests/start_mock_app.py b/tests/start_mock_app.py index 61f1636c..01e9ad20 100644 --- a/tests/start_mock_app.py +++ b/tests/start_mock_app.py @@ -8,27 +8,23 @@ from scrapyd import Config from scrapyd.app import application - -def _get_config(args): - scrapyd_config = Config() - section = "scrapyd" - scrapyd_config.cp.set(section, "http_port", args.http_port) - - if args.auth is not None: - username, password = args.auth.split(":") - scrapyd_config.cp.set(section, "username", username) - scrapyd_config.cp.set(section, "password", password) - - return scrapyd_config - - if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("http_port", default=6800) - parser.add_argument("--auth", default=None) + parser.add_argument("http_port") + parser.add_argument("--username") + parser.add_argument("--password") + args = parser.parse_args() + + config = Config() + config.cp.set(Config.SECTION, "http_port", args.http_port) + if args.username and args.password: + config.cp.set(Config.SECTION, "username", args.username) + config.cp.set(Config.SECTION, "password", args.password) + log.startLogging(sys.stdout) - conf = _get_config(args) - application = application(config=conf) + + application = application(config=config) app.startApplication(application, save=False) + reactor.run() diff --git a/tests/test_eggstorage.py b/tests/test_eggstorage.py index 86fa315c..cd6efeb8 100644 --- a/tests/test_eggstorage.py +++ b/tests/test_eggstorage.py @@ -44,6 +44,7 @@ def eggstorage(tmpdir): [ (["zzz", "b", "ddd", "a", "x"], ["a", "b", "ddd", "x", "zzz"]), (["10", "1", "9"], ["1", "9", "10"]), + (["r10", "r1", "r9"], ["r1", "r10", "r9"]), (["2.11", "2.01", "2.9"], ["2.01", "2.9", "2.11"]), ], ) diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index 8cbdeffb..d073c67c 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -34,7 +34,7 @@ def _deploy(mock_scrapyd, quotesbot_egg) -> Response: def test_urljoin(mock_scrapyd): - assert mock_scrapyd.urljoin("foo") == mock_scrapyd.url + "foo" + assert mock_scrapyd.urljoin("foo") == f"{mock_scrapyd.url}foo" def test_root(mock_scrapyd): @@ -47,7 +47,7 @@ def test_root(mock_scrapyd): def test_auth(): username, password = "Leonardo", "hunter2" - with MockScrapydServer(authentication=username + ":" + password) as server: + with MockScrapydServer(username=username, password=password) as server: assert requests.get(server.url).status_code == 401 res = requests.get(server.url, auth=(username, password))