Beispiel #1
0
    def test_cant_change_settings(self, tmpdir):
        primary_settings = self.create_module_with_data(
            tmpdir, 'primary_module.py', self.PRIMARY_MODULE_DATA)

        settings = Settings(primary_settings)
        with pytest.raises(AttributeError):
            settings.TEST_SETTING = 1
Beispiel #2
0
    def test_load_primary_settings_as_env_var(self, tmpdir):
        test_module = self.create_module_with_data(tmpdir, 'test_module.py',
                                                   self.PRIMARY_MODULE_DATA)
        os.environ[self.ENV_SETTINGS] = getfile(test_module)
        settings = Settings(self.ENV_SETTINGS)

        assert settings.TEST_SETTING == self.PRIMARY_SETTINGS_VALUE
Beispiel #3
0
    def test_load_test_setting_without_custom_settings(self, tmpdir):
        primary_settings = self.create_module_with_data(
            tmpdir, 'primary_module.py', self.PRIMARY_MODULE_DATA)
        test_settings = self.create_module_with_data(tmpdir, 'test_module.py',
                                                     self.TEST_MODULE_DATA)
        settings = Settings(primary_settings, test_settings=test_settings)

        assert settings.TEST_SETTING == self.TEST_SETTINGS_VALUE
Beispiel #4
0
    def test_load_custom_settings(self, tmpdir):
        primary_settings = self.create_module_with_data(
            tmpdir, 'primary_module.py', self.PRIMARY_MODULE_DATA)
        custom_settings = self.create_module_with_data(tmpdir,
                                                       'custom_module.py',
                                                       self.CUSTOM_MODULE_DATA)
        settings = Settings(primary_settings, custom_settings)

        assert settings.TEST_SETTING == self.CUSTOM_SETTINGS_VALUE
Beispiel #5
0
    def test_dont_load_test_settings(self, tmpdir, monkeypatch):
        primary_settings = self.create_module_with_data(
            tmpdir, 'primary_module.py', self.PRIMARY_MODULE_DATA)
        test_settings = self.create_module_with_data(tmpdir, 'test_module.py',
                                                     self.TEST_MODULE_DATA)

        monkeypatch.setattr(sys, 'argv', [''])
        settings = Settings(primary_settings, test_settings=test_settings)

        assert settings.TEST_SETTING == self.PRIMARY_SETTINGS_VALUE
Beispiel #6
0
    def test_load_primary_settings_as_file_path(self, tmpdir):
        test_module = self.create_module_with_data(tmpdir, 'test_module.py',
                                                   self.PRIMARY_MODULE_DATA)
        settings = Settings(getfile(test_module))

        assert settings.TEST_SETTING == self.PRIMARY_SETTINGS_VALUE
Beispiel #7
0
 def test_lazy_import(self, tmpdir):
     primary_settings = self.create_module_with_data(
         tmpdir, 'primary_module.py', self.PRIMARY_MODULE_DATA)
     settings = Settings(primary_settings)
     assert settings._data == {}
     assert settings.TEST_SETTING == self.PRIMARY_SETTINGS_VALUE