e2e: add apply_default_data to load data from migrations after tables have been truncated

This commit is contained in:
Jens Langhammer
2020-06-07 19:30:56 +02:00
parent aa440c17b7
commit fc2eb003ea
11 changed files with 105 additions and 47 deletions

View File

@ -1,38 +1,24 @@
"""test default login flow"""
import string
from random import SystemRandom
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.core.management import call_command
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
from passbook.core.models import User
from e2e.utils import apply_default_data
class TestLogin(StaticLiveServerTestCase):
"""test default login flow"""
host = "0.0.0.0"
port = 8000
host = "passbook"
def setUp(self):
self.driver = webdriver.Remote(
command_executor="http://localhost:4444/wd/hub",
command_executor="http://hub:4444/wd/hub",
desired_capabilities=DesiredCapabilities.CHROME,
)
self.driver.implicitly_wait(2)
self.password = "".join(
SystemRandom().choice(string.ascii_uppercase + string.digits)
for _ in range(8)
)
User.objects.create_superuser(
username="pbadmin", email="admin@example.tld", password=self.password
)
call_command("migrate", "--fake", "passbook_flows", "0001_initial")
call_command("migrate", "passbook_flows", "0002_default_flows")
self.driver.implicitly_wait(5)
apply_default_data()
def tearDown(self):
super().tearDown()
@ -41,12 +27,12 @@ class TestLogin(StaticLiveServerTestCase):
def test_login(self):
"""test default login flow"""
self.driver.get(
f"http://host.docker.internal:{self.port}/flows/default-authentication-flow/?next=%2F"
f"{self.live_server_url}/flows/default-authentication-flow/"
)
self.driver.find_element(By.ID, "id_uid_field").click()
self.driver.find_element(By.ID, "id_uid_field").send_keys("admin@example.tld")
self.driver.find_element(By.ID, "id_uid_field").send_keys("pbadmin")
self.driver.find_element(By.ID, "id_uid_field").send_keys(Keys.ENTER)
self.driver.find_element(By.ID, "id_password").send_keys(self.password)
self.driver.find_element(By.ID, "id_password").send_keys("pbadmin")
self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER)
self.assertEqual(
self.driver.find_element(By.XPATH, "//a[contains(@href, '/-/user/')]").text,