def test_write_to_existing_path(self): prev_config = 'some-text-which is not a config' with open(DEFAULT_CONFIG_FILES[0], 'w') as ostr: ostr.write(prev_config) save_config(self._config_dict()) with open(DEFAULT_CONFIG_FILES[0]) as istr: self.assertFalse(istr.read().startswith(prev_config))
def test_discover(self): org = 'quay.io/cogniteev' truncated_config = StringIO() config = load_config(self.CONFIG_FILE) config['organizations'][org]['repositories'] = None save_config(config, truncated_config) truncated_config.seek(0, 0) discover_command(['cogniteev'], truncated_config, interactive=False) config = load_config(self.CONFIG_FILE) tags = config.get('organizations', {})\ .get('quay.io/cogniteev', {})\ .get('repositories', {})\ .get('docido-contrib-crawlers', {})\ .get('on_build', {})\ .get('tags', {}) self.assertEqual(len(tags), 1) latest_trigger = tags.get('latest') self.assertEqual(len(latest_trigger), 1) github_repo = 'quay.io/cogniteev/docido-pull-crawler-github' assertCountEqual( self, latest_trigger.get(github_repo), [ dict(trigger_uuid="dcb1e958-9fdb-4e9b-9856-4d52771b3df9", ref="refs/heads/develop"), dict(trigger_uuid="567da7a3-0373-4cf2-8480-58a18b8dbe47", ref="refs/tags/v1.1"), ] )
def test_write_to_file_like(self): file_like = StringIO() save_config(self._config_dict(), file_like) self.assertTrue(file_like.getvalue().startswith('organizations:'))
def test_write_to_default_path(self): save_config(self._config_dict()) self.assertTrue(osp.isfile(DEFAULT_CONFIG_FILES[-1]))
def test_write_to_directory(self): with self.assertRaises(IOError) as exc: save_config(self._config_dict(), osp.expanduser("~")) self.assertEqual(exc.exception.errno, 21)
def test_write_to_unknown_path(self): with self.assertRaises(OSError) as exc: save_config(self._config_dict(), '/path/to/unknown/file.yml') self.assertEqual(exc.exception.errno, 13)