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