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""" """test OAuth Provider flow"""
from time import sleep from time import sleep
from django.shortcuts import reverse
from oauth2_provider.generators import generate_client_id, generate_client_secret from oauth2_provider.generators import generate_client_id, generate_client_secret
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys 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_ID": self.client_id,
"GF_AUTH_GITHUB_CLIENT_SECRET": self.client_secret, "GF_AUTH_GITHUB_CLIENT_SECRET": self.client_secret,
"GF_AUTH_GITHUB_SCOPES": "user:email,read:org", "GF_AUTH_GITHUB_SCOPES": "user:email,read:org",
"GF_AUTH_GITHUB_AUTH_URL": ( "GF_AUTH_GITHUB_AUTH_URL": self.url(
self.live_server_url "passbook_providers_oauth:github-authorize"
+ reverse("passbook_providers_oauth:github-authorize")
), ),
"GF_AUTH_GITHUB_TOKEN_URL": ( "GF_AUTH_GITHUB_TOKEN_URL": self.url(
self.live_server_url "passbook_providers_oauth:github-access-token"
+ reverse("passbook_providers_oauth:github-access-token")
), ),
"GF_AUTH_GITHUB_API_URL": ( "GF_AUTH_GITHUB_API_URL": self.url(
self.live_server_url "passbook_providers_oauth:github-user"
+ reverse("passbook_providers_oauth:github-user")
), ),
"GF_LOG_LEVEL": "debug", "GF_LOG_LEVEL": "debug",
}, },

View File

@ -1,7 +1,6 @@
"""test SAML Provider flow""" """test SAML Provider flow"""
from time import sleep from time import sleep
from django.shortcuts import reverse
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
@ -43,10 +42,9 @@ class TestProviderSAML(SeleniumTestCase):
"SP_ENTITY_ID": provider.issuer, "SP_ENTITY_ID": provider.issuer,
"SP_SSO_BINDING": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST", "SP_SSO_BINDING": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
"SP_METADATA_URL": ( "SP_METADATA_URL": (
self.live_server_url self.url(
+ reverse(
"passbook_providers_saml:metadata", "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.container = self.setup_client(provider)
self.driver.get( self.driver.get(
self.live_server_url self.url(
+ reverse(
"passbook_providers_saml:sso-init", "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() 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.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.db import connection, transaction from django.db import connection, transaction
from django.db.utils import IntegrityError from django.db.utils import IntegrityError
from django.shortcuts import reverse
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote.webdriver import WebDriver from selenium.webdriver.remote.webdriver import WebDriver
@ -54,6 +55,10 @@ class SeleniumTestCase(StaticLiveServerTestCase):
self.driver.quit() self.driver.quit()
super().tearDown() 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): def apply_default_data(self):
"""apply objects created by migrations after tables have been truncated""" """apply objects created by migrations after tables have been truncated"""
# Find all migration files # Find all migration files