def seealso(request, source): if request.method == 'GET': finder = SeeAlsoFinder() try: uris = finder.find(source) except (SPARQLQueryProcessorError, SPARQLQueryBuilderError), e: return render_to_response('debian/error.html', {'reason': e}) replydata = {'source': source, 'uris': uris} return render_to_response('debian/seealso.html', replydata)
class SeeAlsoFinderTest(unittest.TestCase): def setUp(self): self.finder = SeeAlsoFinder() self.mox = Mox() debian.services.RES_BASEURI = "base" debian.services.FROM_GRAPH = None def test__fetch_seealso_uris(self): sourcename = "pkg" unversionedsourceuri = "base/source/%s" % sourcename mock = self.mox.CreateMock(SPARQLQueryProcessor) expectedarg = \ r".+SELECT\s*\?uri.+\<%s\>\sa\sdeb:UnversionedSource\s*;\s*rdfs:seeAlso\s\?uri" % \ re.escape(unversionedsourceuri) mock.execute_query(Regex(expectedarg, flags=re.DOTALL)) binding1 = {'uri': {'value': "http://example.org/1"}} binding2 = {'uri': {'value': "http://example.org/2"}} bindings = [binding1, binding2] fakeresults = {'results': {'bindings': bindings}} self.finder.processor = mock self.mox.ReplayAll() self.finder.processor.results = fakeresults uris = self.finder._fetch_seealso_uris(unversionedsourceuri) self.mox.VerifyAll() self.assertEqual(2, len(uris)) self.assertTrue("http://example.org/1" in uris) self.assertTrue("http://example.org/2" in uris) def test_find_forbidden_characters(self): self.assertRaises(SPARQLQueryBuilderPackageNameSchemeError, self.finder.find, "{}@") def test_find(self): srcpkgname = "source" srcpkguri = "base/source/%s" % srcpkgname self.mox.StubOutWithMock(self.finder, "_fetch_seealso_uris") returnvals = ["http://example.org/1", "http://example.org/2"] self.finder._fetch_seealso_uris(srcpkguri).AndReturn(returnvals) self.mox.ReplayAll() uris = self.finder.find(srcpkgname) self.mox.VerifyAll() self.assertEqual(2, len(uris)) self.assertTrue("http://example.org/1" in uris) self.assertTrue("http://example.org/2" in uris) def test_find_escape(self): srcpkgname = "source.+-" srcpkguri = "base/source/%s" % "source.%2B-" self.mox.StubOutWithMock(self.finder, "_fetch_seealso_uris") returnvals = ["http://example.org/1", "http://example.org/2"] self.finder._fetch_seealso_uris(srcpkguri).AndReturn(returnvals) self.mox.ReplayAll() uris = self.finder.find(srcpkgname) self.mox.VerifyAll()
def setUp(self): self.finder = SeeAlsoFinder() self.mox = Mox() debian.services.RES_BASEURI = "base" debian.services.FROM_GRAPH = None