Esempio n. 1
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
Esempio n. 2
0
 def setUpClass(self, x):
     self.specURL = 'http://example.org/url.yml'
     self.loader = URLLoader(self.specURL)
Esempio n. 3
0
class TestURLLoader(unittest.TestCase):
    @classmethod
    def setUp(self):
        self.patcher = patch('grlc.fileLoaders.requests.get',
                             side_effect=mock_requestsUrl)
        self.patcher.start()

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

    @classmethod
    @patch('requests.get', side_effect=mock_requestsUrl)
    def setUpClass(self, x):
        self.specURL = 'http://example.org/url.yml'
        self.loader = URLLoader(self.specURL)

    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=3)
        self.assertEqual(len(files), 3,
                         "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_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_getRawRepoUri(self):
        repoUri = self.loader.getRawRepoUri()

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

        # Should be the same one we used to create the repo
        self.assertIn(self.specURL, repoUri,
                      "Should be the same URL it was initialized with")

    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))