from pathlib import Path
import unittest

ROOT = Path(__file__).resolve().parents[1]


class CompatibilityMetadataTests(unittest.TestCase):
    def test_runtime_source_does_not_import_uwsgi_decorators(self):
        runtime_sources = (ROOT / "oscar_elasticsearch").rglob("*.py")
        imports = [
            source
            for source in runtime_sources
            if "uwsgidecorators" in source.read_text(encoding="utf-8")
        ]
        self.assertEqual(imports, [])

    def test_attribution_and_license_are_shipped_sources(self):
        self.assertTrue((ROOT / "LICENSE").is_file())
        self.assertTrue((ROOT / "NOTICE").is_file())

    def test_metadata_keeps_oscar_odin_on_the_import_compatible_api_line(self):
        setup_source = (ROOT / "setup.py").read_text(encoding="utf-8")
        self.assertIn('"django-oscar-odin>=0.2.2,<0.3"', setup_source)
