Skip to content

Commit

Permalink
feat: migrating Aventri feed to Data Services APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
sekharpanja committed Feb 17, 2021
1 parent 3fe4817 commit 91fcaea
Show file tree
Hide file tree
Showing 6 changed files with 747 additions and 224 deletions.
299 changes: 136 additions & 163 deletions core/app/feeds.py

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion core/app/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ async def http_make_request(session, metrics, method, url, data, headers, params
parsed_url = yarl.URL(url)

with metric_timer(metrics['http_request_duration_seconds'], [parsed_url.host]):
async with session.request(method, parsed_url, data=data, headers=headers, params=params) as result:
async with session.request(
method, parsed_url, data=data, headers=headers, params=params
) as result:
# We must read the body before the connection is closed, which can
# be on exit of the context manager
await result.read()
Expand Down
49 changes: 4 additions & 45 deletions core/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1812,11 +1812,8 @@ def aventri_fetch(results):
'FEEDS__1__TYPE': 'aventri',
'FEEDS__1__SEED': 'http://localhost:8081/tests_fixture_aventri_listEvents.json',
'FEEDS__1__AUTH_URL': 'http://localhost:8081/tests_fixture_aventri_authorize.json',
'FEEDS__1__EVENT_URL': 'http://localhost:8081/tests_fixture_aventri_getEvent.json',
'FEEDS__1__ATTENDEES_LIST_URL':
'http://localhost:8081/tests_fixture_aventri_listAttendees.json',
'FEEDS__1__ATTENDEE_URL':
'http://localhost:8081/tests_fixture_aventri_getAttendee.json',
}

with patch('asyncio.sleep', wraps=fast_sleep):
Expand All @@ -1837,8 +1834,8 @@ def aventri_fetch(results):
self.assertEqual(event['object']['id'], 'dit:aventri:Event:1')
self.assertEqual(event['object']['type'], ['dit:aventri:Event'])
self.assertEqual(event['object']['name'], 'Demo Event')
self.assertEqual(event['object']['published'], '2021-01-27T00:00:00')
self.assertEqual(event['object']['dit:aventri:location_city'], 'London')
self.assertEqual(event['object']['published'], '2021-01-27T01:11:31')
self.assertEqual(event['object']['dit:aventri:location_city'], 'Melbourne')
self.assertEqual(event['object']['dit:public'], True)

attendee = results_dict['hits']['hits'][1]['_source']
Expand All @@ -1853,51 +1850,13 @@ def aventri_fetch(results):
)
self.assertEqual(attendee['object']['id'], 'dit:aventri:Attendee:1')
self.assertEqual(attendee['object']['type'], ['dit:aventri:Attendee'])
self.assertEqual(attendee['object']['published'], '2014-10-06T14:10:01')
self.assertEqual(attendee['object']['published'], '2018-08-31T11:44:00')
self.assertEqual(attendee['object']['dit:aventri:category'], 'Event Speaker')
self.assertEqual(
attendee['object']['dit:aventri:responses'][0],
{'name': 'Email Address', 'response': 'test@example.com'}
{'name': 'Email Address', 'response': 'test@test.com'}
)

@async_test
async def test_aventri_deleted_no_calendar_event(self):
def aventri_fetch(results):
if 'hits' not in results or 'hits' not in results['hits']:
return False
aventri_events = [
item
for item in results['hits']['hits']
for source in [item['_source']]
if 'dit:application' in source and source['dit:application'] == 'aventri'
]
return len(aventri_events) == 2

env = {
**mock_env(),
'FEEDS__1__UNIQUE_ID': 'fourth_feed',
'FEEDS__1__ACCOUNT_ID': '1234',
'FEEDS__1__API_KEY': '5678',
'FEEDS__1__TYPE': 'aventri',
'FEEDS__1__SEED': 'http://localhost:8081/tests_fixture_aventri_listEvents.json',
'FEEDS__1__AUTH_URL': 'http://localhost:8081/tests_fixture_aventri_authorize.json',
'FEEDS__1__EVENT_URL':
'http://localhost:8081/tests_fixture_aventri_getEvent_deleted_no_calendar.json',
'FEEDS__1__ATTENDEES_LIST_URL':
'http://localhost:8081/tests_fixture_aventri_listAttendees.json',
'FEEDS__1__ATTENDEE_URL':
'http://localhost:8081/tests_fixture_aventri_getAttendee.json',
}

with patch('asyncio.sleep', wraps=fast_sleep):
await self.setup_manual(env=env, mock_feed=read_file, mock_feed_status=lambda: 200,
mock_headers=lambda: {})
results_dict = await fetch_all_es_data_until(aventri_fetch)

event = results_dict['hits']['hits'][0]['_source']
self.assertEqual(event['object']['type'], ['dit:aventri:Event', 'Tombstone'])
self.assertEqual(event['object']['dit:public'], False)

@async_test
async def test_maxemail(self):
def maxemail_base_fetch(results):
Expand Down
4 changes: 3 additions & 1 deletion core/tests/tests_fixture_aventri_authorize.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"accesstoken": "sampletoken_juqGzTXYWBrqLAWMYGukNzuvOD5TXTGxxMo0lSft69q2MTgfodwQXRvlsx1YHExTM7Dd4mu5bucbrr3I2isCisrQieie"
"accesstoken": "LuhUgEYSvNxpazJYKo0kkNvipKnisrW8GoJa4GTwMiiveYNzipisXrFe1k2GjMW27VeHk",
"msg": "",
"status": "success"
}
Loading

0 comments on commit 91fcaea

Please sign in to comment.