コード例 #1
0
def test_defaults(key, expected):
    """Test if defaults are properly propagated to app config"""
    class ConfClass:
        SECRET_KEY = "secret"

    app = Flask('test_app')
    app.config.from_object(ConfClass)
    conf = Config(ConfClass)
    conf.set_app_defaults(app)

    assert app.config[key] == expected, "failed for key '{}'".format(key)
コード例 #2
0
def test_greenwave_invalid(conf):
    """Test if invalid config is properly reported"""
    class ConfClass(DefaultConfig):
        GREENWAVE = conf

    with pytest.raises(ValueError):
        conf = Config(ConfClass)
コード例 #3
0
def test_organizations_invalid(conf):
    """Test if invalid config is properly reported"""
    class ConfClass(DefaultConfig):
        ORGANIZATIONS = conf

    with pytest.raises(ValueError):
        Config(ConfClass)
コード例 #4
0
def mocked_koji():
    """Return mocked KojiUtil with session"""
    conf = Config(TestConfig)
    ku = KojiUtil()
    ku.initialize(conf)
    ku._session = flexmock()
    return ku
コード例 #5
0
def test_log_level_invalid(value):
    """Test of setting invalid log level"""
    class ConfClass(DefaultConfig):
        LOG_LEVEL = value

    with pytest.raises(ValueError):
        Config(ConfClass)
コード例 #6
0
def test_zipfile_max_uncompressed_size_invalid():
    """Test of setting invalid zipfile_max_uncompressed_size"""
    class ConfClass(DefaultConfig):
        ZIPFILE_MAX_UNCOMPRESSED_SIZE = -10

    with pytest.raises(ValueError):
        Config(ConfClass)
コード例 #7
0
    def test_getting_configured_org(self):
        """Test of getting organization instance when org is configured"""
        class ConfClass:
            ORGANIZATIONS = {
                'private_org': {
                    # 'public': False, # Default
                    'oauth_token': 'something',
                },
                'public_org': {
                    'public': True,
                    'oauth_token': 'something_else',
                },
                'public_org_no_token': {
                    'public': True
                },
                'private_org_replacing_registries': {
                    'replace_registry': [
                        {
                            'new': 'reg1',
                            'old': 'reg2'
                        },
                    ]
                },
                'org_with_package_name_suffix': {
                    'package_name_suffix': '-suffix',
                },
            }

        conf = Config(ConfClass)
        om = OrgManager()
        om.initialize(conf)

        priv_org = om.get_org('private_org', 'cnr_token')
        assert isinstance(priv_org, QuayOrganization)
        assert not priv_org.public
        assert priv_org.oauth_access
        assert not priv_org.registry_replacing_enabled

        public_org = om.get_org('public_org', 'cnr_token')
        assert isinstance(public_org, QuayOrganization)
        assert public_org.public
        assert public_org.oauth_access
        assert not public_org.registry_replacing_enabled

        public_org_no_token = om.get_org('public_org_no_token', 'cnr_token')
        assert isinstance(public_org_no_token, QuayOrganization)
        assert public_org_no_token.public
        assert not public_org_no_token.oauth_access
        assert not public_org_no_token.registry_replacing_enabled

        priv_org_replacing_registries = om.get_org(
            'private_org_replacing_registries', 'cnr_token')
        assert isinstance(priv_org_replacing_registries, QuayOrganization)
        assert not priv_org_replacing_registries.public
        assert not priv_org_replacing_registries.oauth_access
        assert priv_org_replacing_registries.registry_replacing_enabled

        org_with_package_name_suffix = om.get_org(
            'org_with_package_name_suffix', 'cnr_token')
        assert org_with_package_name_suffix.package_name_suffix == '-suffix'
コード例 #8
0
def test_log_level_debug():
    """Test of setting DEBUG log level"""
    class ConfClass(DefaultConfig):
        LOG_LEVEL = 'DEBUG'

    conf = Config(ConfClass)
    assert conf.log_level == 'DEBUG'
