def test_create_new_rereads_domains(self): FakeSource.new(None, features=['listen'], domain_urls=['http://foo'], domains=['foo']).put() FakeSource.string_id_counter -= 1 auth_entity = testutil.FakeAuthEntity(id='x', user_json=json.dumps( {'urls': [{'value': 'http://bar'}, {'value': 'http://baz'}]})) self.expect_webmention_requests_get('http://bar/', 'no webmention endpoint', verify=False) self.mox.ReplayAll() source = FakeSource.create_new(self.handler, auth_entity=auth_entity) self.assertEquals(['http://bar/', 'http://baz/'], source.domain_urls) self.assertEquals(['bar', 'baz'], source.domains)
def test_create_new_domain_url_redirects_to_path(self): """If a profile URL is a root that redirects to a path, keep the root.""" auth_entity = testutil.FakeAuthEntity(id='x', user_json=json.dumps( {'url': 'http://site'})) auth_entity.put() self.expect_requests_head('http://site', redirected_url='https://site/path') self.mox.ReplayAll() source = FakeSource.create_new(self.handler, auth_entity=auth_entity) self.assertEquals(['http://site/'], source.domain_urls) self.assertEquals(['site'], source.domains)
def test_create_new_too_many_domains(self): urls = ['http://%s/' % i for i in range(10)] auth_entity = testutil.FakeAuthEntity( id='x', user_json=json.dumps({'urls': [{ 'value': u } for u in urls]})) # we should only check the first 5 for url in urls[:models.MAX_AUTHOR_URLS]: self.expect_requests_head(url) self.mox.ReplayAll() source = FakeSource.create_new(self.handler, auth_entity=auth_entity) self.assertEquals(urls, source.domain_urls) self.assertEquals([str(i) for i in range(10)], source.domains)
def test_create_new_domain_url_matches_root_relme(self): """If a profile URL contains a path, check the root for a rel=me to the path.""" auth_entity = testutil.FakeAuthEntity(id='x', user_json=json.dumps( {'url': 'http://site/path'})) auth_entity.put() self.expect_requests_get( 'http://site', '<html><a href="http://site/path" rel="me">http://site/path</a></html>' ) self.mox.ReplayAll() source = FakeSource.create_new(self.handler, auth_entity=auth_entity) self.assertEquals(['http://site/'], source.domain_urls) self.assertEquals(['site'], source.domains)
def setUp(self): super(PublishTest, self).setUp() publish.SOURCE_NAMES['fake'] = testutil.FakeSource publish.SOURCE_DOMAINS['fa.ke'] = testutil.FakeSource self.auth_entity = testutil.FakeAuthEntity(id='0123456789') self.source = testutil.FakeSource(id='foo.com', features=['publish'], domains=['foo.com'], domain_urls=['http://foo.com/'], auth_entity=self.auth_entity.key) self.source.put() self.oauth_state = { 'source_url': 'http://foo.com/bar', 'target_url': 'https://brid.gy/publish/fake', 'source_key': self.source.key.urlsafe(), 'include_link': gr_source.INCLUDE_LINK, } self.post_html = '<article class="h-entry"><p class="e-content">%s</p></article>' self.backlink = '\n<a href="http://localhost/publish/fake"></a>'
def test_create_new_dedupes_domains(self): auth_entity = testutil.FakeAuthEntity(id='x', user_json=json.dumps({ 'urls': [ { 'value': 'http://foo' }, { 'value': 'https://foo/' }, { 'value': 'http://foo/' }, { 'value': 'http://foo' }, ] })) self.mox.ReplayAll() source = FakeSource.create_new(self.handler, auth_entity=auth_entity) self.assertEquals(['https://foo/'], source.domain_urls) self.assertEquals(['foo'], source.domains)
def test_create_new_domain(self): """If the source has a URL set, extract its domain.""" # bad URLs for user_json in ( None, {}, { 'url': 'not<a>url' }, # t.co is in the webmention blacklist { 'url': 'http://t.co/foo' }): auth_entity = None if user_json is not None: auth_entity = testutil.FakeAuthEntity( id='x', user_json=json.dumps(user_json)) auth_entity.put() source = FakeSource.create_new(self.handler, auth_entity=auth_entity) self.assertEqual([], source.domains) self.assertEqual([], source.domain_urls) # good URLs for url in ( 'http://foo.com/bar', 'https://www.foo.com/bar', 'http://FoO.cOm/', # should be normalized to lowercase ): auth_entity = testutil.FakeAuthEntity(id='x', user_json=json.dumps( {'url': url})) auth_entity.put() source = FakeSource.create_new(self.handler, auth_entity=auth_entity) self.assertEquals([url.lower()], source.domain_urls) self.assertEquals(['foo.com'], source.domains) # multiple good URLs and one that's in the webmention blacklist auth_entity = testutil.FakeAuthEntity( id='x', user_json=json.dumps({ 'url': 'http://foo.org', 'urls': [ { 'value': u } for u in 'http://bar.com', 'http://t.co/x', 'http://baz', # utm_* query params should be stripped 'https://baj/biff?utm_campaign=x&utm_source=y' ], })) auth_entity.put() source = FakeSource.create_new(self.handler, auth_entity=auth_entity) self.assertEquals([ 'http://foo.org/', 'http://bar.com/', 'http://baz/', 'https://baj/biff' ], source.domain_urls) self.assertEquals(['foo.org', 'bar.com', 'baz', 'baj'], source.domains) # a URL that redirects auth_entity = testutil.FakeAuthEntity(id='x', user_json=json.dumps( {'url': 'http://orig'})) auth_entity.put() self.expect_requests_head('http://orig', redirected_url='http://final') self.mox.ReplayAll() source = FakeSource.create_new(self.handler, auth_entity=auth_entity) self.assertEquals(['http://final/'], source.domain_urls) self.assertEquals(['final'], source.domains)