-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support tests on Scrapyd server with auth enabled (#66)
- Loading branch information
Showing
12 changed files
with
41 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ requests>=2.21.0 | |
setuptools>=40.6.3 | ||
six>=1.12.0 | ||
SQLAlchemy>=1.2.15 | ||
w3lib>=1.17.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
# MUST be updated: _SCRAPYD_SERVER and _SCRAPYD_SERVER_AUTH | ||
custom_settings = dict( | ||
_SCRAPYD_SERVER='127.0.0.1:6800', | ||
_SCRAPYD_SERVER_AUTH=None, # Or ('yourusername', 'yourpassword') | ||
_SCRAPYD_SERVER_AUTH=('admin', '12345'), # Or None | ||
|
||
SCRAPYD_LOGS_DIR='', # For LogParser, defaults to the 'logs' directory that resides in current user directory | ||
|
||
|
@@ -29,7 +29,7 @@ | |
FROM_ADDR=os.environ.get('FROM_ADDR', '[email protected]'), | ||
TO_ADDRS=[os.environ.get('TO_ADDRS', '[email protected]')], | ||
|
||
SMTP_SERVER_='', # Used in tests/test_a_factory.py/test_check_email_with_ssl_false(), e.g. smtp.139.com | ||
SMTP_SERVER_=os.environ.get('SMTP_SERVER_', ''), # Used in test_check_email_with_ssl_false(), e.g. smtp.139.com | ||
SMTP_PORT_=25, | ||
SMTP_OVER_SSL_=False, | ||
SMTP_CONNECTION_TIMEOUT_=10, | ||
|
@@ -45,6 +45,15 @@ | |
|
||
@pytest.fixture | ||
def app(): | ||
fake_server = 'scrapydweb-fake-domain.com:443' | ||
SCRAPYD_SERVERS = [custom_settings['_SCRAPYD_SERVER'], fake_server] | ||
if custom_settings['_SCRAPYD_SERVER_AUTH']: | ||
username, password = custom_settings['_SCRAPYD_SERVER_AUTH'] | ||
authed_server = '%s:%s@%s' % (username, password, custom_settings['_SCRAPYD_SERVER']) | ||
_SCRAPYD_SERVERS = [authed_server, fake_server] | ||
else: | ||
_SCRAPYD_SERVERS = SCRAPYD_SERVERS | ||
|
||
config = dict( | ||
TESTING=True, | ||
# SERVER_NAME='127.0.0.1:5000', # https://flask.pocoo.org/docs/0.12/config/#builtin-configuration-values | ||
|
@@ -55,13 +64,13 @@ def app(): | |
LOGPARSER_PID=0, | ||
POLL_PID=0, | ||
|
||
SCRAPYD_SERVERS=[custom_settings['_SCRAPYD_SERVER'], 'not-exist:6801'], | ||
SCRAPYD_SERVERS=SCRAPYD_SERVERS, | ||
_SCRAPYD_SERVERS=_SCRAPYD_SERVERS, | ||
LOCAL_SCRAPYD_SERVER=custom_settings['_SCRAPYD_SERVER'], | ||
SCRAPYD_SERVERS_AUTHS=[custom_settings['_SCRAPYD_SERVER_AUTH'], ('username', 'password')], | ||
SCRAPYD_SERVERS_GROUPS=['', 'Scrapyd-group'], | ||
SCRAPY_PROJECTS_DIR=os.path.join(cst.CWD, 'data'), | ||
|
||
|
||
ENABLE_LOGPARSER=False, | ||
|
||
EMAIL_WORKING_DAYS=list(range(1, 8)), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,11 @@ def test_check_app_config(app, client): | |
|
||
# In conftest.py: ENABLE_LOGPARSER=False | ||
assert not os.path.exists(app.config['STATS_JSON_PATH']) | ||
|
||
# ['username:[email protected]:6800', ] | ||
app.config['SCRAPYD_SERVERS'] = app.config['_SCRAPYD_SERVERS'] | ||
check_app_config(app.config) | ||
|
||
strings = [] | ||
|
||
assert app.config['LOGPARSER_PID'] is None | ||
|
@@ -59,7 +63,11 @@ def test_check_app_config(app, client): | |
# Test ENABLE_EMAIL = False | ||
if app.config.get('ENABLE_EMAIL', False): | ||
app.config['ENABLE_EMAIL'] = False | ||
|
||
# ['username:[email protected]:6800', ] | ||
app.config['SCRAPYD_SERVERS'] = app.config['_SCRAPYD_SERVERS'] | ||
check_app_config(app.config) | ||
|
||
assert app.config['LOGPARSER_PID'] is None | ||
assert app.config['POLL_PID'] is None | ||
req(app, client, view='settings', kws=dict(node=1), ins='poll_pid: None') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,11 @@ def json_loads_from_file(path): | |
assert not os.path.exists(app.config['DEMO_JSON_PATH']) | ||
app.config['ENABLE_LOGPARSER'] = True | ||
app.config['ENABLE_EMAIL'] = False | ||
|
||
# ['username:[email protected]:6800', ] | ||
app.config['SCRAPYD_SERVERS'] = app.config['_SCRAPYD_SERVERS'] | ||
check_app_config(app.config) | ||
|
||
logparser_pid = app.config['LOGPARSER_PID'] | ||
assert isinstance(logparser_pid, int) and logparser_pid > 0 | ||
assert app.config['POLL_PID'] is None | ||
|