def testExcludeWordsInQuery(self, requestsMock): web.app.template_folder = "../templates" expectedItems = self.prepareSearchMocks(requestsMock, 1, 1) with web.app.test_request_context('/'): response = self.app.get("/api?t=search&q=query+!excluded") entries, _, _ = newznab.NewzNab(Bunch.fromDict({"name": "forTest", "score": 0, "host": "host"})).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue(compare('http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query+!excluded', calledUrls[0])) response = self.app.get("/api?t=search&q=query+--excluded") entries, _, _ = newznab.NewzNab(Bunch.fromDict({"name": "forTest", "score": 0, "host": "host"})).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue(compare('http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query+!excluded', calledUrls[0])) self.app.get("/internalapi/search?query=query+!excluded&category=all") calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue(compare('http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query+!excluded', calledUrls[0])) self.app.get("/internalapi/search?query=query+--excluded&category=all") calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue(compare('http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query+!excluded', calledUrls[0]))
def testExcludeWordsInQuery(self, requestsMock): web.app.template_folder = "../templates" expectedItems = self.prepareSearchMocks(requestsMock, 1, 1) with web.app.test_request_context('/'): response = self.app.get("/api?t=search&q=query+!excluded") entries, _, _ = newznab.NewzNab( Bunch.fromDict({ "name": "forTest", "score": 0, "host": "host", "backend": "" })).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue( compare( 'http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query+!excluded', calledUrls[0])) response = self.app.get("/api?t=search&q=query+--excluded") entries, _, _ = newznab.NewzNab( Bunch.fromDict({ "name": "forTest", "score": 0, "host": "host", "backend": "" })).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue( compare( 'http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query+!excluded', calledUrls[0])) self.app.get( "/internalapi/search?query=query+!excluded&category=all") calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue( compare( 'http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query+!excluded', calledUrls[0])) self.app.get( "/internalapi/search?query=query+--excluded&category=all") calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue( compare( 'http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query+!excluded', calledUrls[0]))
def testFullStack(self, requestsMock): web.app.template_folder = "../templates" expectedItems = self.prepareSearchMocks(requestsMock, 1, 1) with web.app.test_request_context('/'): response = self.app.get("/api?t=search&q=query") entries, _, _ = newznab.NewzNab(Bunch.fromDict({"name": "forTest", "score": 0, "host": "host"})).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue(compare('http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query', calledUrls[0])) self.assertEqual("http://localhost:5075/getnzb?searchresultid=1", entries[0].link) #Download NZB config.settings.searching.nzbAccessType = "redirect" response = self.app.get("/getnzb?searchresultid=1") self.assertTrue("redirect" in response.data) config.settings.searching.nzbAccessType = "serve" requestsMock.register_uri('GET', re.compile(r'.*newznab1result1.link*'), text="NZB Data") response = self.app.get("/getnzb?searchresultid=1") self.assertEquals("NZB Data", response.data) #Download via API requestsMock.register_uri('GET', re.compile(r'.*newznab1result1.link*'), text="NZB Data") response = self.app.get("/api?t=get&id=%s" % entries[0].indexerguid) self.assertEquals("NZB Data", response.data) #Find downloaded NZBs in stats downloads = json.loads(self.app.get("/internalapi/getnzbdownloads").data)["nzbDownloads"] print(downloads) self.assertEqual(3, len(downloads)) self.assertEqual("http://www.newznab1.com/details/newznab1result1.guid", downloads[0]["detailsLink"]) self.assertTrue(downloads[0]["response_successful"]) self.assertIsNone(downloads[2]["response_successful"]) #Don't know if redirection went well
def same_url(raw_url1, raw_url2): """Check if 2 URLs refer to the same primary resource `urltools.compare()` fails if the 2 URLs have different fragments. See issue #8 for details. The function treats a special case where the path is simply '/blog' to accommodate some blogs that refer to their posts via the fragment. Args: url1 (str): First URL to be compared url2 (str): Second URL Returns: bool: Whether the URLs are the same """ arxiv_exception = 'arxiv.org' fragment_identifier = '#' url1 = _parse_url(raw_url1) url2 = _parse_url(raw_url2) # If it's on arxiv, do some acrobatics if url1['netloc'] == url2['netloc'] == arxiv_exception: regex = '([^/a-z]+\.[^/a-z.]+)' return re.findall(regex, url1['path']) == re.findall(regex, url2['path']) else: return urltools.compare(_normalize_url(raw_url1), _normalize_url(raw_url2))
def startTest(self): with web.app.test_request_context('/'): with requests_mock.mock() as requestsMock: expectedItems = self.prepareSearchMocks(requestsMock, 1, 1) response = self.app.get("/api?t=search&q=query&cat=5030") entries, _, _ = newznab.NewzNab(Bunch.fromDict({"name": "forTest", "score": 0, "host": "host"})).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue(compare('http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query&cat=5030', calledUrls[0])) self.assertEqual("http://localhost:5075/getnzb?searchresultid=1", entries[0].link)
def testFullStackTvSearch(self, requestsMock): #Same as above but just with tvsearch, makes sure default sonarr searches work (breaking that is the worst...) web.app.template_folder = "../templates" expectedItems = self.prepareSearchMocks(requestsMock, 1, 1) with web.app.test_request_context('/'): response = self.app.get("/api?t=tvsearch&q=query&cat=5030") entries, _, _ = newznab.NewzNab( Bunch.fromDict({ "name": "forTest", "score": 0, "host": "host" })).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue( compare( 'http://www.newznab1.com/api?apikey=apikeyindexer.com&t=tvsearch&extended=1&offset=0&limit=100&q=query&cat=5030', calledUrls[0])) self.assertEqual("http://localhost:5075/getnzb?searchresultid=1", entries[0].link) # Download NZB config.settings.searching.nzbAccessType = "redirect" response = self.app.get("/getnzb?searchresultid=1") self.assertTrue("redirect" in response.data) config.settings.searching.nzbAccessType = "serve" requestsMock.register_uri('GET', re.compile(r'.*newznab1result1.link*'), text="NZB Data") response = self.app.get("/getnzb?searchresultid=1") self.assertEquals("NZB Data", response.data) # Download via API requestsMock.register_uri('GET', re.compile(r'.*newznab1result1.link*'), text="NZB Data") response = self.app.get("/api?t=get&id=%s" % entries[0].indexerguid) self.assertEquals("NZB Data", response.data) # Find downloaded NZBs in stats downloads = json.loads( self.app.get( "/internalapi/getnzbdownloads").data)["nzbDownloads"] print(downloads) self.assertEqual(3, len(downloads)) self.assertEqual( "http://www.newznab1.com/details/newznab1result1.guid", downloads[0]["detailsLink"]) self.assertTrue(downloads[0]["response_successful"]) self.assertIsNone( downloads[2] ["response_successful"]) # Don't know if redirection went well
def testSimpleQuerySearch(self, m): web.app.template_folder = "../templates" # Query only expectedItems = self.prepareSearchMocks(m, 1, 1) with web.app.test_request_context('/api?t=search&q=query&apikey=%s' % config.settings.main.apikey): response = web.api() entries, _, _ = newznab.NewzNab(Bunch.fromDict({"name": "forTest", "score": 0, "host": "host"})).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in m.request_history]) self.assertTrue(compare('http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query', calledUrls[0])) # Query with category expectedItems = self.prepareSearchMocks(m, 1, 1) with web.app.test_request_context('/api?t=search&q=query&apikey=%s&cat=2000' % config.settings.main.apikey): response = web.api() entries, _, _ = newznab.NewzNab(Bunch.fromDict({"name": "forTest", "score": 0, "host": "host"})).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in m.request_history]) self.assertTrue(compare('http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query&cat=2000', calledUrls[0]))
def testBaseUrl(self, requestsMock): web.app.template_folder = "../templates" config.settings.main.urlBase = "/nzbhydra" expectedItems = self.prepareSearchMocks(requestsMock, 1, 1) with web.app.test_request_context('/nzbhydra/'): response = self.app.get("/nzbhydra/api?t=search&q=query") entries, _, _ = newznab.NewzNab(Bunch.fromDict({"name": "forTest", "score": 0, "host": "host"})).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue(compare('http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query', calledUrls[0])) self.assertEqual("http://localhost:5075/nzbhydra/getnzb?searchresultid=1", entries[0].link)
def testIgnoreByCategories(self, m): web.app.template_folder = "../templates" config.settings.categories.categories[ "moviessd"].ignoreResults = "always" config.settings.categories.categories["xxx"].ignoreResults = "always" config.settings.categories.categories["pc"].ignoreResults = "internal" movieSdResult = mockbuilder.buildNewznabItem( title="result1", indexer_name="newznab1", categories=[2030] ) #MoviesSD: Is dismissed because its specific category is ignored xxxResult = mockbuilder.buildNewznabItem( title="result2", indexer_name="newznab1", categories=[6000] ) #XXX: Is dismissed because its category is ignored (no more or less specific category exists) movieResult = mockbuilder.buildNewznabItem( title="result3", indexer_name="newznab1", categories=[2000] ) #Is kept because more specific category Movies SD is ignored but not movies in general movieHdResult = mockbuilder.buildNewznabItem( title="result4", indexer_name="newznab1", categories=[2040] ) #MoviesHD: Is kept because the other specific category is ignored but not this one tvResult = mockbuilder.buildNewznabItem( title="result5", indexer_name="newznab1", categories=[ 5000 ]) #TV: Is kept because its category (tv) is never ignored pcResult = mockbuilder.buildNewznabItem( title="result6", indexer_name="newznab1", categories=[4000] ) # PC: Is kept because its category (tv) is only ignored for internal searches (but this is API) expectedItems = self.prepareSearchMocks(m, 1, newznabItems=[[ movieSdResult, xxxResult, movieResult, movieHdResult, tvResult, pcResult ]]) expectedItems = expectedItems[2:] #First two results will be dismissed with web.app.test_request_context('/api?t=search&q=query&apikey=%s' % config.settings.main.apikey): response = web.api() entries, _, _ = newznab.NewzNab( Bunch.fromDict({ "name": "forTest", "score": 0, "host": "host" })).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in m.request_history]) self.assertTrue( compare( 'http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query', calledUrls[0]), calledUrls[0])
def testSimpleQuerySearch(self, m): web.app.template_folder = "../templates" # Query only expectedItems = self.prepareSearchMocks(m, 1, 1) with web.app.test_request_context('/api?t=search&q=query&apikey=%s' % config.settings.main.apikey): response = web.api() entries, _, _ = newznab.NewzNab( Bunch.fromDict({ "name": "forTest", "score": 0, "host": "host" })).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in m.request_history]) self.assertTrue( compare( 'http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query', calledUrls[0])) # Query with category expectedItems = self.prepareSearchMocks(m, 1, 1) with web.app.test_request_context( '/api?t=search&q=query&apikey=%s&cat=2000' % config.settings.main.apikey): response = web.api() entries, _, _ = newznab.NewzNab( Bunch.fromDict({ "name": "forTest", "score": 0, "host": "host" })).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in m.request_history]) self.assertTrue( compare( 'http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query&cat=2000', calledUrls[0]))
def test_cas_enabled(self): """Verify that CAS is wired up properly when enabled""" with self.settings( CAS_ENABLED=True, CAS_SERVER_URL='http://example.com/login', ): # Because this won't actually work, we get in a redirect # loop, or at least, best as I can tell. response = self.client.get(reverse('cas_login')) self.assertTrue(compare( 'http://example.com/login?' 'service=http%3A%2F%2Ftestserver%2Fcas%2Flogin%3Fnext%3D%252F', response['location'] ))
def testRequiredAndForbiddenWords(self, m): web.app.template_folder = "../templates" config.settings.searching.forbiddenWords = "newznab1result1" # Will be removed from parsed results config.settings.categories.categories[ "movies"].forbiddenWords = "newznab1result2" # Will be removed from parsed results config.settings.searching.forbiddenWords = "newznab1result3" # Will be excluded in query config.settings.categories.categories[ "movies"].forbiddenWords = "newznab1result4" # Will be excluded in query config.settings.categories.categories[ "movies"].requiredWords = "newznab1result6" # Will be left config.settings.searching.requiredWords = "newznab1result7" # Will be left config.settings.categories.categories[ "movies"].applyRestrictions = "external" expectedItems = self.prepareSearchMocks(m, 1, 7, categories=[2000], skip=[( 1, 3, ), ( 1, 4, )]) expectedItems.pop(0) # The result with globally forbidden word expectedItems.pop(0) # The result with category forbidden word expectedItems.pop( 0 ) # The result with neither globally nor category required word (newznab1result5) with web.app.test_request_context( '/api?t=search&q=query&apikey=%s&cat=2000' % config.settings.main.apikey): response = web.api() entries, _, _ = newznab.NewzNab( Bunch.fromDict({ "name": "forTest", "score": 0, "host": "host" })).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in m.request_history]) self.assertTrue( compare( 'http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query+!newznab1result3+!newznab1result4&cat=2000', calledUrls[0]), calledUrls[0])
def startTest(self): with web.app.test_request_context("/"): with requests_mock.mock() as requestsMock: expectedItems = self.prepareSearchMocks(requestsMock, 1, 1) response = self.app.get("/api?t=search&q=query&cat=5030") entries, _, _ = newznab.NewzNab( Bunch.fromDict({"name": "forTest", "score": 0, "host": "host"}) ).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue( compare( "http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query&cat=5030", calledUrls[0], ) ) self.assertEqual("http://localhost:5075/getnzb?searchresultid=1", entries[0].link)
def testBaseUrl(self, requestsMock): web.app.template_folder = "../templates" config.settings.main.urlBase = "/nzbhydra" expectedItems = self.prepareSearchMocks(requestsMock, 1, 1) with web.app.test_request_context('/nzbhydra/'): response = self.app.get("/nzbhydra/api?t=search&q=query") entries, _, _ = newznab.NewzNab( Bunch.fromDict({ "name": "forTest", "score": 0, "host": "host" })).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in requestsMock.request_history]) self.assertTrue( compare( 'http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query', calledUrls[0])) self.assertEqual( "http://localhost:5075/nzbhydra/getnzb?searchresultid=1", entries[0].link)
def testRequiredAndForbiddenWords(self, m): web.app.template_folder = "../templates" config.settings.searching.forbiddenWords = "newznab1result1.title" # Will be removed from parsed results config.settings.categories.categories["movies"].forbiddenWords = "newznab1result2.title" # Will be removed from parsed results config.settings.searching.forbiddenWords = "newznab1result3" # Will be excluded in query config.settings.categories.categories["movies"].forbiddenWords = "newznab1result4" # Will be excluded in query config.settings.categories.categories["movies"].requiredWords = "newznab1result6.title" # Will be left config.settings.searching.requiredWords = "newznab1result7.title" # Will be left config.settings.categories.categories["movies"].applyRestrictions = "external" expectedItems = self.prepareSearchMocks(m, 1, 7, categories=[2000], skip=[(1, 3,), (1, 4,)]) expectedItems.pop(0) # The result with globally forbidden word expectedItems.pop(0) # The result with category forbidden word expectedItems.pop(0) # The result with neither globally nor category required word (newznab1result5) with web.app.test_request_context('/api?t=search&q=query&apikey=%s&cat=2000' % config.settings.main.apikey): response = web.api() entries, _, _ = newznab.NewzNab(Bunch.fromDict({"name": "forTest", "score": 0, "host": "host"})).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in m.request_history]) self.assertTrue(compare('http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query+!newznab1result3+!newznab1result4&cat=2000', calledUrls[0]), calledUrls[0])
def testIgnoreByCategories(self, m): web.app.template_folder = "../templates" config.settings.categories.categories["moviessd"].ignoreResults = "always" config.settings.categories.categories["xxx"].ignoreResults = "always" config.settings.categories.categories["pc"].ignoreResults = "internal" movieSdResult = mockbuilder.buildNewznabItem(title="result1", indexer_name="newznab1", categories=[2030]) #MoviesSD: Is dismissed because its specific category is ignored xxxResult = mockbuilder.buildNewznabItem(title="result2", indexer_name="newznab1", categories=[6000]) #XXX: Is dismissed because its category is ignored (no more or less specific category exists) movieResult = mockbuilder.buildNewznabItem(title="result3", indexer_name="newznab1", categories=[2000]) #Is kept because more specific category Movies SD is ignored but not movies in general movieHdResult = mockbuilder.buildNewznabItem(title="result4", indexer_name="newznab1", categories=[2040]) #MoviesHD: Is kept because the other specific category is ignored but not this one tvResult = mockbuilder.buildNewznabItem(title="result5", indexer_name="newznab1", categories=[5000]) #TV: Is kept because its category (tv) is never ignored pcResult = mockbuilder.buildNewznabItem(title="result6", indexer_name="newznab1", categories=[4000]) # PC: Is kept because its category (tv) is only ignored for internal searches (but this is API) expectedItems = self.prepareSearchMocks(m, 1, newznabItems=[[movieSdResult, xxxResult, movieResult, movieHdResult, tvResult, pcResult]]) expectedItems = expectedItems[2:] #First two results will be dismissed with web.app.test_request_context('/api?t=search&q=query&apikey=%s' % config.settings.main.apikey): response = web.api() entries, _, _ = newznab.NewzNab(Bunch.fromDict({"name": "forTest", "score": 0, "host": "host"})).parseXml(response.data) self.assertSearchResults(entries, expectedItems) calledUrls = sorted([x.url for x in m.request_history]) self.assertTrue(compare('http://www.newznab1.com/api?apikey=apikeyindexer.com&t=search&extended=1&offset=0&limit=100&q=query', calledUrls[0]), calledUrls[0])
def assertCatalogEntry(self, entry, build, data=None, link_params=None): data = data or {} link_params = link_params or {} # mandatory self.assertEqual(entry['package'], build.version.package.name) self.assertEqual(entry['version'], build.version.version_string) self.assertEqual( entry['dname'], build.version.displaynames[data.get('language', 'enu')].displayname) self.assertEqual( entry['desc'], build.version.descriptions[data.get('language', 'enu')].description) self.assertTrue( compare(entry['link'], url_for('nas.data', path=build.path, **link_params))) self.assertGreaterEqual(len(entry['thumbnail']), 1) self.assertEqual(entry['thumbnail'], [ url_for('nas.data', path=i.path, _external=True) for i in build.version.icons.values() ]) for t in entry['thumbnail']: self.assert200(self.client.get(t)) self.assertEqual( entry['qinst'], build.version.license is None and build.version.install_wizard is False) self.assertEqual( entry['qupgrade'], build.version.license is None and build.version.upgrade_wizard is False) self.assertEqual(entry['qstart'], (build.version.license is None and build.version.install_wizard is False and build.version.startable is not False)) self.assertEqual(entry['deppkgs'], build.version.dependencies) self.assertEqual(entry['conflictpkgs'], build.version.conflicts) # download download_response = self.client.get( entry['link'], follow_redirects=True, environ_base={'REMOTE_ADDR': '127.0.0.1'}) self.assert200(download_response) # md5 if build.md5: self.assertEqual(entry['md5'], build.md5) self.assertEqual(entry['md5'], hashlib.md5(download_response.data).hexdigest()) # screenshots if build.version.package.screenshots: self.assertEqual(entry['snapshot'], [ url_for('nas.data', path=s.path, _external=True) for s in build.version.package.screenshots ]) for s in build.version.package.screenshots: self.assert200( self.client.get(url_for('nas.data', path=s.path), follow_redirects=True)) else: self.assertNotIn('snapshot', entry) # report_url if build.version.report_url: entry['report_url'] = build.version.report_url entry['beta'] = True else: self.assertNotIn('report_url', entry) self.assertNotIn('beta', entry) # changelog if build.version.changelog: self.assertEqual(entry['changelog'], build.version.changelog) else: self.assertNotIn('changelog', entry) # distributor if build.version.distributor: self.assertEqual(entry['distributor'], build.version.distributor) else: self.assertNotIn('distributor', entry) # distributor_url if build.version.distributor_url: self.assertEqual(entry['distributor_url'], build.version.distributor_url) else: self.assertNotIn('distributor_url', entry) # maintainer if build.version.maintainer: self.assertEqual(entry['maintainer'], build.version.maintainer) else: self.assertNotIn('maintainer', entry) # maintainer_url if build.version.maintainer_url: self.assertEqual(entry['maintainer_url'], build.version.maintainer_url) else: self.assertNotIn('maintainer_url', entry) # depsers if build.version.service_dependencies: self.assertEqual( entry['depsers'], ' '.join([s.code for s in build.version.service_dependencies])) else: self.assertNotIn('depsers', entry) # conf_deppkgs if build.version.conf_dependencies: self.assertEqual(entry['conf_deppkgs'], build.version.conf_dependencies) else: self.assertNotIn('conf_deppkgs', entry) # conf_conxpkgs if build.version.conf_conflicts: self.assertEqual(entry['conf_conxpkgs'], build.version.conf_conflicts) else: self.assertNotIn('conf_conxpkgs', entry)
old_target_url = browser.current_url() # Create Controller object that connects to controller (EPICS IOC) controller = Controller(args.prefix, args.name) # monitor routing PVs and point webbrowser to the right URL accordingly. while(True): try: # get current desired page name page = controller.page # get URL of that page, using default when nothing is specified target_url = browser.get_default() if page=="" else controller.url(page) # if different from previously loaded URL, point browser to it if not urltools.compare(old_target_url, target_url): browser.point(target_url) old_target_url = target_url # reload browser if asked if 1 == controller.reload: controller.reload = 0 browser.refresh() except Exception as e: print e.message time.sleep(1)
def test_compare(): assert compare("http://examPLe.com:80/abc?x=&b=1", "http://eXAmple.com/abc?b=1") is True assert compare("http://examPLe.com:80/abc?x=&b=1", "http://eXAmple.com/abc/de?b=1") is False
def is_same_domain(url1, url2): return compare(url1, url2)
def assertCatalogEntry(self, entry, build, data=None, link_params=None): data = data or {} link_params = link_params or {} # mandatory self.assertEqual(entry['package'], build.version.package.name) self.assertEqual(entry['version'], build.version.version_string) self.assertEqual(entry['dname'], build.version.displaynames[data.get('language', 'enu')].displayname) self.assertEqual(entry['desc'], build.version.descriptions[data.get('language', 'enu')].description) self.assertTrue(compare(entry['link'], url_for('nas.data', path=build.path, **link_params))) self.assertGreaterEqual(len(entry['thumbnail']), 1) self.assertEqual(entry['thumbnail'], [url_for('nas.data', path=i.path, _external=True) for i in build.version.icons.values()]) for t in entry['thumbnail']: self.assert200(self.client.get(t)) self.assertEqual(entry['qinst'], build.version.license is None and build.version.install_wizard is False) self.assertEqual(entry['qupgrade'], build.version.license is None and build.version.upgrade_wizard is False) self.assertEqual(entry['qstart'], (build.version.license is None and build.version.install_wizard is False and build.version.startable is not False)) self.assertEqual(entry['deppkgs'], build.version.dependencies) self.assertEqual(entry['conflictpkgs'], build.version.conflicts) # download download_response = self.client.get(entry['link'], follow_redirects=True, environ_base={'REMOTE_ADDR': '127.0.0.1'}) self.assert200(download_response) # md5 if build.md5: self.assertEqual(entry['md5'], build.md5) self.assertEqual(entry['md5'], hashlib.md5(download_response.data).hexdigest()) # screenshots if build.version.package.screenshots: self.assertEqual(entry['snapshot'], [url_for('nas.data', path=s.path, _external=True) for s in build.version.package.screenshots]) for s in build.version.package.screenshots: self.assert200(self.client.get(url_for('nas.data', path=s.path), follow_redirects=True)) else: self.assertNotIn('snapshot', entry) # report_url if build.version.report_url: entry['report_url'] = build.version.report_url entry['beta'] = True else: self.assertNotIn('report_url', entry) self.assertNotIn('beta', entry) # changelog if build.version.changelog: self.assertEqual(entry['changelog'], build.version.changelog) else: self.assertNotIn('changelog', entry) # distributor if build.version.distributor: self.assertEqual(entry['distributor'], build.version.distributor) else: self.assertNotIn('distributor', entry) # distributor_url if build.version.distributor_url: self.assertEqual(entry['distributor_url'], build.version.distributor_url) else: self.assertNotIn('distributor_url', entry) # maintainer if build.version.maintainer: self.assertEqual(entry['maintainer'], build.version.maintainer) else: self.assertNotIn('maintainer', entry) # maintainer_url if build.version.maintainer_url: self.assertEqual(entry['maintainer_url'], build.version.maintainer_url) else: self.assertNotIn('maintainer_url', entry) # depsers if build.version.service_dependencies: self.assertEqual(entry['depsers'], ' '.join([s.code for s in build.version.service_dependencies])) else: self.assertNotIn('depsers', entry) # conf_deppkgs if build.version.conf_dependencies: self.assertEqual(entry['conf_deppkgs'], build.version.conf_dependencies) else: self.assertNotIn('conf_deppkgs', entry) # conf_conxpkgs if build.version.conf_conflicts: self.assertEqual(entry['conf_conxpkgs'], build.version.conf_conflicts) else: self.assertNotIn('conf_conxpkgs', entry)
def assertCatalogEntry(self, entry, build, data=None, link_params=None): data = data or {} link_params = link_params or {} # mandatory self.assertEqual(entry["package"], build.version.package.name) self.assertEqual(entry["version"], build.version.version_string) self.assertEqual( entry["dname"], build.version.displaynames[data.get("language", "enu")].displayname, ) self.assertEqual( entry["desc"], build.version.descriptions[data.get("language", "enu")].description, ) self.assertTrue( compare(entry["link"], url_for("nas.data", path=build.path, **link_params))) self.assertGreaterEqual(len(entry["thumbnail"]), 1) self.assertEqual( entry["thumbnail"], [ url_for("nas.data", path=i.path, _external=True) for i in build.version.icons.values() ], ) for t in entry["thumbnail"]: self.assert200(self.client.get(t)) self.assertEqual( entry["qinst"], build.version.license is None and build.version.install_wizard is False, ) self.assertEqual( entry["qupgrade"], build.version.license is None and build.version.upgrade_wizard is False, ) self.assertEqual( entry["qstart"], (build.version.license is None and build.version.install_wizard is False and build.version.startable is not False), ) self.assertEqual(entry["deppkgs"], build.version.dependencies) self.assertEqual(entry["conflictpkgs"], build.version.conflicts) # download download_response = self.client.get( entry["link"], follow_redirects=True, environ_base={"REMOTE_ADDR": "127.0.0.1"}, ) self.assert200(download_response) # md5 if build.md5: self.assertEqual(entry["md5"], build.md5) self.assertEqual(entry["md5"], hashlib.md5(download_response.data).hexdigest()) # screenshots if build.version.package.screenshots: self.assertEqual( entry["snapshot"], [ url_for("nas.data", path=s.path, _external=True) for s in build.version.package.screenshots ], ) for s in build.version.package.screenshots: self.assert200( self.client.get(url_for("nas.data", path=s.path), follow_redirects=True)) else: self.assertNotIn("snapshot", entry) # report_url if build.version.report_url: entry["report_url"] = build.version.report_url entry["beta"] = True else: self.assertNotIn("report_url", entry) self.assertNotIn("beta", entry) # changelog if build.version.changelog: self.assertEqual(entry["changelog"], build.version.changelog) else: self.assertNotIn("changelog", entry) # distributor if build.version.distributor: self.assertEqual(entry["distributor"], build.version.distributor) else: self.assertNotIn("distributor", entry) # distributor_url if build.version.distributor_url: self.assertEqual(entry["distributor_url"], build.version.distributor_url) else: self.assertNotIn("distributor_url", entry) # maintainer if build.version.maintainer: self.assertEqual(entry["maintainer"], build.version.maintainer) else: self.assertNotIn("maintainer", entry) # maintainer_url if build.version.maintainer_url: self.assertEqual(entry["maintainer_url"], build.version.maintainer_url) else: self.assertNotIn("maintainer_url", entry) # depsers if build.version.service_dependencies: self.assertEqual( entry["depsers"], " ".join([s.code for s in build.version.service_dependencies]), ) else: self.assertNotIn("depsers", entry) # conf_deppkgs if build.version.conf_dependencies: self.assertEqual(entry["conf_deppkgs"], build.version.conf_dependencies) else: self.assertNotIn("conf_deppkgs", entry) # conf_conxpkgs if build.version.conf_conflicts: self.assertEqual(entry["conf_conxpkgs"], build.version.conf_conflicts) else: self.assertNotIn("conf_conxpkgs", entry) # conf_privilege if build.version.conf_privilege: self.assertEqual(entry["conf_privilege"], build.version.conf_privilege) else: self.assertNotIn("conf_privilege", entry) # conf_resource if build.version.conf_resource: self.assertEqual(entry["conf_resource"], build.version.conf_resource) else: self.assertNotIn("conf_resource", entry)