How to use discover method in stryker-parent

Best JavaScript code snippet using stryker-parent

test_discovery.py

Source:test_discovery.py Github

copy

Full Screen

...652 # Badly-formatted version (when max_version omitted)653 test_exc({'min_version': '2.1', 'version': 'foo'})654 # Badly-formatted next_min_version655 test_exc({'next_min_version': 'bogus', 'not_before': '2019-07-01'})656 def test_endpoint_data_noauth_discover(self):657 mock = self.requests_mock.get(658 BASE_URL, status_code=200, json=V3_VERSION_LIST)659 self.requests_mock.get(660 V3_URL, status_code=200, json=V3_VERSION_ENTRY)661 plugin = noauth.NoAuth(endpoint=BASE_URL)662 data = plugin.get_endpoint_data(self.session)663 self.assertEqual(data.api_version, (3, 0))664 self.assertEqual(data.url, V3_URL)665 self.assertEqual(plugin.get_api_major_version(self.session), (3, 0))666 self.assertEqual(plugin.get_endpoint(self.session), BASE_URL)667 self.assertTrue(mock.called_once)668 def test_endpoint_data_noauth_versioned_discover(self):669 self.requests_mock.get(670 BASE_URL, status_code=200, json=V3_VERSION_LIST)671 self.requests_mock.get(672 V3_URL, status_code=200, json=V3_VERSION_ENTRY)673 plugin = noauth.NoAuth(endpoint=V3_URL)674 data = plugin.get_endpoint_data(self.session)675 self.assertEqual(data.api_version, (3, 0))676 self.assertEqual(data.url, V3_URL)677 self.assertEqual(plugin.get_api_major_version(self.session), (3, 0))678 self.assertEqual(plugin.get_endpoint(self.session), V3_URL)679 def test_endpoint_data_noauth_no_discover(self):680 plugin = noauth.NoAuth(endpoint=V3_URL)681 data = plugin.get_endpoint_data(682 self.session, discover_versions=False)683 self.assertEqual(data.api_version, (3, 0))684 self.assertEqual(data.url, V3_URL)685 self.assertEqual(plugin.get_api_major_version(self.session), (3, 0))686 self.assertEqual(plugin.get_endpoint(self.session), V3_URL)687 def test_endpoint_data_noauth_override_no_discover(self):688 plugin = noauth.NoAuth()689 data = plugin.get_endpoint_data(690 self.session, endpoint_override=V3_URL, discover_versions=False)691 self.assertEqual(data.api_version, (3, 0))692 self.assertEqual(data.url, V3_URL)693 self.assertEqual(694 plugin.get_endpoint(self.session, endpoint_override=V3_URL),695 V3_URL)696 def test_endpoint_data_http_basic_discover(self):697 self.requests_mock.get(698 BASE_URL, status_code=200, json=V3_VERSION_LIST)699 self.requests_mock.get(700 V3_URL, status_code=200, json=V3_VERSION_ENTRY)701 plugin = http_basic.HTTPBasicAuth(endpoint=V3_URL)702 data = plugin.get_endpoint_data(self.session)703 self.assertEqual(data.api_version, (3, 0))704 self.assertEqual(data.url, V3_URL)705 self.assertEqual(plugin.get_api_major_version(self.session), (3, 0))706 self.assertEqual(plugin.get_endpoint(self.session), V3_URL)707 def test_endpoint_data_http_basic_no_discover(self):708 plugin = http_basic.HTTPBasicAuth(endpoint=V3_URL)709 data = plugin.get_endpoint_data(710 self.session, discover_versions=False)711 self.assertEqual(data.api_version, (3, 0))712 self.assertEqual(data.url, V3_URL)713 self.assertEqual(plugin.get_api_major_version(self.session), (3, 0))714 self.assertEqual(plugin.get_endpoint(self.session), V3_URL)715 def test_endpoint_data_http_basic_override_no_discover(self):716 plugin = http_basic.HTTPBasicAuth()717 data = plugin.get_endpoint_data(718 self.session, endpoint_override=V3_URL, discover_versions=False)719 self.assertEqual(data.api_version, (3, 0))720 self.assertEqual(data.url, V3_URL)721 self.assertEqual(722 plugin.get_api_major_version(723 self.session, endpoint_override=V3_URL),724 (3, 0))725 self.assertEqual(726 plugin.get_endpoint(self.session, endpoint_override=V3_URL),727 V3_URL)728 def test_endpoint_data_noauth_adapter(self):729 self.requests_mock.get(730 BASE_URL, status_code=200, json=V3_VERSION_LIST)731 self.requests_mock.get(732 V3_URL, status_code=200, json=V3_VERSION_ENTRY)733 client = adapter.Adapter(734 session.Session(noauth.NoAuth()),735 endpoint_override=BASE_URL)736 data = client.get_endpoint_data()737 self.assertEqual(data.api_version, (3, 0))738 self.assertEqual(data.url, V3_URL)739 self.assertEqual(client.get_api_major_version(), (3, 0))740 self.assertEqual(client.get_endpoint(), BASE_URL)741 def test_endpoint_data_noauth_versioned_adapter(self):742 mock = self.requests_mock.get(743 V3_URL, status_code=200, json=V3_VERSION_ENTRY)744 client = adapter.Adapter(745 session.Session(noauth.NoAuth()),746 endpoint_override=V3_URL)747 data = client.get_endpoint_data()748 self.assertEqual(data.api_version, (3, 0))749 self.assertEqual(data.url, V3_URL)750 self.assertEqual(client.get_api_major_version(), (3, 0))751 self.assertEqual(client.get_endpoint(), V3_URL)752 self.assertTrue(mock.called_once)753 def test_endpoint_data_token_endpoint_discover(self):754 mock = self.requests_mock.get(755 V3_URL, status_code=200, json=V3_VERSION_ENTRY)756 plugin = token_endpoint.Token(endpoint=V3_URL, token='bogus')757 data = plugin.get_endpoint_data(self.session)758 self.assertEqual(data.api_version, (3, 0))759 self.assertEqual(data.url, V3_URL)760 self.assertEqual(plugin.get_api_major_version(self.session), (3, 0))761 self.assertEqual(plugin.get_endpoint(self.session), V3_URL)762 self.assertTrue(mock.called_once)763 def test_endpoint_data_token_endpoint_no_discover(self):764 plugin = token_endpoint.Token(endpoint=V3_URL, token='bogus')765 data = plugin.get_endpoint_data(self.session, discover_versions=False)766 self.assertEqual(data.api_version, (3, 0))767 self.assertEqual(data.url, V3_URL)768 self.assertEqual(plugin.get_api_major_version(self.session), (3, 0))769 self.assertEqual(plugin.get_endpoint(self.session), V3_URL)770 def test_endpoint_data_token_endpoint_adapter(self):771 mock = self.requests_mock.get(772 V3_URL, status_code=200, json=V3_VERSION_ENTRY)773 plugin = token_endpoint.Token(endpoint=V3_URL, token='bogus')774 client = adapter.Adapter(session.Session(plugin))775 data = client.get_endpoint_data()776 self.assertEqual(data.api_version, (3, 0))777 self.assertEqual(data.url, V3_URL)...

Full Screen

Full Screen

test_discover.py

Source:test_discover.py Github

