コード例 #1
0
ファイル: test_sandbox.py プロジェクト: FlorianKempenich/kata
    def test_explore_repo(self):
        github_user = '******'
        # repo_name = 'ansible-role-python-virtualenv'
        repo_name = 'My-Java-Archetype'
        path = ''
        thread_pool_executor = futures.ThreadPoolExecutor(
            100, thread_name_prefix='subdir-explorer-')
        api = GithubApi()
        repo = GRepo(api, thread_pool_executor)

        result = repo.get_files_to_download(github_user, repo_name, path)
        pprint(result)
コード例 #2
0
ファイル: test_grepo.py プロジェクト: FlorianKempenich/kata
        def test_root_dir_isn_t_a_dir(self, tmp_path: Path, grepo: GRepo):
            # Given: Root dir isn't a 'directory'
            not_a_dir = tmp_path / 'not_a_dir'
            with not_a_dir.open('w') as file:
                file.write('I am not a dir')
            assert not not_a_dir.is_dir()

            # When: Trying to download files
            # Then: An exception is raised
            with pytest.raises(FileExistsError) as raised_exception:
                grepo.download_files_at_location(root_dir=not_a_dir,
                                                 files_to_download=[DownloadableFile(Path('file.txt'),
                                                                                     'http://url.com/file.txt')])
            assert raised_exception.match(r"Root dir '.*not_a_dir' is not a directory")
コード例 #3
0
 def init_domain():
     self.grepo = GRepo(self.api, self.file_writer, self.executor)
     self.init_kata_service = InitKataService(self.kata_language_repo,
                                              self.kata_template_repo,
                                              self.grepo,
                                              self.config_repo)
     self.login_service = LoginService(self.config_repo)
コード例 #4
0
ファイル: test_sandbox.py プロジェクト: FlorianKempenich/kata
 def __init__(self):
     self.executor = ThreadPoolExecutor(100)
     self.api = GithubApi()
     self.file_writer = FileWriter()
     self.grepo = GRepo(self.api, self.file_writer, self.executor)
     self.kata_template_repo = HardCoded.KataTemplateRepo()
     self.real_kata_template_repo = KataTemplateRepo(self.api)
     self.sandbox_dir = Path('../sandbox')
     self.init_kata_service = InitKataService(self.kata_template_repo,
                                              self.grepo)
コード例 #5
0
ファイル: test_grepo.py プロジェクト: FlorianKempenich/kata
        def test_diverse_multiple_files(self, tmp_path: Path, mock_api: GithubApi, grepo: GRepo):
            def return_file_content_for_correct_url(url):
                mock_content_for_url = {
                    'http://this_is_the_url/file_1.md': "CONTENT FOR 'file_1.md'",
                    'http://this_is_the_url/file_2.md': "CONTENT FOR 'file_2.md'",
                    'http://this_is_the_url/file_with_wrong_name_in_url.txt': "CONTENT FOR 'file_3.md'",
                    'http://this_is_the_url/file_empty.md': "",
                    'http://this_is_the_url/sub/path/file_in_sub_path.md': "CONTENT FOR 'file_in_sub_path.md'",
                }
                if url not in mock_content_for_url:
                    pytest.fail(f"Api wasn't called with the correct url | Incorrect URL: {url}")
                return mock_content_for_url[url]

            # GIVEN: A list of DownloadableFiles w/ content available in the Mock Api
            mock_api.download_raw_text_file.side_effect = return_file_content_for_correct_url
            files_to_download = [
                DownloadableFile(file_path=Path('file_1.md'),
                                 download_url='http://this_is_the_url/file_1.md'),
                DownloadableFile(file_path=Path('file_2.md'),
                                 download_url='http://this_is_the_url/file_2.md'),
                DownloadableFile(file_path=Path('file_3.md'),
                                 download_url='http://this_is_the_url/file_with_wrong_name_in_url.txt'),
                DownloadableFile(file_path=Path('file_empty.md'),
                                 download_url='http://this_is_the_url/file_empty.md'),
                DownloadableFile(file_path=Path('sub/path/file_in_sub_path.md'),
                                 download_url='http://this_is_the_url/sub/path/file_in_sub_path.md')]

            # WHEN: Downloading all files
            root_dir = tmp_path
            grepo.download_files_at_location(root_dir=root_dir, files_to_download=files_to_download)

            # THEN: All files have been correctly downloaded
            def assert_file_at_path_has_content(file_path: Path, expected_content: str):
                assert file_path.exists()
                with file_path.open('r') as downloaded_file:
                    assert downloaded_file.read() == expected_content

            assert_file_at_path_has_content(root_dir / 'file_1.md', "CONTENT FOR 'file_1.md'")
            assert_file_at_path_has_content(root_dir / 'file_2.md', "CONTENT FOR 'file_2.md'")
            assert_file_at_path_has_content(root_dir / 'file_3.md', "CONTENT FOR 'file_3.md'")
            assert_file_at_path_has_content(root_dir / 'file_empty.md', "")
            assert_file_at_path_has_content(root_dir / 'sub/path/file_in_sub_path.md',
                                            "CONTENT FOR 'file_in_sub_path.md'")
コード例 #6
0
ファイル: test_grepo.py プロジェクト: FlorianKempenich/kata
 def test_empty_list(self, tmp_path: Path, grepo: GRepo):
     root_dir = tmp_path
     empty_list = []
     grepo.download_files_at_location(root_dir, empty_list)
     for _ in root_dir.iterdir():
         pytest.fail('root_dir should be empty but was not!!')
コード例 #7
0
ファイル: test_grepo.py プロジェクト: FlorianKempenich/kata
def grepo(mock_api, thread_pool_executor):
    file_writer = FileWriter()
    return GRepo(mock_api, file_writer, thread_pool_executor)