コード例 #9
0
    def test_getting_configured_org(self):
        """Test of getting organization instance when org is configured"""
        class ConfClass:
            ORGANIZATIONS = {
                'private_org': {
                    # 'public': False, # Default
                    'oauth_token': 'something',
                },
                'public_org': {
                    'public': True,
                    'oauth_token': 'something_else',
                },
                'public_org_no_token': {
                    'public': True
                }
            }

        conf = Config(ConfClass)
        om = OrgManager()
        om.initialize(conf)

        priv_org = om.get_org('private_org', 'cnr_token')
        assert isinstance(priv_org, QuayOrganization)
        assert not priv_org.public
        assert priv_org.oauth_access

        public_org = om.get_org('public_org', 'cnr_token')
        assert isinstance(public_org, QuayOrganization)
        assert public_org.public
        assert public_org.oauth_access

        public_org_no_token = om.get_org('public_org_no_token', 'cnr_token')
        assert isinstance(public_org_no_token, QuayOrganization)
        assert public_org_no_token.public
        assert not public_org_no_token.oauth_access
コード例 #10
0
def test_zipfile_max_uncompressed_size():
    """Test of setting zipfile_max_uncompressed_size"""
    expected = 10

    class ConfClass(DefaultConfig):
        ZIPFILE_MAX_UNCOMPRESSED_SIZE = expected

    conf = Config(ConfClass)
    assert conf.zipfile_max_uncompressed_size == expected
コード例 #11
0
def test_log_format():
    """Test of setting log format"""
    expected = 'Test'

    class ConfClass(DefaultConfig):
        LOG_FORMAT = expected

    conf = Config(ConfClass)
    assert conf.log_format == expected
コード例 #12
0
    def _get_instance(self):
        class ConfClass:
            GREENWAVE = {
                "url": self.g_url,
                "context": self.g_context,
                "product_version": self.g_product_version
            }

        conf = Config(ConfClass)
        gh = GreenwaveHelper()
        gh.initialize(conf)
        return gh
コード例 #13
0
def test_greenwave():
    """Test Greenwave settings"""
    expected = {
        "url": "https://greenwave.example.com",
        "context": "omps_push",
        "product_version": "cvp"
    }

    class ConfClass(DefaultConfig):
        GREENWAVE = expected

    conf = Config(ConfClass)
    assert conf.greenwave == expected
コード例 #14
0
def test_organizations():
    """Test of organization settings"""
    expected = {
        'myorg': {
            'public': False,
            'oauth_token': 'token',
        }
    }

    class ConfClass(DefaultConfig):
        ORGANIZATIONS = expected

    conf = Config(ConfClass)
    assert conf.organizations == expected
コード例 #15
0
    def test_getting_unconfigured_org(self):
        """Test of getting organization instance whne org is not configured in
        settings"""
        class ConfClass:
            ORGANIZATIONS = {}

        conf = Config(ConfClass)
        om = OrgManager()
        om.initialize(conf)

        unconfigured_org = om.get_org('unconfigured_org', 'cnr_token')
        assert isinstance(unconfigured_org, QuayOrganization)
        assert not unconfigured_org.public
        assert not unconfigured_org.oauth_access
コード例 #16
0
def test_organizations():
    """Test of organization settings"""
    expected = {
        'myorg': {
            'public': False,
            'oauth_token': 'token',
            'replace_registry': [
                {
                    'old': 'quay.io',
                    'new': 'example.com',
                },
            ]
        }
    }

    class ConfClass(DefaultConfig):
        ORGANIZATIONS = expected

    conf = Config(ConfClass)
    assert conf.organizations == expected
コード例 #17
0
def test_organziation_regexp():
    """Organziation with regexp Test"""
    expected = {
        'myorg': {
            'public':
            False,
            'oauth_token':
            'token',
            'replace_registry': [
                {
                    'old': 'quay.io/$',
                    'new': 'example.com',
                    'regexp': True,
                },
            ]
        }
    }

    class ConfClass(DefaultConfig):
        ORGANIZATIONS = expected

    conf = Config(ConfClass)
    assert conf.organizations == expected