copy

Full Screen

...40 fetchers.setDefaultFetcher(None)41 def runOneTest(self):42 expected_status = self.responses[-1].status43 try:44 discover.discover(self.url)45 except DiscoveryFailure, why:46 self.failUnlessEqual(why.http_response.status, expected_status)47 else:48 self.fail('Did not raise DiscoveryFailure')49### Tests for raising/catching exceptions from the fetcher through the50### discover function51# Python 2.5 displays a message when running this test, which is52# testing the behaviour in the presence of string exceptions,53# deprecated or not, so tell it no to complain when this particular54# string exception is raised.55import warnings56warnings.filterwarnings('ignore', 'raising a string.*', DeprecationWarning,57 r'^openid\.test\.test_discover$', 77)58class ErrorRaisingFetcher(object):59 """Just raise an exception when fetch is called"""60 def __init__(self, thing_to_raise):61 self.thing_to_raise = thing_to_raise62 def fetch(self, url, body=None, headers=None):63 raise self.thing_to_raise64class DidFetch(Exception):65 """Custom exception just to make sure it's not handled differently"""66class TestFetchException(datadriven.DataDrivenTestCase):67 """Make sure exceptions get passed through discover function from68 fetcher."""69 cases = [70 Exception(),71 DidFetch(),72 ValueError(),73 RuntimeError(),74 ]75 # String exceptions are finally gone from Python 2.6.76 if sys.version_info[:2] < (2, 6):77 cases.append('oi!')78 def __init__(self, exc):79 datadriven.DataDrivenTestCase.__init__(self, repr(exc))80 self.exc = exc81 def setUp(self):82 fetcher = ErrorRaisingFetcher(self.exc)83 fetchers.setDefaultFetcher(fetcher, wrap_exceptions=False)84 def tearDown(self):85 fetchers.setDefaultFetcher(None)86 def runOneTest(self):87 try:88 discover.discover('http://doesnt.matter/')89 except:90 exc = sys.exc_info()[1]91 if exc is None:92 # str exception93 self.failUnless(self.exc is sys.exc_info()[0])94 else:95 self.failUnless(self.exc is exc, exc)96 else:97 self.fail('Expected %r', self.exc)98### Tests for openid.consumer.discover.discover99class TestNormalization(unittest.TestCase):100 def testAddingProtocol(self):101 f = ErrorRaisingFetcher(RuntimeError())102 fetchers.setDefaultFetcher(f, wrap_exceptions=False)103 try:104 discover.discover('users.stompy.janrain.com:8000/x')105 except DiscoveryFailure, why:106 self.fail('failed to parse url with port correctly')107 except RuntimeError:108 pass #expected109 fetchers.setDefaultFetcher(None)110class DiscoveryMockFetcher(object):111 redirect = None112 def __init__(self, documents):113 self.documents = documents114 self.fetchlog = []115 def fetch(self, url, body=None, headers=None):116 self.fetchlog.append((url, body, headers))117 if self.redirect:118 final_url = self.redirect119 else:120 final_url = url121 try:122 ctype, body = self.documents[url]123 except KeyError:124 status = 404125 ctype = 'text/plain'126 body = ''127 else:128 status = 200129 return HTTPResponse(final_url, status, {'content-type': ctype}, body)130# from twisted.trial import unittest as trialtest131class BaseTestDiscovery(unittest.TestCase):132 id_url = "http://someuser.unittest/"133 documents = {}134 fetcherClass = DiscoveryMockFetcher135 def _checkService(self, s,136 server_url,137 claimed_id=None,138 local_id=None,139 canonical_id=None,140 types=None,141 used_yadis=False,142 display_identifier=None143 ):144 self.failUnlessEqual(server_url, s.server_url)145 if types == ['2.0 OP']:146 self.failIf(claimed_id)147 self.failIf(local_id)148 self.failIf(s.claimed_id)149 self.failIf(s.local_id)150 self.failIf(s.getLocalID())151 self.failIf(s.compatibilityMode())152 self.failUnless(s.isOPIdentifier())153 self.failUnlessEqual(s.preferredNamespace(),154 discover.OPENID_2_0_MESSAGE_NS)155 else:156 self.failUnlessEqual(claimed_id, s.claimed_id)157 self.failUnlessEqual(local_id, s.getLocalID())158 if used_yadis:159 self.failUnless(s.used_yadis, "Expected to use Yadis")160 else:161 self.failIf(s.used_yadis,162 "Expected to use old-style discovery")163 openid_types = {164 '1.1': discover.OPENID_1_1_TYPE,165 '1.0': discover.OPENID_1_0_TYPE,166 '2.0': discover.OPENID_2_0_TYPE,167 '2.0 OP': discover.OPENID_IDP_2_0_TYPE,168 }169 type_uris = [openid_types[t] for t in types]170 self.failUnlessEqual(type_uris, s.type_uris)171 self.failUnlessEqual(canonical_id, s.canonicalID)172 if s.canonicalID:173 self.failUnless(s.getDisplayIdentifier() != claimed_id)174 self.failUnless(s.getDisplayIdentifier() is not None)175 self.failUnlessEqual(display_identifier, s.getDisplayIdentifier())176 self.failUnlessEqual(s.claimed_id, s.canonicalID)177 self.failUnlessEqual(s.display_identifier or s.claimed_id, s.getDisplayIdentifier())178 def setUp(self):179 self.documents = self.documents.copy()180 self.fetcher = self.fetcherClass(self.documents)181 fetchers.setDefaultFetcher(self.fetcher)182 def tearDown(self):183 fetchers.setDefaultFetcher(None)184def readDataFile(filename):185 module_directory = os.path.dirname(os.path.abspath(__file__))186 filename = os.path.join(187 module_directory, 'data', 'test_discover', filename)188 return file(filename).read()189class TestDiscovery(BaseTestDiscovery):190 def _discover(self, content_type, data,191 expected_services, expected_id=None):192 if expected_id is None:193 expected_id = self.id_url194 self.documents[self.id_url] = (content_type, data)195 id_url, services = discover.discover(self.id_url)196 self.failUnlessEqual(expected_services, len(services))197 self.failUnlessEqual(expected_id, id_url)198 return services199 def test_404(self):200 self.failUnlessRaises(DiscoveryFailure,201 discover.discover, self.id_url + '/404')202 def test_noOpenID(self):203 services = self._discover(content_type='text/plain',204 data="junk",205 expected_services=0)206 services = self._discover(207 content_type='text/html',208 data=readDataFile('openid_no_delegate.html'),209 expected_services=1,210 )211 self._checkService(212 services[0],213 used_yadis=False,214 types=['1.1'],215 server_url="http://www.myopenid.com/server",216 claimed_id=self.id_url,217 local_id=self.id_url,218 )219 def test_html1(self):220 services = self._discover(221 content_type='text/html',222 data=readDataFile('openid.html'),223 expected_services=1)224 self._checkService(225 services[0],226 used_yadis=False,227 types=['1.1'],228 server_url="http://www.myopenid.com/server",229 claimed_id=self.id_url,230 local_id='http://smoker.myopenid.com/',231 display_identifier=self.id_url,232 )233 def test_html1Fragment(self):234 """Ensure that the Claimed Identifier does not have a fragment235 if one is supplied in the User Input."""236 content_type = 'text/html'237 data = readDataFile('openid.html')238 expected_services = 1239 self.documents[self.id_url] = (content_type, data)240 expected_id = self.id_url241 self.id_url = self.id_url + '#fragment'242 id_url, services = discover.discover(self.id_url)243 self.failUnlessEqual(expected_services, len(services))244 self.failUnlessEqual(expected_id, id_url)245 self._checkService(246 services[0],247 used_yadis=False,248 types=['1.1'],249 server_url="http://www.myopenid.com/server",250 claimed_id=expected_id,251 local_id='http://smoker.myopenid.com/',252 display_identifier=expected_id,253 )254 def test_html2(self):255 services = self._discover(256 content_type='text/html',257 data=readDataFile('openid2.html'),258 expected_services=1,259 )260 self._checkService(261 services[0],262 used_yadis=False,263 types=['2.0'],264 server_url="http://www.myopenid.com/server",265 claimed_id=self.id_url,266 local_id='http://smoker.myopenid.com/',267 display_identifier=self.id_url,268 )269 def test_html1And2(self):270 services = self._discover(271 content_type='text/html',272 data=readDataFile('openid_1_and_2.html'),273 expected_services=2,274 )275 for t, s in zip(['2.0', '1.1'], services):276 self._checkService(277 s,278 used_yadis=False,279 types=[t],280 server_url="http://www.myopenid.com/server",281 claimed_id=self.id_url,282 local_id='http://smoker.myopenid.com/',283 display_identifier=self.id_url,284 )285 def test_yadisEmpty(self):286 services = self._discover(content_type='application/xrds+xml',287 data=readDataFile('yadis_0entries.xml'),288 expected_services=0)289 def test_htmlEmptyYadis(self):290 """HTML document has discovery information, but points to an291 empty Yadis document."""292 # The XRDS document pointed to by "openid_and_yadis.html"293 self.documents[self.id_url + 'xrds'] = (294 'application/xrds+xml', readDataFile('yadis_0entries.xml'))295 services = self._discover(content_type='text/html',296 data=readDataFile('openid_and_yadis.html'),297 expected_services=1)298 self._checkService(299 services[0],300 used_yadis=False,301 types=['1.1'],302 server_url="http://www.myopenid.com/server",303 claimed_id=self.id_url,304 local_id='http://smoker.myopenid.com/',305 display_identifier=self.id_url,306 )307 def test_yadis1NoDelegate(self):308 services = self._discover(content_type='application/xrds+xml',309 data=readDataFile('yadis_no_delegate.xml'),310 expected_services=1)311 self._checkService(312 services[0],313 used_yadis=True,314 types=['1.0'],315 server_url="http://www.myopenid.com/server",316 claimed_id=self.id_url,317 local_id=self.id_url,318 display_identifier=self.id_url,319 )320 def test_yadis2NoLocalID(self):321 services = self._discover(322 content_type='application/xrds+xml',323 data=readDataFile('openid2_xrds_no_local_id.xml'),324 expected_services=1,325 )326 self._checkService(327 services[0],328 used_yadis=True,329 types=['2.0'],330 server_url="http://www.myopenid.com/server",331 claimed_id=self.id_url,332 local_id=self.id_url,333 display_identifier=self.id_url,334 )335 def test_yadis2(self):336 services = self._discover(337 content_type='application/xrds+xml',338 data=readDataFile('openid2_xrds.xml'),339 expected_services=1,340 )341 self._checkService(342 services[0],343 used_yadis=True,344 types=['2.0'],345 server_url="http://www.myopenid.com/server",346 claimed_id=self.id_url,347 local_id='http://smoker.myopenid.com/',348 display_identifier=self.id_url,349 )350 def test_yadis2OP(self):351 services = self._discover(352 content_type='application/xrds+xml',353 data=readDataFile('yadis_idp.xml'),354 expected_services=1,355 )356 self._checkService(357 services[0],358 used_yadis=True,359 types=['2.0 OP'],360 server_url="http://www.myopenid.com/server",361 display_identifier=self.id_url,362 )363 def test_yadis2OPDelegate(self):364 """The delegate tag isn't meaningful for OP entries."""365 services = self._discover(366 content_type='application/xrds+xml',367 data=readDataFile('yadis_idp_delegate.xml'),368 expected_services=1,369 )370 self._checkService(371 services[0],372 used_yadis=True,373 types=['2.0 OP'],374 server_url="http://www.myopenid.com/server",375 display_identifier=self.id_url,376 )377 def test_yadis2BadLocalID(self):378 self.failUnlessRaises(DiscoveryFailure, self._discover,379 content_type='application/xrds+xml',380 data=readDataFile('yadis_2_bad_local_id.xml'),381 expected_services=1,382 )383 def test_yadis1And2(self):384 services = self._discover(385 content_type='application/xrds+xml',386 data=readDataFile('openid_1_and_2_xrds.xml'),387 expected_services=1,388 )389 self._checkService(390 services[0],391 used_yadis=True,392 types=['2.0', '1.1'],393 server_url="http://www.myopenid.com/server",394 claimed_id=self.id_url,395 local_id='http://smoker.myopenid.com/',396 display_identifier=self.id_url,397 )398 def test_yadis1And2BadLocalID(self):399 self.failUnlessRaises(DiscoveryFailure, self._discover,400 content_type='application/xrds+xml',401 data=readDataFile('openid_1_and_2_xrds_bad_delegate.xml'),402 expected_services=1,403 )404class MockFetcherForXRIProxy(object):405 def __init__(self, documents, proxy_url=xrires.DEFAULT_PROXY):406 self.documents = documents407 self.fetchlog = []408 self.proxy_url = None409 def fetch(self, url, body=None, headers=None):410 self.fetchlog.append((url, body, headers))411 u = urlsplit(url)412 proxy_host = u[1]413 xri = u[2]414 query = u[3]415 if not headers and not query:416 raise ValueError("No headers or query; you probably didn't "417 "mean to do that.")418 if xri.startswith('/'):419 xri = xri[1:]420 try:421 ctype, body = self.documents[xri]422 except KeyError:423 status = 404424 ctype = 'text/plain'425 body = ''426 else:427 status = 200428 return HTTPResponse(url, status, {'content-type': ctype}, body)429class TestXRIDiscovery(BaseTestDiscovery):430 fetcherClass = MockFetcherForXRIProxy431 documents = {'=smoker': ('application/xrds+xml',432 readDataFile('yadis_2entries_delegate.xml')),433 '=smoker*bad': ('application/xrds+xml',434 readDataFile('yadis_another_delegate.xml')) }435 def test_xri(self):436 user_xri, services = discover.discoverXRI('=smoker')437 self._checkService(438 services[0],439 used_yadis=True,440 types=['1.0'],441 server_url="http://www.myopenid.com/server",442 claimed_id=XRI("=!1000"),443 canonical_id=XRI("=!1000"),444 local_id='http://smoker.myopenid.com/',445 display_identifier='=smoker'446 )447 self._checkService(448 services[1],449 used_yadis=True,450 types=['1.0'],451 server_url="http://www.livejournal.com/openid/server.bml",452 claimed_id=XRI("=!1000"),453 canonical_id=XRI("=!1000"),454 local_id='http://frank.livejournal.com/',455 display_identifier='=smoker'456 )457 def test_xri_normalize(self):458 user_xri, services = discover.discoverXRI('xri://=smoker')459 self._checkService(460 services[0],461 used_yadis=True,462 types=['1.0'],463 server_url="http://www.myopenid.com/server",464 claimed_id=XRI("=!1000"),465 canonical_id=XRI("=!1000"),466 local_id='http://smoker.myopenid.com/',467 display_identifier='=smoker'468 )469 self._checkService(470 services[1],471 used_yadis=True,472 types=['1.0'],473 server_url="http://www.livejournal.com/openid/server.bml",474 claimed_id=XRI("=!1000"),475 canonical_id=XRI("=!1000"),476 local_id='http://frank.livejournal.com/',477 display_identifier='=smoker'478 )479 def test_xriNoCanonicalID(self):480 user_xri, services = discover.discoverXRI('=smoker*bad')481 self.failIf(services)482 def test_useCanonicalID(self):483 """When there is no delegate, the CanonicalID should be used with XRI.484 """485 endpoint = discover.OpenIDServiceEndpoint()486 endpoint.claimed_id = XRI("=!1000")487 endpoint.canonicalID = XRI("=!1000")488 self.failUnlessEqual(endpoint.getLocalID(), XRI("=!1000"))489class TestXRIDiscoveryIDP(BaseTestDiscovery):490 fetcherClass = MockFetcherForXRIProxy491 documents = {'=smoker': ('application/xrds+xml',492 readDataFile('yadis_2entries_idp.xml')) }493 def test_xri(self):494 user_xri, services = discover.discoverXRI('=smoker')495 self.failUnless(services, "Expected services, got zero")496 self.failUnlessEqual(services[0].server_url,497 "http://www.livejournal.com/openid/server.bml")498class TestPreferredNamespace(datadriven.DataDrivenTestCase):499 def __init__(self, expected_ns, type_uris):500 datadriven.DataDrivenTestCase.__init__(501 self, 'Expecting %s from %s' % (expected_ns, type_uris))502 self.expected_ns = expected_ns503 self.type_uris = type_uris504 def runOneTest(self):505 endpoint = discover.OpenIDServiceEndpoint()506 endpoint.type_uris = self.type_uris507 actual_ns = endpoint.preferredNamespace()508 self.failUnlessEqual(actual_ns, self.expected_ns)509 cases = [510 (message.OPENID1_NS, []),511 (message.OPENID1_NS, ['http://jyte.com/']),512 (message.OPENID1_NS, [discover.OPENID_1_0_TYPE]),513 (message.OPENID1_NS, [discover.OPENID_1_1_TYPE]),514 (message.OPENID2_NS, [discover.OPENID_2_0_TYPE]),515 (message.OPENID2_NS, [discover.OPENID_IDP_2_0_TYPE]),516 (message.OPENID2_NS, [discover.OPENID_2_0_TYPE,517 discover.OPENID_1_0_TYPE]),518 (message.OPENID2_NS, [discover.OPENID_1_0_TYPE,519 discover.OPENID_2_0_TYPE]),520 ]521class TestIsOPIdentifier(unittest.TestCase):522 def setUp(self):523 self.endpoint = discover.OpenIDServiceEndpoint()524 def test_none(self):525 self.failIf(self.endpoint.isOPIdentifier())526 def test_openid1_0(self):527 self.endpoint.type_uris = [discover.OPENID_1_0_TYPE]528 self.failIf(self.endpoint.isOPIdentifier())529 def test_openid1_1(self):530 self.endpoint.type_uris = [discover.OPENID_1_1_TYPE]531 self.failIf(self.endpoint.isOPIdentifier())532 def test_openid2(self):533 self.endpoint.type_uris = [discover.OPENID_2_0_TYPE]534 self.failIf(self.endpoint.isOPIdentifier())535 def test_openid2OP(self):536 self.endpoint.type_uris = [discover.OPENID_IDP_2_0_TYPE]537 self.failUnless(self.endpoint.isOPIdentifier())538 def test_multipleMissing(self):539 self.endpoint.type_uris = [discover.OPENID_2_0_TYPE,540 discover.OPENID_1_0_TYPE]541 self.failIf(self.endpoint.isOPIdentifier())542 def test_multiplePresent(self):543 self.endpoint.type_uris = [discover.OPENID_2_0_TYPE,544 discover.OPENID_1_0_TYPE,545 discover.OPENID_IDP_2_0_TYPE]546 self.failUnless(self.endpoint.isOPIdentifier())547class TestFromOPEndpointURL(unittest.TestCase):548 def setUp(self):549 self.op_endpoint_url = 'http://example.com/op/endpoint'550 self.endpoint = discover.OpenIDServiceEndpoint.fromOPEndpointURL(551 self.op_endpoint_url)552 def test_isOPEndpoint(self):553 self.failUnless(self.endpoint.isOPIdentifier())554 def test_noIdentifiers(self):555 self.failUnlessEqual(self.endpoint.getLocalID(), None)556 self.failUnlessEqual(self.endpoint.claimed_id, None)557 def test_compatibility(self):558 self.failIf(self.endpoint.compatibilityMode())559 def test_canonicalID(self):560 self.failUnlessEqual(self.endpoint.canonicalID, None)561 def test_serverURL(self):562 self.failUnlessEqual(self.endpoint.server_url, self.op_endpoint_url)563class TestDiscoverFunction(unittest.TestCase):564 def setUp(self):565 self._old_discoverURI = discover.discoverURI566 self._old_discoverXRI = discover.discoverXRI567 discover.discoverXRI = self.discoverXRI568 discover.discoverURI = self.discoverURI569 def tearDown(self):570 discover.discoverURI = self._old_discoverURI571 discover.discoverXRI = self._old_discoverXRI572 def discoverXRI(self, identifier):573 return 'XRI'574 def discoverURI(self, identifier):575 return 'URI'576 def test_uri(self):577 self.failUnlessEqual('URI', discover.discover('http://woo!'))578 def test_uriForBogus(self):579 self.failUnlessEqual('URI', discover.discover('not a URL or XRI'))580 def test_xri(self):581 self.failUnlessEqual('XRI', discover.discover('xri://=something'))582 def test_xriChar(self):583 self.failUnlessEqual('XRI', discover.discover('=something'))584class TestEndpointSupportsType(unittest.TestCase):585 def setUp(self):586 self.endpoint = discover.OpenIDServiceEndpoint()587 def failUnlessSupportsOnly(self, *types):588 for t in [589 'foo',590 discover.OPENID_1_1_TYPE,591 discover.OPENID_1_0_TYPE,592 discover.OPENID_2_0_TYPE,593 discover.OPENID_IDP_2_0_TYPE,594 ]:595 if t in types:596 self.failUnless(self.endpoint.supportsType(t),597 "Must support %r" % (t,))...

