-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: add regression test to check WFs are started properly #37
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
import json | ||
import uuid | ||
|
||
from mock import MagicMock, PropertyMock | ||
from mock import MagicMock, PropertyMock, patch | ||
|
||
import requests_mock | ||
from six.moves.urllib.parse import urlparse | ||
|
@@ -146,6 +146,40 @@ def test_tasks(app, db, halt_workflow, sample_records_uri): | |
assert job.status == JobStatus.ERROR | ||
|
||
|
||
def test_submit_result_starts_a_workflow( | ||
app, | ||
db, | ||
halt_workflow, | ||
sample_records_uri, | ||
sample_records | ||
): | ||
"""Test tasks.""" | ||
job_id = uuid.uuid4().hex # init random value | ||
with app.app_context(): | ||
CrawlerJob.create( | ||
job_id=job_id, | ||
spider="Test", | ||
workflow=halt_workflow.__name__, | ||
logs=None, | ||
results=None, | ||
) | ||
db.session.commit() | ||
|
||
job = CrawlerJob.get_by_job(job_id) | ||
assert job | ||
assert str(job.status) | ||
assert job.status == JobStatus.PENDING | ||
|
||
with patch('inspire_crawler.tasks.start') as mock: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
submit_results( | ||
job_id=job_id, | ||
results_uri=sample_records_uri, | ||
errors=None, | ||
log_file="/foo/bar" | ||
) | ||
mock.apply_async.assert_called() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
|
||
def test_submit_results_with_results_data(app, db, halt_workflow, | ||
sample_records_uri, sample_records): | ||
"""Test submit_results passing the data as payload.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit is not required, pls remove it.
Also, changing the state of the db in a test is bad practice as it affects other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: if you feel proactive you can try to remove the same statement in all other tests and see it was required for the test to pass. My guess is that in most cases, it is not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe that changing the DB state is a bad practice. Not cleaning it, instead, it is.
A proper
tear-down
function is defined in theconfig.py
and run after each test, this ensures the DB consistency for each test. Also, not committing the session won't insert a CrawlerJob in the DB, making these tests fail because they read it from the DB.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure you need to commit, if you are working in the same session. But if you clean up explicitly, it's not too bad.