def setUp(self): super().setUp() app.testing = True self.client = app.test_client() # clear datastore requests.post('http://%s/reset' % ndb_client.host) self.ndb_context = ndb_client.context() self.ndb_context.__enter__()
def setUp(self): super(TestCase, self).setUp() # clear datastore requests.post('http://%s/reset' % ndb_client.host) self.ndb_context = ndb_client.context() self.ndb_context.__enter__() self.request = webapp2.Request.blank('/') self.response = webapp2.Response() self.handler = common.Handler(self.request, self.response)
def setUp(self): super(HandlerTest, self).setUp() self.handler = util.Handler(self.request, self.response) FakeGrSource.clear() util.now_fn = lambda: NOW # add FakeSource everywhere necessary util.BLACKLIST.add('fa.ke') util.webmention_endpoint_cache.clear() self.stubbed_create_task = False tasks_client.create_task = lambda *args, **kwargs: Task(name='foo') # clear datastore orig_requests_post('http://%s/reset' % ndb_client.host) self.ndb_context = ndb_client.context() self.ndb_context.__enter__()
def setUp(self): super().setUp() FakeGrSource.clear() util.now_fn = lambda: NOW # add FakeSource everywhere necessary util.BLOCKLIST.add('fa.ke') util.webmention_endpoint_cache.clear() self.stubbed_create_task = False tasks_client.create_task = lambda *args, **kwargs: Task(name='foo') self.client = self.app.test_client() self.client.__enter__() self.clear_datastore() self.ndb_context = ndb_client.context() self.ndb_context.__enter__() # sources self.auth_entities = [ FakeAuthEntity(key=ndb.Key('FakeAuthEntity', '01122334455'), user_json=json_dumps({ 'id': '0123456789', 'name': 'Fake User', 'url': 'http://fakeuser.com/', })), FakeAuthEntity(key=ndb.Key('FakeAuthEntity', '0022446688'), user_json=json_dumps({ 'id': '0022446688', 'name': 'Another Fake', 'url': 'http://anotherfake.com/', })) ] self.sources = [ FakeSource.new(auth_entity=self.auth_entities[0]), FakeSource.new(auth_entity=self.auth_entities[1]) ] for entity in self.sources: entity.features = ['listen'] with self.app.test_request_context(): self.source_bridgy_url = self.sources[0].bridgy_url() self.actor = FakeGrSource.actor = { 'objectType': 'person', 'id': 'tag:fa.ke,2013:212038', 'username': '******', 'displayName': 'Ryan B', 'url': 'https://snarfed.org/', 'image': { 'url': 'http://pic.ture/url' }, } # activities self.activities = FakeGrSource.activities = [{ 'id': f'tag:source.com,2013:{id}', 'url': 'http://fa.ke/post/url', 'object': { 'objectType': 'note', 'id': f'tag:source.com,2013:{id}', 'url': 'http://fa.ke/post/url', 'content': 'foo http://target1/post/url bar', 'to': [{ 'objectType': 'group', 'alias': '@public' }], 'replies': { 'items': [{ 'objectType': 'comment', 'id': f'tag:source.com,2013:1_2_{id}', 'url': 'http://fa.ke/comment/url', 'content': 'foo bar', }], 'totalItems': 1, }, 'tags': [{ 'objectType': 'activity', 'verb': 'like', 'id': f'tag:source.com,2013:{id}_liked_by_alice', 'object': { 'url': 'http://example.com/abc' }, 'author': { 'id': 'tag:source.com,2013:alice', 'url': 'http://example.com/alice', }, }, { 'id': f'tag:source.com,2013:{id}_reposted_by_bob', 'objectType': 'activity', 'verb': 'share', 'object': { 'url': 'http://example.com/def' }, 'author': { 'url': 'http://example.com/bob' }, }, { 'id': f'tag:source.com,2013:{id}_scissors_by_bob', 'objectType': 'activity', 'verb': 'react', 'content': '✁', 'object': { 'url': 'http://example.com/def' }, 'author': { 'url': 'http://example.com/bob' }, }], }, } for id in ('a', 'b', 'c')] # responses self.responses = [] created = datetime.now(timezone.utc) - timedelta(days=10) for activity in self.activities: obj = activity['object'] pruned_activity = { 'id': activity['id'], 'url': 'http://fa.ke/post/url', 'object': { 'content': 'foo http://target1/post/url bar', } } comment = obj['replies']['items'][0] self.responses.append( Response(id=comment['id'], activities_json=[json_dumps(pruned_activity)], response_json=json_dumps(comment), type='comment', source=self.sources[0].key, unsent=['http://target1/post/url'], created=created)) created += timedelta(hours=1) like = obj['tags'][0] self.responses.append( Response(id=like['id'], activities_json=[json_dumps(pruned_activity)], response_json=json_dumps(like), type='like', source=self.sources[0].key, unsent=['http://target1/post/url'], created=created)) created += timedelta(hours=1) share = obj['tags'][1] self.responses.append( Response(id=share['id'], activities_json=[json_dumps(pruned_activity)], response_json=json_dumps(share), type='repost', source=self.sources[0].key, unsent=['http://target1/post/url'], created=created)) created += timedelta(hours=1) reaction = obj['tags'][2] self.responses.append( Response(id=reaction['id'], activities_json=[json_dumps(pruned_activity)], response_json=json_dumps(reaction), type='react', source=self.sources[0].key, unsent=['http://target1/post/url'], created=created)) created += timedelta(hours=1) # publishes self.publishes = [ Publish( parent=PublishedPage(id='https://post').key, source=self.sources[0].key, status='complete', published={'url': 'http://fa.ke/syndpost'}, ) ] # blogposts self.blogposts = [ BlogPost( id='https://post', source=self.sources[0].key, status='complete', feed_item={'title': 'a post'}, sent=['http://a/link'], ) ]