Full Screen

Full Screen

interfaces.py

Source:interfaces.py Github

copy

Full Screen

...22 """ Return an iterable with discovered time periods:23 >>> from zope.component import getUtility24 >>> from eea.alchemy.interfaces import IDiscoverUtility25 >>> discover = getUtility(IDiscoverUtility, name='temporalCoverage')26 >>> res = discover('Publication 1990-2010 until 2010 - 2030')27 res28 [{29 'count': '1',30 'relevance': '100.0',31 'type': 'Time',32 'text': '1990-2010'33 }, ...]34 >>> res.next()['text']35 '1990-2010'36 >>> res.next()['text']37 '2010-2030'38 Keyword arguments:39 text -- string to look in for temporal coverage40 """41class IDiscoverGeographicalCoverage(IDiscoverUtility):42 """ Auto discover geographical coverage from text43 """44 def __call__(kwargs):45 """ Return an iterable with discovered geotags46 >>> from zope.component import getUtility47 >>> from eea.alchemy.interfaces import IDiscoverUtility48 >>> discover = getUtility(IDiscoverUtility, name='location')49 >>> res = discover("12345",50 ... 'Formation of new land cover in the region of Valencia, Spain')51 res52 [{53 'count': '1',54 'relevance': '0.90',55 'type': 'Country',56 'text': 'Spain'57 }, ...]58 #TODO update test when AlchemyAPI replacement is integrated59 When an AlchemyAPI replacement will be ready,60 something like res.next()['text'] should produce 'Spain',61 and then again 'Valencia'62 Keyword arguments:63 key -- Alchemy API authentication key64 text -- string to look in for geotags65 """66class IDiscoverKeywords(IDiscoverUtility):67 """ Auto discover keywords from text68 """69 def __call__(kwargs):70 """ Return an iterable with discovered keywords71 >>> from zope.component import getUtility72 >>> from eea.alchemy.interfaces import IDiscoverUtility73 >>> discover = getUtility(IDiscoverUtility, name='subject')74 >>> res = discover("12345",75 ... 'Formation of new land cover in the region of Valencia, Spain')76 res77 [{78 'relevance': '0.99',79 'text': 'new land cover'80 }, ...]81 #TODO update test when AlchemyAPI replacement is integrated82 When an AlchemyAPI replacement will be ready,83 something like res.next()['text'] should produce 'new land cover'84 Keyword arguments:85 key -- Alchemy API authentication key86 text -- string to look in for geotags87 """88class IDiscoverLinks(IDiscoverUtility):89 """ Extract internal links from text90 """91 def __call__(kwargs):92 """ Return an iterable with discovered links93 >>> from zope.component import getUtility94 >>> from eea.alchemy.interfaces import IDiscoverUtility95 >>> discover = getUtility(IDiscoverUtility, name='links')96 >>> text = "<p>"97 >>> text += "<a href='http://example.com/a?x=1&y=2#tab-2'>This</a>"98 >>> text += "also <a href='https://example.com/b/c/d#tab-3'>exampl</a> "99 >>> text += "also <a href='https://example.com/b/download.pdf'>dow</a> "100 >>> text += "while <a href='http://foobar.com/b/c/d/'>this external</a>"101 >>> text += " article shouldn't be included in the results. "102 >>> text += "Neither this: https://example.com/a/b as it's not a link"103 >>> text += "</p>"104 >>> res = discover(text, match="http://example.com")105 res106 [{107 'count': '1',108 'relevance': '100.0',109 'type': 'Link',110 'text': 'a'111 }, ...]112 >>> res.next()['text']113 'a'114 >>> res.next()['text']115 'b/c/d'116 >>> res.next()['text']117 'b/download.pdf'118 >>> res.next()119 Traceback (most recent call last):120 ...121 StopIteration122 Keyword arguments:123 text -- search in text124 match -- filter links by this match expression125 """126class IDiscoverIframes(IDiscoverUtility):127 """ Extract iframe links from text128 """129 def __call__(kwargs):130 """ Return an iterable with discovered links extracted from iframea src131 >>> from zope.component import getUtility132 >>> from eea.alchemy.interfaces import IDiscoverUtility133 >>> discover = getUtility(IDiscoverUtility, name='iframes')134 >>> text = "<p>"135 >>> text += "<iframe src='http://example.com/a/b/c/embed-chart?a=1&b=2'"136 >>> text += " width='1500' height='400'></iframe>"137 >>> text += "more text here <br /> <br />"138 >>> text += "<iframe src='http://example.com/a/embed-dashboard?d=1&b=2'"139 >>> text += " width='1240' height='1400'></iframe>"140 >>> text += "And a link: https://example.com/a/b as it's not a link"141 >>> text += "</p>"142 >>> res = discover(text, match="http://example.com")143 res144 [{145 'count': '1',146 'relevance': '100.0',147 'type': 'Link',148 'text': 'a/b/c'149 }, ...]150 >>> res.next()['text']151 'a/b/c/embed-chart'152 >>> res.next()['text']153 'a/embed-dashboard'154 >>> res.next()155 Traceback (most recent call last):156 ......

Full Screen

Full Screen

test_discover_runner.py

Source:test_discover_runner.py Github

copy

Full Screen

1import os2from argparse import ArgumentParser3from contextlib import contextmanager4from unittest import TestSuite, TextTestRunner, defaultTestLoader5from django.test import TestCase6from django.test.runner import DiscoverRunner7@contextmanager8def change_cwd(directory):9 current_dir = os.path.abspath(os.path.dirname(__file__))10 new_dir = os.path.join(current_dir, directory)11 old_cwd = os.getcwd()12 os.chdir(new_dir)13 try:14 yield15 finally:16 os.chdir(old_cwd)17class DiscoverRunnerTest(TestCase):18 def test_init_debug_mode(self):19 runner = DiscoverRunner()20 self.assertFalse(runner.debug_mode)21 def test_add_arguments_debug_mode(self):22 parser = ArgumentParser()23 DiscoverRunner.add_arguments(parser)24 ns = parser.parse_args([])25 self.assertFalse(ns.debug_mode)26 ns = parser.parse_args(["--debug-mode"])27 self.assertTrue(ns.debug_mode)28 def test_dotted_test_module(self):29 count = DiscoverRunner().build_suite(30 ["test_discovery_sample.tests_sample"],31 ).countTestCases()32 self.assertEqual(count, 6)33 def test_dotted_test_class_vanilla_unittest(self):34 count = DiscoverRunner().build_suite(35 ["test_discovery_sample.tests_sample.TestVanillaUnittest"],36 ).countTestCases()37 self.assertEqual(count, 1)38 def test_dotted_test_class_django_testcase(self):39 count = DiscoverRunner().build_suite(40 ["test_discovery_sample.tests_sample.TestDjangoTestCase"],41 ).countTestCases()42 self.assertEqual(count, 1)43 def test_dotted_test_method_django_testcase(self):44 count = DiscoverRunner().build_suite(45 ["test_discovery_sample.tests_sample.TestDjangoTestCase.test_sample"],46 ).countTestCases()47 self.assertEqual(count, 1)48 def test_pattern(self):49 count = DiscoverRunner(50 pattern="*_tests.py",51 ).build_suite(["test_discovery_sample"]).countTestCases()52 self.assertEqual(count, 1)53 def test_file_path(self):54 with change_cwd(".."):55 count = DiscoverRunner().build_suite(56 ["test_discovery_sample/"],57 ).countTestCases()58 self.assertEqual(count, 7)59 def test_empty_label(self):60 """61 If the test label is empty, discovery should happen on the current62 working directory.63 """64 with change_cwd("."):65 suite = DiscoverRunner().build_suite([])66 self.assertEqual(67 suite._tests[0].id().split(".")[0],68 os.path.basename(os.getcwd()),69 )70 def test_empty_test_case(self):71 count = DiscoverRunner().build_suite(72 ["test_discovery_sample.tests_sample.EmptyTestCase"],73 ).countTestCases()74 self.assertEqual(count, 0)75 def test_discovery_on_package(self):76 count = DiscoverRunner().build_suite(77 ["test_discovery_sample.tests"],78 ).countTestCases()79 self.assertEqual(count, 1)80 def test_ignore_adjacent(self):81 """82 When given a dotted path to a module, unittest discovery searches83 not just the module, but also the directory containing the module.84 This results in tests from adjacent modules being run when they85 should not. The discover runner avoids this behavior.86 """87 count = DiscoverRunner().build_suite(88 ["test_discovery_sample.empty"],89 ).countTestCases()90 self.assertEqual(count, 0)91 def test_testcase_ordering(self):92 with change_cwd(".."):93 suite = DiscoverRunner().build_suite(["test_discovery_sample/"])94 self.assertEqual(95 suite._tests[0].__class__.__name__,96 'TestDjangoTestCase',97 msg="TestDjangoTestCase should be the first test case")98 self.assertEqual(99 suite._tests[1].__class__.__name__,100 'TestZimpleTestCase',101 msg="TestZimpleTestCase should be the second test case")102 # All others can follow in unspecified order, including doctests103 self.assertIn('DocTestCase', [t.__class__.__name__ for t in suite._tests[2:]])104 def test_duplicates_ignored(self):105 """106 Tests shouldn't be discovered twice when discovering on overlapping paths.107 """108 base_app = 'forms_tests'109 sub_app = 'forms_tests.field_tests'110 with self.modify_settings(INSTALLED_APPS={'append': sub_app}):111 single = DiscoverRunner().build_suite([base_app]).countTestCases()112 dups = DiscoverRunner().build_suite([base_app, sub_app]).countTestCases()113 self.assertEqual(single, dups)114 def test_reverse(self):115 """116 Reverse should reorder tests while maintaining the grouping specified117 by ``DiscoverRunner.reorder_by``.118 """119 runner = DiscoverRunner(reverse=True)120 suite = runner.build_suite(121 test_labels=('test_discovery_sample', 'test_discovery_sample2'))122 self.assertIn('test_discovery_sample2', next(iter(suite)).id(),123 msg="Test labels should be reversed.")124 suite = runner.build_suite(test_labels=('test_discovery_sample2',))125 suite = tuple(suite)126 self.assertIn('DjangoCase', suite[0].id(),127 msg="Test groups should not be reversed.")128 self.assertIn('SimpleCase', suite[4].id(),129 msg="Test groups order should be preserved.")130 self.assertIn('DjangoCase2', suite[0].id(),131 msg="Django test cases should be reversed.")132 self.assertIn('SimpleCase2', suite[4].id(),133 msg="Simple test cases should be reversed.")134 self.assertIn('UnittestCase2', suite[8].id(),135 msg="Unittest test cases should be reversed.")136 self.assertIn('test_2', suite[0].id(),137 msg="Methods of Django cases should be reversed.")138 self.assertIn('test_2', suite[4].id(),139 msg="Methods of simple cases should be reversed.")140 self.assertIn('test_2', suite[8].id(),141 msg="Methods of unittest cases should be reversed.")142 def test_overridable_get_test_runner_kwargs(self):143 self.assertIsInstance(DiscoverRunner().get_test_runner_kwargs(), dict)144 def test_overridable_test_suite(self):145 self.assertEqual(DiscoverRunner().test_suite, TestSuite)146 def test_overridable_test_runner(self):147 self.assertEqual(DiscoverRunner().test_runner, TextTestRunner)148 def test_overridable_test_loader(self):149 self.assertEqual(DiscoverRunner().test_loader, defaultTestLoader)150 def test_tags(self):151 runner = DiscoverRunner(tags=['core'])152 self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 1)153 runner = DiscoverRunner(tags=['fast'])154 self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 2)155 runner = DiscoverRunner(tags=['slow'])156 self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 2)157 def test_exclude_tags(self):158 runner = DiscoverRunner(tags=['fast'], exclude_tags=['core'])159 self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 1)160 runner = DiscoverRunner(tags=['fast'], exclude_tags=['slow'])161 self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 0)162 runner = DiscoverRunner(exclude_tags=['slow'])...

