Skip to content

Commit

Permalink
feature: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
abbas123456 committed Feb 4, 2021
1 parent 1fa57d4 commit 2da42fe
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 23 deletions.
79 changes: 57 additions & 22 deletions core/app/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def parse_feed_config(feed_config):
by_feed_type = {
'activity_stream': ActivityStreamFeed,
'zendesk': ZendeskFeed,
'maxemail': EventFeed,
'maxemail': MaxemailFeed,
'aventri': EventFeed,
}
return by_feed_type[feed_config['TYPE']].parse_config(feed_config)
Expand Down Expand Up @@ -335,11 +335,16 @@ async def fetch_attendees(event_id):
attendee_object = {
'type': ['Attendee', 'dit:aventri:Attendee'],
'id': 'dit:aventri:Attendee:' + attendee['attendeeid'],
'registration_status': attendee['registrationstatus'],
'individual_cost': attendee['individualcost'],
'cost': attendee['cost'],
'total_cost': attendee['totalcost'],
'created': attendee['created']
'registrationstatus': attendee['registrationstatus'],
'category': attendee['category']['name'],
'approvalstatus': attendee['approvalstatus'],
'created': attendee['created'],
'createdby': attendee['createdby'],
'language': attendee['language'],
'lastmodified': attendee['lastmodified'],
'modifiedby': attendee['modifiedby'],
'responses': [{'name': r['name'], 'response': r['response']}
for r in attendee['responses'].values()]
}
attendees.append(attendee_object)
return attendees
Expand All @@ -365,43 +370,73 @@ async def fetch_event(event_id):
headers={'accesstoken': self.access_token})
result.raise_for_status()
event = json_loads(result._body)
if 'error' in event:
event = {}
else:
event['attendeees'] = await fetch_attendees(event_id)

if 'error' not in event:
event['attendees'] = await fetch_attendees(event_id)

await context.redis_client.execute(
'SETEX', f'event-{event_id}', 60*60*24, json_dumps(event))
return event

now = datetime.datetime.now().isoformat()
return [
{
'type': 'Create',
'type': 'dit:aventri:Event',
'id': 'dit:aventri:Event:' + str(event['eventid']) + ':Create',
'published': now,
'eventid': event['eventid'],
'dit:application': 'aventri',
'object': {
'type': ['Event', 'dit:aventri:Event'],
'id': 'dit:aventri:Event:' + event['eventid'],
'name': event['name'],
'url': event['url'],
'content': event['description'],
'startdate': event['startdate'],
'approval_required': event['approval_required'],
'approval_status': event['approval_status'],
'city': event['city'],
'clientcontact': event['clientcontact'],
'closedate': event['closedate'],
'closetime': event['closetime'],
'code': event['code'],
'contactinfo': event['contactinfo'],
'country': event['country'],
'createdby': event['createdby'],
'createddatetime': event['createddatetime'],
'defaultlanguage': event['defaultlanguage'],
'description': event['description'],
'enddate': event['enddate'],
'endtime': event['endtime'],
'eventtype': event['eventtype'],
'folderid': event['folderid'],
'foldername': event['foldername'],
'location': event['location'],
'language': event['defaultlanguage'],
'timezone': event['timezone'],
'currency': event['standardcurrency'],
'live_date': event['live_date'],
'location_address1': event['location']['address1'],
'location_address2': event['location']['address2'],
'location_address3': event['location']['address3'],
'location_city': event['location']['city'],
'location_country': event['location']['country'],
'location_name': event['location']['name'],
'location_postcode': event['location']['postcode'],
'location_state': event['location']['state'],
'locationname': event['locationname'],
'login1': event['login1'],
'login2': event['login2'],
'max_reg': event['max_reg'],
'modifiedby': event['modifiedby'],
'modifieddatetime': event['modifieddatetime'],
'name': event['name'],
'price_type': event['price_type'],
'price': event['pricepoints'],
'pricepoints': event['pricepoints'],
'standardcurrency': event['standardcurrency'],
'startdate': event['startdate'],
'starttime': event['starttime'],
'status': event['status'],
'state': event['state'],
'timezone': event['timezone'],
'url': event['url'],
'attributedTo': event['attendees']
}
}
for page_event in feed
for event in [await get_event(page_event['eventid'])]
if event is not None
if 'eventid' in event
]


