Exemple #1
0
 def setUpClass(self, github_get_repo_patch):
     self.user = '******'
     self.repo = 'fakerepo'
     self.loader = GithubLoader(self.user,
                                self.repo,
                                subdir=None,
                                sha=None,
                                prov=None)
Exemple #2
0
 def setUpClass(self, mocked_repo):
     self.user = '******'
     self.repo = 'fakerepo'
     self.loader = GithubLoader(self.user,
                                self.repo,
                                subdir=None,
                                sha=None,
                                prov=None)
Exemple #3
0
def getLoader(user, repo, sha=None, prov=None):
    """Build a fileLoader (LocalLoader or GithubLoader) for the given repository."""
    if user is None and repo is None:
        loader = LocalLoader()
    else:
        loader = GithubLoader(user, repo, sha, prov)
    return loader
Exemple #4
0
def getLoader(user, repo, subdir=None, spec_url=None, sha=None, prov=None):
    """Build a fileLoader (LocalLoader, GithubLoader, URLLoader) for the given parameters."""
    if user is None and repo is None and not spec_url:
        loader = LocalLoader()
    elif spec_url:
        loader = URLLoader(spec_url)
    else:
        loader = GithubLoader(user, repo, subdir, sha, prov)
    return loader
Exemple #5
0
def getLoader(user, repo, subdir=None, query_urls=[], sha=None, prov=None):
    """Build a fileLoader (LocalLoader, GithubLoader, ParamLoader) for the given parameters."""
    if user is None and repo is None and not query_urls:
        loader = LocalLoader()
    elif query_urls:
        loader = ParamLoader(query_urls)
    else:
        loader = GithubLoader(user, repo, subdir, sha, prov)
    return loader
Exemple #6
0
class TestGithubLoader(unittest.TestCase):
    def setUp(self):
        self.patcher = patch('requests.get', side_effect=mock_requestsGithub)
        self.patcher.start()

    def tearDown(self):
        self.patcher.stop()

    @classmethod
    @patch('github.Github.get_repo', return_value=[])
    def setUpClass(self, github_get_repo_patch):
        self.user = '******'
        self.repo = 'fakerepo'
        self.loader = GithubLoader(self.user, self.repo, None, None)

    def test_fetchFiles(self):
        files = self.loader.fetchFiles()

        # Should return a list of file items
        self.assertIsInstance(files, list, "Should return a list of file items")

        # Should have N files (where N=5)
        self.assertEquals(len(files), 5, "Should return correct number of files")

        # File items should have a download_url
        for fItem in files:
            self.assertIn('download_url', fItem, "File items should have a download_url")

    def test_getRawRepoUri(self):
        repoUri = self.loader.getRawRepoUri()

        # Should be a string
        self.assertIsInstance(repoUri, six.string_types, "Should be a string")

        # For URI shoud contain user / repo
        self.assertIn(self.user, repoUri, "Should contain user")
        self.assertIn(self.repo, repoUri, "Should contain repo")

    def test_getTextFor(self):
        files = self.loader.fetchFiles()

        # the contents of each file
        for fItem in files:
            text = self.loader.getTextFor(fItem)

            # Should be some text
            self.assertIsInstance(text, six.string_types, "Should be some text")

            # Should be non-empty for existing items
            self.assertGreater(len(text), 0, "Should be non-empty")

        # Should raise exception for invalid file items
        with self.assertRaises(Exception, message="Should raise exception for invalid file items"):
            text = self.loader.getTextFor( { } )

    def test_getTextForName(self):
        testableNames = [
            ('test-rq', qType['SPARQL']),
            ('test-sparql', qType['SPARQL']),
            ('test-tpf', qType['TPF'])
        ]
        for name, expectedType in testableNames:
            text, actualType = self.loader.getTextForName(name)
            self.assertEqual(expectedType, actualType, "Query type should match %s != %s"%(expectedType, actualType))
Exemple #7
0
 def setUpClass(self, github_get_repo_patch):
     self.user = '******'
     self.repo = 'fakerepo'
     self.loader = GithubLoader(self.user, self.repo, None, None)
Exemple #8
0
 def setUpClass(self):
     self.user = '******'
     self.repo = 'fakerepo'
     self.loader = GithubLoader(self.user, self.repo, None, None)
Exemple #9
0
class TestGithubLoader(unittest.TestCase):
    @classmethod
    @patch('grlc.fileLoaders.Github.get_repo', return_value=MockGithubRepo())
    def setUpClass(self, mocked_repo):
        self.user = '******'
        self.repo = 'fakerepo'
        self.loader = GithubLoader(self.user,
                                   self.repo,
                                   subdir=None,
                                   sha=None,
                                   prov=None)

    def test_fetchFiles(self):
        files = self.loader.fetchFiles()

        # Should return a list of file items
        self.assertIsInstance(files, list,
                              "Should return a list of file items")

        # Should have N files (where N=9)
        self.assertEqual(len(files), 9,
                         "Should return correct number of files")

        # File items should have a download_url
        for fItem in files:
            self.assertIn('download_url', fItem,
                          "File items should have a download_url")

    def test_getRawRepoUri(self):
        repoUri = self.loader.getRawRepoUri()

        # Should be a string
        self.assertIsInstance(repoUri, six.string_types, "Should be a string")

        # For URI shoud contain user / repo
        self.assertIn(self.user, repoUri, "Should contain user")
        self.assertIn(self.repo, repoUri, "Should contain repo")

    def test_getTextFor(self):
        files = self.loader.fetchFiles()

        # the contents of each file
        for fItem in files:
            text = self.loader.getTextFor(fItem)

            # Should be some text
            self.assertIsInstance(text, six.string_types,
                                  "Should be some text")

            # Should be non-empty for existing items
            self.assertGreater(len(text), 0, "Should be non-empty")

        # Should raise exception for invalid file items
        with self.assertRaises(
                Exception,
                msg="Should raise exception for invalid file items"):
            text = self.loader.getTextFor({})

    def test_getTextForName(self):
        testableNames = [('test-rq', qType['SPARQL']),
                         ('test-sparql', qType['SPARQL']),
                         ('test-tpf', qType['TPF'])]
        for name, expectedType in testableNames:
            text, actualType = self.loader.getTextForName(name)
            self.assertEqual(
                expectedType, actualType, "Query type should match %s != %s" %
                (expectedType, actualType))

    def test_getEndpointText(self):
        endpoint = self.loader.getEndpointText()

        # Should be some text
        self.assertIsInstance(endpoint, six.string_types,
                              "Should be some text")