Full Screen

Full Screen

discover_unittest.py

Source:discover_unittest.py Github

copy

Full Screen

1# Copyright 2013 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4from __future__ import absolute_import5from __future__ import division6from __future__ import print_function7import os8import unittest9import six10from py_utils import discover11class DiscoverTest(unittest.TestCase):12 def setUp(self):13 self._base_dir = os.path.join(os.path.dirname(__file__), 'test_data')14 self._start_dir = os.path.join(self._base_dir, 'discoverable_classes')15 self._base_class = Exception16 def testDiscoverClassesWithIndexByModuleName(self):17 classes = discover.DiscoverClasses(self._start_dir,18 self._base_dir,19 self._base_class,20 index_by_class_name=False)21 actual_classes = dict(22 (name, cls.__name__) for name, cls in six.iteritems(classes))23 expected_classes = {24 'another_discover_dummyclass': 'DummyExceptionWithParameterImpl1',25 'discover_dummyclass': 'DummyException',26 'parameter_discover_dummyclass': 'DummyExceptionWithParameterImpl2'27 }28 self.assertEqual(actual_classes, expected_classes)29 def testDiscoverDirectlyConstructableClassesWithIndexByClassName(self):30 classes = discover.DiscoverClasses(self._start_dir,31 self._base_dir,32 self._base_class,33 directly_constructable=True)34 actual_classes = dict(35 (name, cls.__name__) for name, cls in six.iteritems(classes))36 expected_classes = {37 'dummy_exception': 'DummyException',38 'dummy_exception_impl1': 'DummyExceptionImpl1',39 'dummy_exception_impl2': 'DummyExceptionImpl2',40 }41 self.assertEqual(actual_classes, expected_classes)42 def testDiscoverClassesWithIndexByClassName(self):43 classes = discover.DiscoverClasses(self._start_dir, self._base_dir,44 self._base_class)45 actual_classes = dict(46 (name, cls.__name__) for name, cls in six.iteritems(classes))47 expected_classes = {48 'dummy_exception': 'DummyException',49 'dummy_exception_impl1': 'DummyExceptionImpl1',50 'dummy_exception_impl2': 'DummyExceptionImpl2',51 'dummy_exception_with_parameter_impl1':52 'DummyExceptionWithParameterImpl1',53 'dummy_exception_with_parameter_impl2':54 'DummyExceptionWithParameterImpl2'55 }56 self.assertEqual(actual_classes, expected_classes)57 def testDiscoverClassesWithPatternAndIndexByModule(self):58 classes = discover.DiscoverClasses(self._start_dir,59 self._base_dir,60 self._base_class,61 pattern='another*',62 index_by_class_name=False)63 actual_classes = dict(64 (name, cls.__name__) for name, cls in six.iteritems(classes))65 expected_classes = {66 'another_discover_dummyclass': 'DummyExceptionWithParameterImpl1'67 }68 self.assertEqual(actual_classes, expected_classes)69 def testDiscoverDirectlyConstructableClassesWithPatternAndIndexByClassName(70 self):71 classes = discover.DiscoverClasses(self._start_dir,72 self._base_dir,73 self._base_class,74 pattern='another*',75 directly_constructable=True)76 actual_classes = dict(77 (name, cls.__name__) for name, cls in six.iteritems(classes))78 expected_classes = {79 'dummy_exception_impl1': 'DummyExceptionImpl1',80 'dummy_exception_impl2': 'DummyExceptionImpl2',81 }82 self.assertEqual(actual_classes, expected_classes)83 def testDiscoverClassesWithPatternAndIndexByClassName(self):84 classes = discover.DiscoverClasses(self._start_dir,85 self._base_dir,86 self._base_class,87 pattern='another*')88 actual_classes = dict(89 (name, cls.__name__) for name, cls in six.iteritems(classes))90 expected_classes = {91 'dummy_exception_impl1': 'DummyExceptionImpl1',92 'dummy_exception_impl2': 'DummyExceptionImpl2',93 'dummy_exception_with_parameter_impl1':94 'DummyExceptionWithParameterImpl1',95 }96 self.assertEqual(actual_classes, expected_classes)97class ClassWithoutInitDefOne: # pylint: disable=old-style-class, no-init98 pass99class ClassWithoutInitDefTwo(object):100 pass101class ClassWhoseInitOnlyHasSelf(object):102 def __init__(self):103 pass104class ClassWhoseInitWithDefaultArguments(object):105 def __init__(self, dog=1, cat=None, cow=None, fud='a'):106 pass107class ClassWhoseInitWithDefaultArgumentsAndNonDefaultArguments(object):108 def __init__(self, x, dog=1, cat=None, fish=None, fud='a'):109 pass110class IsDirectlyConstructableTest(unittest.TestCase):111 def testIsDirectlyConstructableReturnsTrue(self):112 self.assertTrue(discover.IsDirectlyConstructable(ClassWithoutInitDefOne))113 self.assertTrue(discover.IsDirectlyConstructable(ClassWithoutInitDefTwo))114 self.assertTrue(discover.IsDirectlyConstructable(ClassWhoseInitOnlyHasSelf))115 self.assertTrue(116 discover.IsDirectlyConstructable(ClassWhoseInitWithDefaultArguments))117 def testIsDirectlyConstructableReturnsFalse(self):118 self.assertFalse(119 discover.IsDirectlyConstructable(...