Expand Down
2 changes: 1 addition & 1 deletion core/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def json_loads(data):
def main(run_application_coroutine):
stdout_handler = logging.StreamHandler(sys.stdout)
app_logger = logging.getLogger('activity-stream')
app_logger.setLevel(logging.DEBUG)
app_logger.setLevel(logging.INFO)
app_logger.addHandler(stdout_handler)

loop = asyncio.get_event_loop()
Expand Down
53 changes: 53 additions & 0 deletions core/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,59 @@ def has_two_zendesk_tickets(results):
self.assertIn('"dit:zendesk:Ticket:3:Create"', results)
self.assertIn('"2011-04-12T12:48:13+00:00"', results)

@async_test
async def test_aventri(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) == 1

env = {
**mock_env(),
'FEEDS__1__UNIQUE_ID': 'third_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.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['dit:application'], 'aventri')
self.assertEqual(event['id'], 'dit:aventri:Event:1:Create')
self.assertEqual(event['type'], 'dit:aventri:Event')

self.assertEqual(event['object']['id'], 'dit:aventri:Event:1')
self.assertEqual(event['object']['type'], ['Event', 'dit:aventri:Event'])
self.assertEqual(event['object']['name'], 'Demo Event')
self.assertEqual(event['object']['location_city'], 'London')

self.assertEqual(event['object']['attributedTo'][0]['id'],
'dit:aventri:Attendee:1')
self.assertEqual(event['object']['attributedTo'][0]['category'],
'Event Speaker')
self.assertEqual(event['object']['attributedTo'][0]['type'],
['Attendee', 'dit:aventri:Attendee'])
self.assertEqual(event['object']['attributedTo'][0]['responses'][0],
{'name': 'Email Address', 'response': 'test@example.com'})

@async_test
async def test_maxemail(self):
def maxemail_base_fetch(results):
Expand Down
3 changes: 3 additions & 0 deletions core/tests/tests_fixture_aventri_authorize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"accesstoken": "sampletoken_juqGzTXYWBrqLAWMYGukNzuvOD5TXTGxxMo0lSft69q2MTgfodwQXRvlsx1YHExTM7Dd4mu5bucbrr3I2isCisrQieie"
}
64 changes: 64 additions & 0 deletions core/tests/tests_fixture_aventri_getAttendee.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"adjustments": "0.00",
"agendacost": "0.00",
"approvalstatus": "",
"attendeeid": "1",
"balancedue": "0.00",
"category": {
"categoryid": "1",
"name": "Event Speaker"
},
"categorycost": "0.00",
"cost": "0.00",
"created": "2014-10-06 14:10:01",
"createdby": "attendee",
"guestcost": "0.00",
"hotelcost": "0.00",
"individualcost": "0.00",
"language": "eng",
"last_lobby_login": "2020-10-30 06:08:30",
"lastmodified": "2014-10-06 14:10:31",
"modifiedby": "attendee",
"optioncost": "0.00",
"preload-recordid": "1",
"received": "0.00",
"recordid": "XXX",
"registrationstatus": "Confirmed",
"responses": {
"1": {
"choicekey": "test@example.com",
"fieldname": "email",
"name": "Email Address",
"page": "Welcome",
"pageid": "1",
"questionid": "1",
"response": "test@example.com"
},
"2": {
"auto_capitalize": "0",
"choicekey": "1",
"fieldname": "28341900",
"name": "Session A",
"page": "Agenda",
"pageid": "3",
"questionid": "28341900",
"response": "Session A"
},
"3": {
"auto_capitalize": "0",
"choicekey": "1",
"fieldname": "28341982",
"name": "Option A",
"page": "Options",
"pageid": "4",
"questionid": "28341982",
"response": "Option A"
}
},
"statetax": "0.00",
"subcategorycost": "0.00",
"tax": "0.00",
"testregistration": "0",
"totalcost": "0.00",
"virtual_event_attendance": "Yes"
}
127 changes: 127 additions & 0 deletions core/tests/tests_fixture_aventri_getEvent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"accountid": "1234",
"adminemails": null,
"allow_other_fonts": null,
"allowedEmailSuffixes": null,
"api_trigger_type": null,
"api_trigger_url": null,
"approval_required": null,
"approval_status": null,
"blackListFailureMessage": null,
"businessunit": "0",
"calendar_country": "",
"callcenter": null,
"cardacceptance": null,
"city": "London",
"clientcontact": "John Smith",
"clonedfrom": null,
"closedate": "0000-00-00",
"closetime": null,
"code": "1000",
"contactinfo": "contact@example.com",
"country": "GB",
"createdby": "12345678",
"createddatetime": "2021-01-27 00:00:00",
"currency_dec_point": ".",
"currency_thousands_sep": ",",
"customhtml": null,
"customstats": null,
"dateformat": "l, j F Y",
"defaultlanguage": "eng",
"deleted": "0",
"department": "0",
"description": "Join the demo event",
"division": "0",
"domainid": null,
"eBooth": null,
"eBudget": null,
"eConnect": null,
"eHome": null,
"eMobile": "0",
"ePlanning": null,
"eProject": null,
"eRFP": null,
"eReg": "1",
"eScheduler": null,
"eSeating": null,
"eSelect": "0",
"eSocial": "1",
"eWiki": null,
"emailSuffixData": null,
"emailSuffixes": null,
"enable_virtual_event": null,
"enddate": "2022-03-31",
"endtime": "17:00:00",
"event_setup_date": null,
"event_setup_hours": null,
"eventclosemessage": "This event is now closed.",
"eventid": "1",
"eventlogo": "",
"eventtype": "event",
"facebook_eventid": null,
"folderid": "5678",
"foldername": "Test",
"footercustomcode": null,
"force_agenda_selection_max": null,
"force_agenda_selection_min": null,
"force_option_selection": null,
"headercustomcode": null,
"homepage": "",
"include_calendar": "1",
"include_internal_calendar": null,
"ipreoid": "0",
"languages": "English",
"line_item_tax": "0",
"linktohomepage": null,
"live_date": null,
"location": {
"address1": "",
"address2": "",
"address3": "",
"city": "London",
"country": "GB",
"email": "",
"map": "",
"name": "",
"phone": "",
"postcode": "",
"state": ""
},
"locationname": "",
"lodgingnotes": "",
"login1": "email",
"login2": "attendeeid",
"logo_textid": null,
"logoalign": null,
"logolinktohomepage": null,
"max_reg": "0",
"modifiedby": "user@example.com",
"modifieddatetime": "2021-01-29 00:00:00",
"name": "Demo Event",
"nolodgingrequired": null,
"price_type": null,
"pricepoints": null,
"programmanager": "",
"revenue_status": null,
"scansettings": null,
"standardcurrency": "Sterling",
"startdate": "2021-10-01",
"starttime": "09:00:00",
"state": "",
"status": "Live",
"statusmessage": null,
"tax_rounding": null,
"taxid": null,
"tellafriendlinktohomepage": null,
"timeformat": "g:i a",
"timeoutlinktohomepage": null,
"timezone": "[GMT] Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London",
"timezonedescription": null,
"timezoneid": "27",
"url": "https://example.com",
"use_account_codes": null,
"use_template": null,
"useehomepage": null,
"viral_ticketing": null,
"wrapservices": null
}
8 changes: 8 additions & 0 deletions core/tests/tests_fixture_aventri_listAttendees.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"attendeeid": "1",
"email": "attendee1001email@example.com",
"name": "[Attendee 1001 First Name Last Name]",
"parentid": "0"
}
]

0 comments on commit 2da42fe

Please sign in to comment.