-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use django URL names in test suite (#730)
* namespaces urls by app * refactor urls patterns and test for wasteline views * refactor core app tests to use named urls * refactor rcrasite urls to use named urls remove 'rcra' from our REST API endpoint URLs * refactor profile app endpoints to use namespaces and named endpoints * refactor manifest app to use namespaces and named endpoints * refactor org app to use namespaces and named endpoints * refactor site app to use namespaces and named endpoints
- Loading branch information
1 parent
e57bb47
commit 174b161
Showing
29 changed files
with
334 additions
and
210 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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
from django.test.client import Client | ||
from rest_framework import status | ||
from rest_framework.reverse import reverse | ||
from rest_framework.test import APIRequestFactory, force_authenticate | ||
|
||
from apps.core.views import LaunchExampleTaskView, TaskStatusView | ||
|
||
|
||
class TestUserViews: | ||
@pytest.fixture | ||
def factory(self): | ||
return APIRequestFactory() | ||
|
||
@pytest.fixture | ||
def user(self, user_factory): | ||
return user_factory() | ||
|
||
def test_returns_user_details(self, factory, user): | ||
c = Client() | ||
c.force_login(user) | ||
response = c.get(reverse("core:user:details")) | ||
data: dict = response.json() | ||
assert response.status_code == 200 | ||
assert user.username in data.values() | ||
assert user.first_name in data.values() | ||
|
||
|
||
class TestLaunchExampleTaskView: | ||
@pytest.fixture | ||
def factory(self): | ||
return APIRequestFactory() | ||
|
||
def test_successful_launch(self, factory): | ||
with mock.patch("apps.core.views.launch_example_task") as mock_task: | ||
request = factory.get(reverse("core:task:example")) | ||
mock_task.return_value = "123" | ||
response = LaunchExampleTaskView.as_view()(request) | ||
assert response.status_code == status.HTTP_200_OK | ||
assert response.data == {"taskId": "123"} | ||
|
||
|
||
class TestTaskStatusView: | ||
@pytest.fixture | ||
def factory(self): | ||
return APIRequestFactory() | ||
|
||
def test_successful_get_status(self, factory, user_factory): | ||
user = user_factory() | ||
task_id = "123" | ||
request = factory.get(reverse("core:task:status", args=[task_id])) | ||
force_authenticate(request, user) | ||
with mock.patch("apps.core.views.get_task_status") as mock_task: | ||
mock_task.return_value = { | ||
"status": "PENDING", | ||
"name": "task_name", | ||
"result": None, | ||
"taskId": task_id, | ||
} | ||
response = TaskStatusView.as_view()(request, task_id=task_id) | ||
assert response.status_code == status.HTTP_200_OK | ||
assert "PENDING" in response.data.values() |
Oops, something went wrong.