This repository has been archived by the owner on Mar 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for worker hooks hook api
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import json | ||
|
||
from api import API_URL, AUTH | ||
from mock import patch, Mock | ||
from hooks.hook_api import send_score, run | ||
|
||
|
||
class TestSendScore(): | ||
def test_send(self): | ||
project_score_id = 2 | ||
score_attribute_id = 3 | ||
result = "4" | ||
payload = { | ||
"score_attribute": score_attribute_id, | ||
"project_score": project_score_id, | ||
"score_value": None, | ||
"result": json.dumps(result) | ||
} | ||
mock_requests = Mock() | ||
with patch("hooks.hook_api.requests", mock_requests): | ||
send_score(score_attribute_id, project_score_id, result) | ||
mock_requests.post.assert_called_with( | ||
"{0}project-score-attributes/".format(API_URL), | ||
data=payload, | ||
auth=AUTH | ||
) | ||
|
||
|
||
class TestRun(): | ||
def test_no_project_score_id(self): | ||
project = {} | ||
result = [] | ||
assert run(project, result) is None | ||
|
||
def test_send_score_skipped(self): | ||
project_score_id = 1 | ||
project = {"project_score_id": project_score_id} | ||
score_attrib_slug = "slug" | ||
value = None | ||
result = {"value": value, 'name': score_attrib_slug} | ||
score_attrib_id = 3 | ||
mock_get_score_attribute = Mock(return_value={"id": score_attrib_id}) | ||
mock_send_score = Mock() | ||
with patch("hooks.hook_api.get_score_attribute", | ||
mock_get_score_attribute): | ||
with patch("hooks.hook_api.send_score", mock_send_score): | ||
assert run(project, result) == result | ||
mock_get_score_attribute.assert_called_with(score_attrib_slug) | ||
mock_send_score.call_count == 0 | ||
|
||
def test_run(self): | ||
project_score_id = 1 | ||
project = {"project_score_id": project_score_id} | ||
score_attrib_slug = "slug" | ||
value = True | ||
result = {"value": value, 'name': score_attrib_slug} | ||
score_attrib_id = 3 | ||
mock_get_score_attribute = Mock(return_value={"id": score_attrib_id}) | ||
mock_send_score = Mock() | ||
with patch("hooks.hook_api.get_score_attribute", | ||
mock_get_score_attribute): | ||
with patch("hooks.hook_api.send_score", mock_send_score): | ||
r = run(project, result) | ||
result.update(project_score_attribute_id=score_attrib_id) | ||
assert r == result | ||
mock_get_score_attribute.assert_called_with(score_attrib_slug) | ||
mock_send_score.assert_called_with(score_attrib_id, | ||
project_score_id, value) |