-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for dashboard.vanity.Router (#536)
We're now up to 54% test coverage! Jira: OPS-1443
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copied a snapshot from https://github.com/mozilla-iam/sso-dashboard-configuration/ | ||
apps: | ||
- application: | ||
authorized_groups: | ||
- mozilliansorg_netlify-access | ||
authorized_users: [] | ||
client_id: client-id-for-netlify | ||
display: true | ||
logo: netlify.png | ||
name: Netlify | ||
op: auth0 | ||
url: https://some-url-for-netlify | ||
vanity_url: | ||
- /netlify | ||
- application: | ||
authorized_groups: | ||
- team_moco | ||
- team_mofo | ||
- team_mzla | ||
authorized_users: [] | ||
display: true | ||
logo: accountmanager.png | ||
name: Account Portal | ||
op: auth0 | ||
url: https://some-url-for-account-manager | ||
vanity_url: | ||
- /accountmanager | ||
- application: | ||
authorized_groups: | ||
- mozilliansorg_acoustic_production_access | ||
authorized_users: [] | ||
client_id: client-id-for-acoustic | ||
display: true | ||
logo: acoustic.png | ||
name: Acoustic | ||
op: auth0 | ||
url: https://some-url-for-acoustic | ||
vanity_url: | ||
- /acoustic |
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,53 @@ | ||
from pathlib import Path | ||
import pytest | ||
from flask import Flask | ||
from dashboard import config | ||
from dashboard import vanity | ||
from dashboard.models import tile | ||
from dashboard.op import yaml_loader | ||
|
||
|
||
@pytest.fixture | ||
def externals(monkeypatch): | ||
# Internal to the way dashboard.models.tile.CDNTransfer works. | ||
models_dir = Path(__file__).parent / "models" | ||
monkeypatch.setattr("os.path.dirname", lambda _: models_dir) | ||
# Internal to how Configs work. | ||
monkeypatch.setenv("SSO-DASHBOARD_REDIS_CONNECTOR", "foobar") | ||
monkeypatch.setenv("SSO-DASHBOARD_SECRET_KEY", "deadbeef") | ||
monkeypatch.setenv("SSO-DASHBOARD_S3_BUCKET", "") | ||
monkeypatch.setenv("SSO-DASHBOARD_FORBIDDEN_PAGE_PUBLIC_KEY", "") | ||
monkeypatch.setenv("SSO-DASHBOARD_CDN", "https://localhost") | ||
|
||
|
||
@pytest.fixture | ||
def app_config(externals): | ||
return config.Default() | ||
|
||
|
||
@pytest.fixture | ||
def dashboard_app(app_config): | ||
""" | ||
A mini instance of the app. | ||
""" | ||
app = Flask("dashboard") | ||
app.config.from_object(app_config) | ||
yield app | ||
|
||
|
||
@pytest.fixture | ||
def cdn(app_config): | ||
return tile.CDNTransfer(app_config) | ||
|
||
|
||
@pytest.fixture | ||
def client(dashboard_app): | ||
return dashboard_app.test_client() | ||
|
||
|
||
class TestVanity: | ||
def test_router(self, dashboard_app, cdn, client): | ||
router = vanity.Router(dashboard_app, cdn) | ||
router.setup() | ||
response = client.get("/netlify") | ||
assert response.location == "https://some-url-for-netlify", "Did not properly redirect vanity URL" |