Full Screen

Full Screen

tasks.py

Source:tasks.py Github

copy

Full Screen

...12 # the urllib module was split into three modules in Python3...13 import urllib.request, urllib.parse, urllib.error14import socket15import sys16def HDHRdiscover():17 discoveredTuners = {}18 # 1. Add to 'discoveredTuners' from discovery URL (https://my.hdhomerun.com/discover)19 SDdiscover = []20 try:21 r = requests.get('https://my.hdhomerun.com/discover', timeout=(.5, .2))22 r.raise_for_status()23 SDdiscover = r.json()24 if not isinstance(SDdiscover, list):25 SDdiscover = []26 except (requests.exceptions.RequestException, json.decoder.JSONDecodeError):27 SDdiscover = []28 # print (SDdiscover)29 for device in SDdiscover:30 if not isinstance(device, dict):31 print ("ignoring device ", device)32 continue33 Legacy = False34 DeviceID = None35 DiscoverURL = None36 LocalIP = None37 if 'Legacy' in device:38 Legacy = bool(device['Legacy'])39 if 'DeviceID' in device:40 DeviceID = device['DeviceID']41 if 'DiscoverURL' in device:42 DiscoverURL = device['DiscoverURL']43 if 'LocalIP' in device:44 LocalIP = device['LocalIP']45 if (Legacy) or (DeviceID is None) or (DiscoverURL is None) or (LocalIP is None):46 continue47 discoveredTuners[LocalIP] = DiscoverURL48 # 2. Add to 'discoveredTuners' from a hand-constructed UDP discovery message (device type = tuner, device id = wildcard)49 discovery_udp_msg = bytearray.fromhex('00 02 00 0c 01 04 00 00 00 01 02 04 ff ff ff ff 4e 50 7f 35')50 discovery_udp_port = 6500151 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)52 sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)53 sock.settimeout(.2)54 for i in range(2):55 sock.sendto(discovery_udp_msg, ('<broadcast>', discovery_udp_port))56 while True:57 try:58 (buf, addr) = sock.recvfrom(2048)59 except socket.timeout:60 break61 if addr is None:62 continue63 if buf is None:64 continue65 DiscoverURL = 'http://' + addr[0] + ':80/discover.json'66 discoveredTuners[addr[0]] = DiscoverURL67 eligibleTuners = []68 # 3. Filter the 'discoveredTuners' into 'eligibleTuners', adding 'LocalIP' property69 for device in discoveredTuners:70 discoverResponse = {}71 try:72 r = requests.get(discoveredTuners[device], timeout=(.2, .2))73 r.raise_for_status()74 discoverResponse = r.json()75 if not isinstance(discoverResponse, dict):76 discoverResponse = {}77 except (requests.exceptions.RequestException, json.decoder.JSONDecodeError):78 discoverResponse = {}79 Legacy = False80 DeviceID = None81 LineupURL = None82 if 'Legacy' in discoverResponse:83 Legacy = bool(discoverResponse['Legacy'])84 if 'DeviceID' in discoverResponse:85 DeviceID = discoverResponse['DeviceID']86 if 'LineupURL' in discoverResponse:87 LineupURL = discoverResponse['LineupURL']88 if (Legacy) or (DeviceID is None) or (LineupURL is None):89 continue90 discoverResponse['LocalIP'] = device91 eligibleTuners.append(discoverResponse)92 return eligibleTuners93vars = {}94try:95 device = sys.argv[1]96 url = 'http://' + device + '/discover.json'97 r = requests.get(url)98 j = r.json()99 vars['DeviceAuth'] = j['DeviceAuth']100except:101 try:102 discoveredHDHRs = HDHRdiscover()103 vars['DeviceAuth'] = discoveredHDHRs[0]['DeviceAuth']104 except:105 print ("Discovery failed, use: " + __file__ + " x.x.x.x (HDHomeRun IP)")106 exit() 107if is_py2:108 qstring = urllib.urlencode(vars)109else:110 qstring = urllib.parse.urlencode(vars)111#print (qstring)112url = 'https://api.hdhomerun.com/api/recording_rules?' + qstring113r = requests.get(url)114#print (r.text)115j = r.json()116print ("RuleID / SeriesID Title")...

