e2e: SeleniumTestCase: add url() to reverse into full URL

This commit is contained in:
Jens Langhammer 2020-06-20 23:56:35 +02:00
parent 4285175bba
commit 7e47b64b05
3 changed files with 15 additions and 17 deletions

View file

@ -1,7 +1,6 @@
"""test OAuth Provider flow"""
from time import sleep
from django.shortcuts import reverse
from oauth2_provider.generators import generate_client_id, generate_client_secret
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
@ -43,17 +42,14 @@ class TestProviderOAuth(SeleniumTestCase):
"GF_AUTH_GITHUB_CLIENT_ID": self.client_id,
"GF_AUTH_GITHUB_CLIENT_SECRET": self.client_secret,
"GF_AUTH_GITHUB_SCOPES": "user:email,read:org",
"GF_AUTH_GITHUB_AUTH_URL": (
self.live_server_url
+ reverse("passbook_providers_oauth:github-authorize")
"GF_AUTH_GITHUB_AUTH_URL": self.url(
"passbook_providers_oauth:github-authorize"
),
"GF_AUTH_GITHUB_TOKEN_URL": (
self.live_server_url
+ reverse("passbook_providers_oauth:github-access-token")
"GF_AUTH_GITHUB_TOKEN_URL": self.url(
"passbook_providers_oauth:github-access-token"
),
"GF_AUTH_GITHUB_API_URL": (
self.live_server_url
+ reverse("passbook_providers_oauth:github-user")
"GF_AUTH_GITHUB_API_URL": self.url(
"passbook_providers_oauth:github-user"
),
"GF_LOG_LEVEL": "debug",
},

View file

@ -1,7 +1,6 @@
"""test SAML Provider flow"""
from time import sleep
from django.shortcuts import reverse
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
@ -43,10 +42,9 @@ class TestProviderSAML(SeleniumTestCase):
"SP_ENTITY_ID": provider.issuer,
"SP_SSO_BINDING": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
"SP_METADATA_URL": (
self.live_server_url
+ reverse(
self.url(
"passbook_providers_saml:metadata",
kwargs={"application_slug": provider.application.slug},
application_slug=provider.application.slug,
)
),
},
@ -158,10 +156,9 @@ class TestProviderSAML(SeleniumTestCase):
)
self.container = self.setup_client(provider)
self.driver.get(
self.live_server_url
+ reverse(
self.url(
"passbook_providers_saml:sso-init",
kwargs={"application_slug": provider.application.slug},
application_slug=provider.application.slug,
)
)
self.driver.find_element(By.ID, "id_uid_field").click()

View file

@ -9,6 +9,7 @@ from django.apps import apps
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.db import connection, transaction
from django.db.utils import IntegrityError
from django.shortcuts import reverse
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote.webdriver import WebDriver
@ -54,6 +55,10 @@ class SeleniumTestCase(StaticLiveServerTestCase):
self.driver.quit()
super().tearDown()
def url(self, view, **kwargs) -> str:
"""reverse `view` with `**kwargs` into full URL using live_server_url"""
return self.live_server_url + reverse(view, kwargs=kwargs)
def apply_default_data(self):
"""apply objects created by migrations after tables have been truncated"""
# Find all migration files