Skip to content

Commit

Permalink
Tests for dashboard.vanity.Router (#536)
Browse files Browse the repository at this point in the history
We're now up to 54% test coverage!

Jira: OPS-1443
  • Loading branch information
bheesham authored Nov 4, 2024
1 parent a2d56de commit ec8bd24
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/data/apps.yml
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
53 changes: 53 additions & 0 deletions tests/test_vanity.py
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"

0 comments on commit ec8bd24

Please sign in to comment.