-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom actions via ActionAPI
- Loading branch information
1 parent
d9afa2a
commit a58127a
Showing
18 changed files
with
301 additions
and
186 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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from tests import parametrize | ||
|
||
|
||
def test_action_model_func(user_client, profile): | ||
response = user_client.put(f"/profiles/{profile.pk}/unsubscribe/") | ||
result = response.json() | ||
assert response.status_code == 200, result | ||
profile.refresh_from_db() | ||
assert profile.is_subscribed is False | ||
assert profile.subscribed_at is None | ||
assert profile.subscribed_by is None | ||
|
||
|
||
def test_action_model_func_with_user_argument(user_client, profile, user): | ||
response = user_client.put(f"/profiles/{profile.pk}/subscribe/") | ||
result = response.json() | ||
assert response.status_code == 200, result | ||
profile.refresh_from_db() | ||
assert profile.is_subscribed is True | ||
assert profile.subscribed_at is not None | ||
assert profile.subscribed_by == user | ||
|
||
|
||
def test_action_view_func(user_client, profile, user): | ||
response = user_client.put(f"/profiles/{profile.pk}/resubscribe/") | ||
result = response.json() | ||
assert response.status_code == 200, result | ||
profile.refresh_from_db() | ||
assert profile.is_subscribed is True | ||
assert profile.subscribed_at is not None | ||
assert profile.subscribed_by == user | ||
|
||
|
||
def test_invalid_action(user_client, profile): | ||
response = user_client.put(f"/profiles/{profile.pk}/invalid-action/") | ||
result = response.json() | ||
assert response.status_code == 400, result | ||
assert result["message"] == "Invalid action: invalid-action" | ||
|
||
|
||
def test_invalid_arguments(user_client, profile): | ||
kwargs = dict(text="I love newsletters") | ||
response = user_client.put(f"/profiles/{profile.pk}/subscribe/", kwargs) | ||
result = response.json() | ||
assert response.status_code == 400, result | ||
message = "Invalid arguments: subscribe() got an unexpected keyword argument 'text'" | ||
assert result["message"] == message | ||
|
||
|
||
@parametrize("method", ["GET", "DELETE", "PATCH", "POST"]) | ||
def test_invalid_method(user_client, method, profile): | ||
response = user_client.generic(method, f"/profiles/{profile.pk}/subscribe/") | ||
assert response.status_code == 405 |
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,16 @@ | ||
from tests import parametrize | ||
from worf import exceptions | ||
|
||
|
||
@parametrize( | ||
dict(e=exceptions.ActionError("test")), | ||
dict(e=exceptions.AuthenticationError("test")), | ||
dict(e=exceptions.DataConflict("test")), | ||
dict(e=exceptions.NamingThingsError("test")), | ||
dict(e=exceptions.NotFound("test")), | ||
dict(e=exceptions.PermissionsError("test")), | ||
dict(e=exceptions.SerializerError("test")), | ||
dict(e=exceptions.WorfError("test")), | ||
) | ||
def test_exception(e): | ||
assert e.message == str(e) == "test" |
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
Oops, something went wrong.