Beispiel #1
0
    def test__init__(self):
        importer = GitRepoModuleImporter(name='name',
                                         modules=[],
                                         repo_raw_url=self.repo_raw_url,
                                         branch=self.branch)
        self.assertEqual(importer.repo_raw_url, self.repo_raw_url)
        self.assertEqual(importer.branch, self.branch)

        importer = GitRepoModuleImporter(
            name='name',
            modules=[],
            repo_raw_url=self.repo_raw_url_without_slash,
            branch=self.branch)
        self.assertEqual(importer.repo_raw_url, self.repo_raw_url)
        self.assertEqual(importer.branch, self.branch)

        self.assertRaises(ValueError,
                          GitRepoModuleImporter,
                          name='name',
                          modules=[],
                          repo_raw_url='http://repo-addr/',
                          branch=self.branch)

        GitRepoModuleImporter(name='name',
                              modules=[],
                              repo_raw_url='http://repo-addr/',
                              branch=self.branch,
                              secure_only=False)
Beispiel #2
0
    def test_get_source(self):
        importer = GitRepoModuleImporter(name='name', modules=[], repo_raw_url=self.repo_raw_url, branch=self.branch)

        source = importer.get_source(self.fullname)

        self.assertEqual(source, _FETCH_REPO_FILE_RETURN)
        importer._fetch_repo_file.assert_called_once_with(importer._file_url(self.fullname, is_pkg=IS_PACKAGE_RETURN))
Beispiel #3
0
    def test_get_code(self):
        expect_code = compile(GET_SOURCE_RETURN, GET_FILE_RETURN, 'exec')
        importer = GitRepoModuleImporter(name='name',
                                         modules=[],
                                         repo_raw_url=self.repo_raw_url,
                                         branch=self.branch)

        self.assertEqual(expect_code, importer.get_code(self.fullname))
Beispiel #4
0
    def test_get_file(self):
        importer = GitRepoModuleImporter(name='name', modules=[], repo_raw_url=self.repo_raw_url, branch=self.branch)

        with patch(UTILS_IMPORTER_GIT_IS_PACKAGE, MagicMock(return_value=False)):
            self.assertEqual(importer.get_file(self.fullname), self.module_url)

        with patch(UTILS_IMPORTER_GIT_IS_PACKAGE, MagicMock(return_value=True)):
            self.assertEqual(importer.get_file(self.fullname), self.package_url)
Beispiel #5
0
 def test__file_url(self):
     importer = GitRepoModuleImporter(name='name',
                                      modules=[],
                                      repo_raw_url=self.repo_raw_url,
                                      branch=self.branch)
     self.assertEqual(importer._file_url(self.fullname, is_pkg=True),
                      self.package_url)
     self.assertEqual(importer._file_url(self.fullname, is_pkg=False),
                      self.module_url)
Beispiel #6
0
    def test_get_path(self):
        importer = GitRepoModuleImporter(name='name',
                                         modules=[],
                                         repo_raw_url=self.repo_raw_url,
                                         branch=self.branch)

        self.assertEqual(
            importer.get_path(self.fullname),
            ['https://test-git-repo-raw/master/module1/module2/module3'])
Beispiel #7
0
    def test_get_source__fetch_none(self):
        importer = GitRepoModuleImporter(name='name',
                                         modules=[],
                                         repo_raw_url=self.repo_raw_url,
                                         branch=self.branch)

        self.assertRaises(ImportError, importer.get_source, self.fullname)
        importer._fetch_repo_file.assert_called_once_with(
            importer._file_url(self.fullname, is_pkg=IS_PACKAGE_RETURN))
Beispiel #8
0
    def test__fetch_repo_file__no_cache(self):
        importer = GitRepoModuleImporter(name='name',
                                         modules=[],
                                         repo_raw_url=self.repo_raw_url,
                                         branch=self.branch,
                                         use_cache=False)
        first_resp = MockResponse(content='first_request_content')
        second_resp = MockResponse(content='second_request_content')

        with patch(REQUESTS_GET, MagicMock(return_value=first_resp)):
            self.assertEqual(importer._fetch_repo_file(self.module_url), first_resp.content)
            self.assertEqual(importer.file_cache, {})

        with patch(REQUESTS_GET, MagicMock(return_value=second_resp)):
            self.assertEqual(importer._fetch_repo_file(self.module_url), second_resp.content)
            self.assertEqual(importer.file_cache, {})

        with patch(REQUESTS_GET, MagicMock(return_value=MockResponse(ok=False))):
            self.assertIsNone(importer._fetch_repo_file(self.module_url))
            self.assertEqual(importer.file_cache, {})
Beispiel #9
0
    def test_is_package(self):
        importer = GitRepoModuleImporter(name='name', modules=[], repo_raw_url=self.repo_raw_url, branch=self.branch)

        with patch(UTILS_IMPORTER_GIT__FETCH_REPO_FILE, MagicMock(return_value=None)):
            self.assertFalse(importer.is_package(self.fullname))
            importer._fetch_repo_file.assert_called_once_with(importer._file_url(self.fullname, is_pkg=True))

        with patch(UTILS_IMPORTER_GIT__FETCH_REPO_FILE, MagicMock(return_value='')):
            self.assertTrue(importer.is_package(self.fullname))
            importer._fetch_repo_file.assert_called_once_with(importer._file_url(self.fullname, is_pkg=True))