def test_wiki_with_fake_origin(self, mock_get): fixture = fixture_setup.FakePartsWikiOrigin() self.useFixture(fixture) origin_url = fixture.fake_parts_wiki_origin_fixture.url _create_example_output(""" --- maintainer: John Doe <*****@*****.**> origin: {origin_url} description: example parts: [somepart] """.format(origin_url=origin_url)) origin_dir = os.path.join(BASE_DIR, _encode_origin(origin_url)) os.makedirs(origin_dir, exist_ok=True) # Create a fake snapcraft.yaml for _get_origin_data() to parse with open(os.path.join(origin_dir, 'snapcraft.yaml'), 'w') as fp: text = requests.get(origin_url).text fp.write(text) main(['--debug', '--index', TEST_OUTPUT_PATH]) self.assertEqual(1, _get_part_list_count()) part = _get_part('somepart') self.assertTrue(part)
def test_wiki_with_fake_origin_with_bad_snapcraft_yaml(self): fixture = fixture_setup.FakePartsWikiOrigin() self.useFixture(fixture) origin_url = fixture.fake_parts_wiki_origin_fixture.url fake_logger = fixtures.FakeLogger(level=logging.ERROR) self.useFixture(fake_logger) _create_example_output(""" --- maintainer: John Doe <*****@*****.**> origin: {origin_url} description: example parts: [somepart] """.format(origin_url=origin_url)) origin_dir = os.path.join(parser._get_base_dir(), _encode_origin(origin_url)) os.makedirs(origin_dir, exist_ok=True) # Create a fake snapcraft.yaml for _get_origin_data() to parse with open(os.path.join(origin_dir, 'snapcraft.yaml'), 'w') as fp: fp.write("bad yaml is : bad :yaml:::") main(['--debug', '--index', TEST_OUTPUT_PATH]) self.assertEqual(0, _get_part_list_count()) self.assertTrue( 'Invalid wiki entry' in fake_logger.output, 'Missing invalid wiki entry info in output')
def test_wiki_with_fake_origin_with_bad_snapcraft_yaml(self, mock_get): fixture = fixture_setup.FakePartsWikiOrigin() self.useFixture(fixture) origin_url = fixture.fake_parts_wiki_origin_fixture.url fake_logger = fixtures.FakeLogger(level=logging.ERROR) self.useFixture(fake_logger) _create_example_output(""" --- maintainer: John Doe <*****@*****.**> origin: {origin_url} description: example parts: [somepart] """.format(origin_url=origin_url)) origin_dir = os.path.join(BASE_DIR, _encode_origin(origin_url)) os.makedirs(origin_dir, exist_ok=True) # Create a fake snapcraft.yaml for _get_origin_data() to parse with open(os.path.join(origin_dir, 'snapcraft.yaml'), 'w') as fp: fp.write("bad yaml is : bad :yaml:::") main(['--debug', '--index', TEST_OUTPUT_PATH]) self.assertEqual(0, _get_part_list_count()) self.assertTrue('Invalid wiki entry' in fake_logger.output, 'Missing invalid wiki entry info in output')
def test_wiki_with_fake_origin(self): fixture = fixture_setup.FakePartsWikiOrigin() self.useFixture(fixture) origin_url = fixture.fake_parts_wiki_origin_fixture.url _create_example_output(""" --- maintainer: John Doe <*****@*****.**> origin: {origin_url} description: example parts: [somepart] """.format(origin_url=origin_url)) origin_dir = os.path.join(parser._get_base_dir(), _encode_origin(origin_url)) os.makedirs(origin_dir, exist_ok=True) # Create a fake snapcraft.yaml for _get_origin_data() to parse with open(os.path.join(origin_dir, 'snapcraft.yaml'), 'w') as fp: text = requests.get(origin_url).text fp.write(text) main(['--debug', '--index', TEST_OUTPUT_PATH]) self.assertEqual(1, _get_part_list_count()) part = _get_part('somepart') self.assertTrue(part)
def test_wiki_with_fake_origin(self): fixture = fixture_setup.FakePartsWikiOrigin() self.useFixture(fixture) origin_url = fixture.fake_parts_wiki_origin_fixture.url _create_example_output(""" --- maintainer: John Doe <*****@*****.**> origin: {origin_url} description: example parts: [somepart] """.format(origin_url=origin_url)) origin_dir = os.path.join(parser._get_base_dir(), _encode_origin(origin_url)) os.makedirs(origin_dir, exist_ok=True) # Create a fake snapcraft.yaml for _get_origin_data() to parse with open(os.path.join(origin_dir, "snapcraft.yaml"), "w") as fp: text = requests.get(origin_url).text fp.write(text) main(["--debug", "--index", TEST_OUTPUT_PATH]) self.assertThat(_get_part_list_count(), Equals(1)) part = _get_part("somepart") self.assertTrue(part)
def test_wiki_with_fake_origin_with_bad_snapcraft_yaml(self): fixture = fixture_setup.FakePartsWikiOrigin() self.useFixture(fixture) origin_url = fixture.fake_parts_wiki_origin_fixture.url fake_logger = fixtures.FakeLogger(level=logging.ERROR) self.useFixture(fake_logger) _create_example_output(""" --- maintainer: John Doe <*****@*****.**> origin: {origin_url} description: example parts: [somepart] """.format(origin_url=origin_url)) origin_dir = os.path.join(parser._get_base_dir(), _encode_origin(origin_url)) os.makedirs(origin_dir, exist_ok=True) # Create a fake snapcraft.yaml for _get_origin_data() to parse with open(os.path.join(origin_dir, "snapcraft.yaml"), "w") as fp: fp.write("bad yaml is : bad :yaml:::") main(["--debug", "--index", TEST_OUTPUT_PATH]) self.assertThat(_get_part_list_count(), Equals(0)) self.assertTrue( "Invalid wiki entry" in fake_logger.output, "Missing invalid wiki entry info in output", )
def test_origin_options(self, mock_get_origin_data, mock_get_base_dir): _create_example_output( """ {{{ --- maintainer: John Doe <[email protected] origin: lp:snapcraft-parser-example origin-type: bzr origin-branch: stable-branch origin-commit: 123 origin-tag: source-tag description: example parts: [main] }}} """ ) mock_get_base_dir.return_value = tempfile.mkdtemp() mock_get_origin_data.return_value = { "parts": { "main": { "source": "lp:something", "plugin": "copy", "files": ["file1", "file2"], } } } main(["--debug", "--index", TEST_OUTPUT_PATH]) self.mock_get.assert_has_calls( [mock.call("lp:snapcraft-parser-example", source_type="bzr")] ) mock_source_handler = self.mock_get.return_value mock_source_handler.assert_has_calls( [ mock.call( "lp:snapcraft-parser-example", source_dir=os.path.join( parser._get_base_dir(), _encode_origin("lp:snapcraft-parser-example"), ), ) ] ) mock_handler = mock_source_handler.return_value self.assertThat(mock_handler.source_branch, Equals("stable-branch")) self.assertThat(mock_handler.source_commit, Equals(123)) self.assertThat(mock_handler.source_tag, Equals("source-tag"))
def test_origin_options(self, mock_get_origin_data, mock_get_base_dir): _create_example_output(""" {{{ --- maintainer: John Doe <[email protected] origin: lp:snapcraft-parser-example origin-type: bzr origin-branch: stable-branch origin-commit: 123 origin-tag: source-tag description: example parts: [main] }}} """) mock_get_base_dir.return_value = tempfile.mkdtemp() mock_get_origin_data.return_value = { 'parts': { 'main': { 'source': 'lp:something', 'plugin': 'copy', 'files': ['file1', 'file2'], }, } } main(['--debug', '--index', TEST_OUTPUT_PATH]) self.mock_get.assert_has_calls([ mock.call('lp:snapcraft-parser-example', source_type='bzr') ]) mock_source_handler = self.mock_get.return_value mock_source_handler.assert_has_calls([ mock.call( 'lp:snapcraft-parser-example', source_dir=os.path.join( parser._get_base_dir(), _encode_origin('lp:snapcraft-parser-example'))) ]) mock_handler = mock_source_handler.return_value self.assertEqual(mock_handler.source_branch, 'stable-branch') self.assertEqual(mock_handler.source_commit, 123) self.assertEqual(mock_handler.source_tag, 'source-tag')
def test__encode_origin_lp(self): origin = 'lp:~testuser/testproject/testbranch' origin_dir = _encode_origin(origin) self.assertEqual('lptestusertestprojecttestbranch', origin_dir)
def test__encode_origin_git(self): origin = "[email protected]:testuser/testproject.git" origin_dir = _encode_origin(origin) self.assertThat(origin_dir, Equals("gitgithub.comtestusertestproject.git"))
def test__encode_origin_lp(self): origin = "lp:~testuser/testproject/testbranch" origin_dir = _encode_origin(origin) self.assertThat(origin_dir, Equals("lptestusertestprojecttestbranch"))
def test__encode_origin_git(self): origin = '[email protected]:testuser/testproject.git' origin_dir = _encode_origin(origin) self.assertEqual('gitgithub.comtestusertestproject.git', origin_dir)