-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working towards pushing more validation into the BLL, it means our test users to be more accurate and more customisable in tests. The existing `client_with_permissions` and `client_with_user` fixtures don't work as well with this model, because as our permissions model has developped, what does with_permission mean? This change refactors away those fixtures, and replaces it with a `airlock_client` fixture that is more like normal django client in usage. It overrides the login method, so you can call `airlock_client.login(...)` or `airlock_client.login_with_user(...)`, just as you do with a normal client. Under the hood, this uses the new factories.create_user, giving us all the same conveniences. I think this makes test setup still simple, but more explicit.
- Loading branch information
1 parent
5cd90a4
commit 435a103
Showing
5 changed files
with
218 additions
and
209 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
import pytest | ||
from django.test import Client | ||
|
||
from tests import factories | ||
|
||
|
||
@pytest.fixture | ||
def client_with_user(client): | ||
def _client(session_user): | ||
session_user.setdefault("username", "test") | ||
user = factories.create_user(**session_user) | ||
session = client.session | ||
class AirlockClient(Client): | ||
def login(self, username="testuser", workspaces={}, output_checker=False): | ||
user = factories.create_user(username, workspaces, output_checker) | ||
self.login_with_user(user) | ||
|
||
def login_with_user(self, user): | ||
session = self.session | ||
session["user"] = user.to_dict() | ||
session.save() | ||
client.user = user | ||
return client | ||
|
||
return _client | ||
self.user = user | ||
|
||
|
||
@pytest.fixture | ||
def client_with_permission(client_with_user): | ||
output_checker = {"output_checker": True} | ||
yield client_with_user(output_checker) | ||
def airlock_client(): | ||
return AirlockClient() |
Oops, something went wrong.