mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 02:54:26 +00:00
patch.py located files/ruby/ relative to its own __file__. That holds in the repo, where the script sits next to the fragments, but the image copies the script to /tmp/patch.py and the fragments to /tmp/ruby/, so parent.parent resolved to / and the build died with FileNotFoundError: /ruby/omniauth_provider.rb on every retry. DECIDIM_PATCH_RUBY_DOCKER already decides where the COPY puts the fragments. Reading it in the script makes that variable the only place the location is stated, so the layout can change without a second place silently disagreeing. Missing variable raises instead of guessing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
"""Unit tests for roles/web-app-decidim/files/python/patch.py."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
import unittest
|
|
|
|
from . import PROJECT_ROOT
|
|
|
|
sys.path.insert(0, str(PROJECT_ROOT / "roles" / "web-app-decidim" / "files" / "python"))
|
|
|
|
from patch import patch_omniauth_helper_rb, patch_omniauth_rb
|
|
|
|
os.environ["DECIDIM_PATCH_RUBY_DOCKER"] = str(
|
|
PROJECT_ROOT / "roles" / "web-app-decidim" / "files" / "ruby"
|
|
)
|
|
|
|
OMNIAUTH_RB_FIXTURE = """\
|
|
Decidim::Auth.setup do |config|
|
|
config.providers = []
|
|
end
|
|
end
|
|
"""
|
|
|
|
OMNIAUTH_HELPER_FIXTURE = """\
|
|
module Decidim
|
|
module OmniauthHelper
|
|
def oauth_icon(provider)
|
|
info = current_organization.enabled_omniauth_providers[provider.to_sym]
|
|
end
|
|
end
|
|
end
|
|
"""
|
|
|
|
|
|
class TestPatchOmniauthRb(unittest.TestCase):
|
|
def test_inserts_env_gated_provider(self):
|
|
result = patch_omniauth_rb(OMNIAUTH_RB_FIXTURE)
|
|
self.assertIn('ENV["OIDC_ENABLED"].to_s == "true"', result)
|
|
self.assertIn("omniauth_openid_connect", result)
|
|
self.assertIn("redirect_uri", result)
|
|
|
|
def test_registers_provider_in_decidim_registry(self):
|
|
result = patch_omniauth_rb(OMNIAUTH_RB_FIXTURE)
|
|
self.assertIn("Decidim.omniauth_providers[:openid_connect]", result)
|
|
registry_idx = result.index("Decidim.omniauth_providers[:openid_connect]")
|
|
builder_idx = result.index("Decidim::Auth.setup")
|
|
self.assertLess(registry_idx, builder_idx)
|
|
|
|
def test_closes_correctly(self):
|
|
result = patch_omniauth_rb(OMNIAUTH_RB_FIXTURE)
|
|
self.assertTrue(result.rstrip().endswith("end"))
|
|
|
|
def test_is_idempotent(self):
|
|
once = patch_omniauth_rb(OMNIAUTH_RB_FIXTURE)
|
|
twice = patch_omniauth_rb(once)
|
|
self.assertEqual(once, twice)
|
|
|
|
|
|
class TestPatchOmniauthHelperRb(unittest.TestCase):
|
|
def test_adds_early_return(self):
|
|
result = patch_omniauth_helper_rb(OMNIAUTH_HELPER_FIXTURE)
|
|
self.assertIn(
|
|
'return icon("login-box-line") if provider.to_sym == :openid_connect',
|
|
result,
|
|
)
|
|
|
|
def test_preserves_original_method(self):
|
|
result = patch_omniauth_helper_rb(OMNIAUTH_HELPER_FIXTURE)
|
|
self.assertIn("current_organization.enabled_omniauth_providers", result)
|
|
|
|
def test_is_idempotent(self):
|
|
once = patch_omniauth_helper_rb(OMNIAUTH_HELPER_FIXTURE)
|
|
twice = patch_omniauth_helper_rb(once)
|
|
self.assertEqual(once, twice)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|