-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created initial selenium testing framework with pylenium. Added test …
…for user login (#2216) * Created initial selenium testing framework with pylenium. Added test for user login * Restoring precommit hook
- Loading branch information
1 parent
ca3e457
commit e921af0
Showing
9 changed files
with
2,120 additions
and
450 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,60 @@ | ||
import json | ||
from logging import getLogger | ||
from secrets import token_hex | ||
|
||
from django.conf import settings | ||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase | ||
from django.urls import reverse | ||
from pylenium.config import PyleniumConfig | ||
from pylenium.driver import Pylenium | ||
|
||
from .utils import CreateTestUsers | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
class SeleniumTests(CreateTestUsers, StaticLiveServerTestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
try: | ||
with open(settings.PYLENIUM_CONFIG) as file: | ||
_json = json.load(file) | ||
config = PyleniumConfig(**_json) | ||
except FileNotFoundError: | ||
logger.warning( | ||
"settings.PYLENIUM_CONFIG (%s) was not found; using defaults.", | ||
settings.PYLENIUM_CONFIG, | ||
) | ||
config = PyleniumConfig() | ||
|
||
cls.py = Pylenium(config) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
cls.py.quit() | ||
super().tearDownClass() | ||
|
||
def reverse(self, name): | ||
return f"{self.live_server_url}{reverse(name)}" | ||
|
||
def test_login(self): | ||
self.py.visit(self.reverse("registration_login")) | ||
self.py.get("[name='username']").type(token_hex(8)) | ||
self.py.get("[name='password']").type(token_hex(24)) | ||
self.py.get("button#login").click() | ||
self.assertTrue( | ||
self.py.should().have_url(f"{self.live_server_url}/account/login/") | ||
) | ||
self.assertTrue( | ||
self.py.get("form#login-form") | ||
.should() | ||
.contain_text("Please enter a correct username and password") | ||
) | ||
|
||
user = self.create_user("login-test") | ||
self.py.visit(self.reverse("registration_login")) | ||
self.py.get("[name='username']").type(user.username) | ||
self.py.get("[name='password']").type(user._password) | ||
self.py.get("button#login").click() | ||
self.assertTrue(self.py.should().have_url(f"{self.live_server_url}/")) |
Oops, something went wrong.