Full Screen

Full Screen

scrape-movies.py

Source:scrape-movies.py Github

copy

Full Screen

1#!/usr/bin/env/ python323# scrape-movies.py - retreive movie database from tmdb4# movies are collected a year at a time5# API key can be retreived by signing up at6 # https://developers.themoviedb.org/3/getting-started/introduction78import pandas as pd9import tmdbsimple as tmdb10import numpy as np11import time1213tmdb.API_KEY = 'Signup for a key at TMDB'14retry_time = 3015dbFileName = 'moviesDb-raw-test.csv'16def getCertificationUS(id):17 response = id.releases()18 for c in id.countries:19 if c['iso_3166_1'] == 'US':20 return c['certification']21def getMovie(discoverId):22 while(True):23 try:24 id = tmdb.Movies(discoverId)25 response = id.info()26 certification_US = getCertificationUS(id)27 break28 except Exception as e:29 print(e)30 print(f'Error when getting movie, retrying in {retry_time} secs')31 time.sleep(retry_time)32 # add movie to dataframe33 movieRow = pd.DataFrame([[discoverId,34 id.title,35 id.original_title,36 id.release_date,37 id.budget,38 id.revenue,39 id.popularity,40 id.runtime,41 id.vote_average,42 id.vote_count,43 id.adult,44 id.status,45 certification_US,46 id.genres,47 id.production_companies,48 id.production_countries]])49 print(f'\t{id.release_date} {id.title}')50 return movieRow51def getMoviesByYear(year, dbFileName):52 # get total pages from discovery query53 while(True):54 try:55 discover = tmdb.Discover()56 discoverResponse = discover.movie(page = 1, language='en-US',57 sort_by='release_date.asc', include_adult=True, primary_release_year=year)58 numPages = discover.total_pages59 break60 except:61 print(f'\tError when getting page number, retrying in {retry_time} secs')62 time.sleep(retry_time)63 # iterate through each page and get info64 for currentPage in range(1, numPages+1):65 print(f'Page: {currentPage} / {numPages}')66 while(True):67 try:68 discover = tmdb.Discover()69 discoverResponse = discover.movie(page = currentPage, language='en-US',70 sort_by='release_date.asc', include_adult=True, primary_release_year=year)71 break72 except:73 print(f'Error when getting page, retying in {retry_time} secs')74 time.sleep(retry_time)75 for item in discover.results:76 discoverId = item['id']77 # get Movies by id because discover does not include all info78 movieRow = getMovie(discoverId)79 # moviesDf = moviesDf.append(movieRow)80 # append movie to csv file81 movieRow.to_csv(dbFileName, mode='a', header=False, encoding='utf-8')82def main():83 # initialize DataFrame84 moviesDf = pd.DataFrame(columns=['id',85 'title',86 'original_title',87 'release_date',88 'budget',89 'revenue',90 'popularity',91 'runtime',92 'vote_average',93 'vote_count',94 'adult',95 'status',96 'certification_US',97 'genres',98 'production_companies',99 'production_countries'])100 moviesDf.to_csv(dbFileName, mode='a', encoding='utf-8')101 for year in range(1873, 2020):102 getMoviesByYear(year, dbFileName)103if __name__ == '__main__':...

Full Screen

Full Screen

discover.py

Source:discover.py Github

copy

Full Screen

1import unittest2from ..common import ApiTestBase3class DiscoverTests(ApiTestBase):4 """Tests for DiscoverEndpointsMixin."""5 @staticmethod6 def init_all(api):7 return [8 {9 'name': 'test_discover_channels_home',10 'test': DiscoverTests('test_discover_channels_home', api)11 },12 {13 'name': 'test_discover_chaining',14 'test': DiscoverTests('test_discover_chaining', api, user_id='329452045')15 },16 {17 'name': 'test_explore',18 'test': DiscoverTests('test_explore', api)19 },20 {21 'name': 'test_discover_top_live',22 'test': DiscoverTests('test_discover_top_live', api)23 },24 {25 'name': 'test_top_live_status',26 'test': DiscoverTests('test_top_live_status', api)27 },28 ]29 def test_explore(self):30 results = self.api.explore()31 self.assertEqual(results.get('status'), 'ok')32 self.assertGreater(len(results.get('items', [])), 0, 'No items returned.')33 @unittest.skip('Deprecated.')34 def test_discover_channels_home(self):35 results = self.api.discover_channels_home()36 self.assertEqual(results.get('status'), 'ok')37 self.assertGreater(len(results.get('items', [])), 0, 'No items returned.')38 def test_discover_chaining(self):39 results = self.api.discover_chaining(self.test_user_id)40 self.assertEqual(results.get('status'), 'ok')41 self.assertGreater(len(results.get('users', [])), 0, 'No users returned.')42 def test_discover_top_live(self):43 results = self.api.discover_top_live()44 self.assertEqual(results.get('status'), 'ok')45 self.assertTrue('broadcasts' in results)46 def test_top_live_status(self):47 results = self.api.discover_top_live()48 broadcast_ids = [b['id'] for b in results.get('broadcasts', [])]49 if broadcast_ids:50 results = self.api.top_live_status(broadcast_ids)51 self.assertEqual(results.get('status'), 'ok')52 self.assertGreater(len(results.get('broadcast_status_items', [])), 0, 'No broadcast_status_items returned.')53 results = self.api.top_live_status(str(broadcast_ids[0]))54 self.assertEqual(results.get('status'), 'ok')...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const Stryker = require('stryker-parent').Stryker;2const strykerConfig = require('./stryker.conf.js');3const stryker = new Stryker(strykerConfig);4stryker.runMutationTest();5module.exports = function(config){6 config.set({7 mochaOptions: {8 }9 });10};11package.json (1.1 KB)12module.exports = function(config){13 config.set({

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2parent.discover().then(function (result) {3 console.log(result);4});5var parent = require('stryker-parent');6parent.discover().then(function (result) {7 console.log(result);8});9var parent = require('stryker-parent');10parent.discover().then(function (result) {11 console.log(result);12});13var parent = require('stryker-parent');14parent.discover().then(function (result) {15 console.log(result);16});17var parent = require('stryker-parent');18parent.discover().then(function (result) {19 console.log(result);20});21var parent = require('stryker-parent');22parent.discover().then(function (result) {23 console.log(result);24});25var parent = require('stryker-parent');26parent.discover().then(function (result) {27 console.log(result);28});29var parent = require('stryker-parent');30parent.discover().then(function (result) {31 console.log(result);32});33var parent = require('stryker-parent');34parent.discover().then(function (result) {35 console.log(result);36});37var parent = require('stryker-parent');38parent.discover().then(function (result) {39 console.log(result);40});41var parent = require('stryker-parent');42parent.discover().then(function (result) {43 console.log(result);44});45var parent = require('stryker-parent');46parent.discover().then(function (result) {47 console.log(result);48});

Full Screen

Using AI Code Generation

copy

Full Screen

1const discover = require('stryker-parent').discover;2const files = discover('test/**/*.js');3module.exports = function(config) {4 config.set({5 });6};7module.exports = function(config) {8 config.set({9 });10};11const discover = require('stryker-parent').discover;12const files = discover('test/**/*.js');13module.exports = function(config) {14 config.set({15 });16};17const discover = require('stryker-parent').discover;18const files = discover('test/**/*.js');19module.exports = function(config) {20 config.set({21 });22};23const discover = require('stryker-parent').discover;24const files = discover('test/**/*.js');25module.exports = function(config) {26 config.set({27 });28};29const discover = require('stryker-parent').discover;30const files = discover('test/**/*.js');31module.exports = function(config) {32 config.set({33 });34};35const discover = require('stryker-parent').discover;36const files = discover('test/**/*.js');37module.exports = function(config) {38 config.set({39 });40};41const discover = require('stryker-parent').discover

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful