def test_seantis_import_build_url(self): context = mock.Mock() context.url = ' http://www.ex.ch/ev/ ' context.do_filter = False context.import_imported = False context.cat1 = '' context.cat2 = '' source = EventsSourceSeantisJson(context) self.assertEquals(source.build_url(), 'http://www.ex.ch/ev/?type=json&compact=true') context.url = ' http://www.ex.ch/ev ' source = EventsSourceSeantisJson(context) self.assertEquals(source.build_url(), 'http://www.ex.ch/ev?type=json&compact=true') context.do_filter = True source = EventsSourceSeantisJson(context) self.assertEquals(source.build_url(), 'http://www.ex.ch/ev?type=json&compact=true') context.cat1 = 'cat1' source = EventsSourceSeantisJson(context) self.assertEquals( source.build_url(), 'http://www.ex.ch/ev?type=json&compact=true&filter=true&cat1=cat1') context.cat1 = '' context.cat2 = 'cat2' source = EventsSourceSeantisJson(context) self.assertEquals( source.build_url(), 'http://www.ex.ch/ev?type=json&compact=true&filter=true&cat2=cat2') context.cat1 = 'cat1' source = EventsSourceSeantisJson(context) self.assertEquals( source.build_url(), 'http://www.ex.ch/ev?type=json&compact=true&filter=true' '&cat1=cat1&cat2=cat2') context.import_imported = True source = EventsSourceSeantisJson(context) self.assertEquals( source.build_url(), 'http://www.ex.ch/ev?type=json&compact=true&imported=1&filter=true' '&cat1=cat1&cat2=cat2')
def test_seantis_import(self): json_string = """[{ "id": "id1", "title": "title", "short_description": "short_description", "long_description": "h\u00e4nsel", "cat1": ["cat12", "cat11"], "cat2": ["cat21"], "event_url": "http://www.event.ch", "timezone": "Europe/Zurich", "start": "2014-01-15T00:00:00+00:00", "end": "2014-01-15T23:59:59+00:00", "whole_day": true, "recurrence": "RRULE:FREQ=WEEKLY;BYDAY=MO,TU;UNTIL=20150101T0000Z", "locality": "locality", "street": "street", "housenumber": "housenumber", "zipcode": "1234", "town": "town", "longitude": 2.0, "latitude": 1.0, "location_url": "http://www.location.ch", "contact_name": "contact_name", "contact_phone": "+12 (3) 45 678 90 12", "contact_email": "*****@*****.**", "registration": "http://www.tickets.ch", "organizer": "organizer", "prices": "prices", "images": [{"url": "img_url", "name": "img_name"}], "attachements": [ {"url": "a1_url", "name": "a1_name"}, {"url": "a2_url", "name": "a2_name"} ], "submitter": "sumitter", "submitter_email": "*****@*****.**" },{ "last_update": "2014-01-21T10:21:47+01:00", "id": "test", "title": "test", "short_description": "test", "long_description": null, "cat1": ["cat13", "cat14"], "cat2": ["cat21", "cat22", "cat23"], "event_url": null, "timezone": "UTC", "start": "2014-01-19T17:00:00+02:00", "end": "2014-01-19T18:00:00+02:00", "whole_day": false, "recurrence": null, "locality": null, "street": null, "housenumber": null, "zipcode": null, "town": null, "longitude": null, "latitude": null, "location_url": null, "contact_name": null, "contact_phone": null, "contact_email": null, "registration": null, "organizer": null, "prices": null, "images": null, "attachments": [], "submitter": "cccc", "submitter_email": "*****@*****.**" }]""" context = mock.Mock() context.url = 'url' context.do_filter = False context.cat1 = '' context.cat2 = '' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 2) self.assertTrue( default_now() - events[0]['last_update'] < timedelta(seconds=10) ) self.assertEquals(events[0]['fetch_id'], 'url') self.assertEquals(events[0]['id'], 'id1') self.assertEquals(events[0]['source_id'], 'id1') self.assertEquals(events[0]['title'], 'title') self.assertEquals(events[0]['short_description'], u'short_description') self.assertEquals(events[0]['long_description'], u'h\xe4nsel') self.assertEquals(events[0]['event_url'], 'http://www.event.ch') self.assertEquals(events[0]['registration'], 'http://www.tickets.ch') self.assertEquals(events[0]['location_url'], 'http://www.location.ch') self.assertEquals(events[0]['image'], 'img_url') self.assertEquals(events[0]['image_name'], 'img_name') self.assertEquals(events[0]['attachment_1'], 'a1_url') self.assertEquals(events[0]['attachment_1_name'], 'a1_name') self.assertEquals(events[0]['attachment_2'], 'a2_url') self.assertEquals(events[0]['attachment_2_name'], 'a2_name') self.assertEquals(events[0]['organizer'], 'organizer') self.assertEquals(events[0]['street'], 'street') self.assertEquals(events[0]['housenumber'], 'housenumber') self.assertEquals(events[0]['locality'], 'locality') self.assertEquals(events[0]['zipcode'], '1234') self.assertEquals(events[0]['town'], 'town') self.assertEquals(events[0]['contact_name'], 'contact_name') self.assertEquals(events[0]['contact_email'], '*****@*****.**') self.assertEquals(events[0]['contact_phone'], '+12 (3) 45 678 90 12') self.assertEquals(events[0]['latitude'], '1.0') self.assertEquals(events[0]['longitude'], '2.0') self.assertEquals(events[0]['timezone'], 'Europe/Zurich') self.assertEquals(events[0]['start'], datetime(2014, 1, 15, 0, 0, tzinfo=pytz.UTC)) self.assertEquals(events[0]['end'], datetime(2014, 1, 15, 23, 59, 59, tzinfo=pytz.UTC)) self.assertEquals(events[0]['recurrence'], 'RRULE:FREQ=WEEKLY;BYDAY=MO,TU;UNTIL=20150101T0000Z') self.assertEquals(events[0]['whole_day'], True) self.assertEquals(events[0]['cat1'], set(['cat11', 'cat12'])) self.assertEquals(events[0]['cat2'], set(['cat21'])) self.assertEquals(events[0]['submitter'], 'sumitter') self.assertEquals(events[0]['submitter_email'], '*****@*****.**') self.assertEquals( events[1]['last_update'], datetime(2014, 1, 21, 9, 21, 47, tzinfo=pytz.UTC) ) self.assertEquals(events[1]['latitude'], None) self.assertEquals(events[1]['longitude'], None) self.assertEquals(events[1]['timezone'], 'UTC') self.assertEquals(events[1]['start'], datetime(2014, 1, 19, 15, 0, tzinfo=pytz.UTC)) self.assertEquals(events[1]['end'], datetime(2014, 1, 19, 16, 0, tzinfo=pytz.UTC)) self.assertEquals(events[1]['whole_day'], False) self.assertEquals(events[1]['cat1'], set(['cat13', 'cat14'])) self.assertEquals(events[1]['cat2'], set(['cat21', 'cat22', 'cat23'])) # Filter by categories context.do_filter = False context.cat1 = 'cat5' context.cat2 = 'cat6' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 2) context.do_filter = True context.cat1 = '' context.cat2 = '' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 2) context.cat1 = 'cat1' context.cat2 = '' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 0) context.cat1 = 'cat11' context.cat2 = '' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 1) self.assertEquals(events[0]['cat1'], set(['cat11', 'cat12'])) context.cat1 = 'cat12' context.cat2 = '' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 1) self.assertEquals(events[0]['cat1'], set(['cat11', 'cat12'])) context.cat1 = '' context.cat2 = 'cat23' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 1) self.assertEquals(events[0]['cat2'], set(['cat21', 'cat22', 'cat23'])) context.cat1 = '' context.cat2 = 'cat24' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 0) context.do_filter = True context.cat1 = 'cat11' context.cat2 = 'cat21' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 1) self.assertEquals(events[0]['cat1'], set(['cat11', 'cat12'])) self.assertEquals(events[0]['cat2'], set(['cat21']))
def test_seantis_import(self): json_string = """[{ "id": "id1", "title": "title", "short_description": "short_description", "long_description": "h\u00e4nsel", "cat1": ["cat12", "cat11"], "cat2": ["cat21"], "event_url": "http://www.event.ch", "timezone": "Europe/Zurich", "start": "2014-01-15T00:00:00+00:00", "end": "2014-01-15T23:59:59+00:00", "whole_day": true, "recurrence": "RRULE:FREQ=WEEKLY;BYDAY=MO,TU;UNTIL=20150101T0000Z", "locality": "locality", "street": "street", "housenumber": "housenumber", "zipcode": "1234", "town": "town", "longitude": 2.0, "latitude": 1.0, "location_url": "http://www.location.ch", "contact_name": "contact_name", "contact_phone": "+12 (3) 45 678 90 12", "contact_email": "*****@*****.**", "registration": "http://www.tickets.ch", "organizer": "organizer", "prices": "prices", "images": [{"url": "img_url", "name": "img_name"}], "attachements": [ {"url": "a1_url", "name": "a1_name"}, {"url": "a2_url", "name": "a2_name"} ], "submitter": "sumitter", "submitter_email": "*****@*****.**" },{ "last_update": "2014-01-21T10:21:47+01:00", "id": "test", "title": "test", "short_description": "test", "long_description": null, "cat1": ["cat13", "cat14"], "cat2": ["cat21", "cat22", "cat23"], "event_url": null, "timezone": "UTC", "start": "2014-01-19T17:00:00+02:00", "end": "2014-01-19T18:00:00+02:00", "whole_day": false, "recurrence": null, "locality": null, "street": null, "housenumber": null, "zipcode": null, "town": null, "longitude": null, "latitude": null, "location_url": null, "contact_name": null, "contact_phone": null, "contact_email": null, "registration": null, "organizer": null, "prices": null, "images": null, "attachments": [], "submitter": "cccc", "submitter_email": "*****@*****.**" }]""" context = mock.Mock() context.url = 'url' context.do_filter = False context.cat1 = '' context.cat2 = '' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 2) self.assertTrue( default_now() - events[0]['last_update'] < timedelta(seconds=10)) self.assertEquals(events[0]['fetch_id'], 'url') self.assertEquals(events[0]['id'], 'id1') self.assertEquals(events[0]['source_id'], 'id1') self.assertEquals(events[0]['title'], 'title') self.assertEquals(events[0]['short_description'], u'short_description') self.assertEquals(events[0]['long_description'], u'h\xe4nsel') self.assertEquals(events[0]['event_url'], 'http://www.event.ch') self.assertEquals(events[0]['registration'], 'http://www.tickets.ch') self.assertEquals(events[0]['location_url'], 'http://www.location.ch') self.assertEquals(events[0]['image'], 'img_url') self.assertEquals(events[0]['image_name'], 'img_name') self.assertEquals(events[0]['attachment_1'], 'a1_url') self.assertEquals(events[0]['attachment_1_name'], 'a1_name') self.assertEquals(events[0]['attachment_2'], 'a2_url') self.assertEquals(events[0]['attachment_2_name'], 'a2_name') self.assertEquals(events[0]['organizer'], 'organizer') self.assertEquals(events[0]['street'], 'street') self.assertEquals(events[0]['housenumber'], 'housenumber') self.assertEquals(events[0]['locality'], 'locality') self.assertEquals(events[0]['zipcode'], '1234') self.assertEquals(events[0]['town'], 'town') self.assertEquals(events[0]['contact_name'], 'contact_name') self.assertEquals(events[0]['contact_email'], '*****@*****.**') self.assertEquals(events[0]['contact_phone'], '+12 (3) 45 678 90 12') self.assertEquals(events[0]['latitude'], '1.0') self.assertEquals(events[0]['longitude'], '2.0') self.assertEquals(events[0]['timezone'], 'Europe/Zurich') self.assertEquals(events[0]['start'], datetime(2014, 1, 15, 0, 0, tzinfo=pytz.UTC)) self.assertEquals(events[0]['end'], datetime(2014, 1, 15, 23, 59, 59, tzinfo=pytz.UTC)) self.assertEquals( events[0]['recurrence'], 'RRULE:FREQ=WEEKLY;BYDAY=MO,TU;UNTIL=20150101T0000Z') self.assertEquals(events[0]['whole_day'], True) self.assertEquals(events[0]['cat1'], set(['cat11', 'cat12'])) self.assertEquals(events[0]['cat2'], set(['cat21'])) self.assertEquals(events[0]['submitter'], 'sumitter') self.assertEquals(events[0]['submitter_email'], '*****@*****.**') self.assertEquals(events[1]['last_update'], datetime(2014, 1, 21, 9, 21, 47, tzinfo=pytz.UTC)) self.assertEquals(events[1]['latitude'], None) self.assertEquals(events[1]['longitude'], None) self.assertEquals(events[1]['timezone'], 'UTC') self.assertEquals(events[1]['start'], datetime(2014, 1, 19, 15, 0, tzinfo=pytz.UTC)) self.assertEquals(events[1]['end'], datetime(2014, 1, 19, 16, 0, tzinfo=pytz.UTC)) self.assertEquals(events[1]['whole_day'], False) self.assertEquals(events[1]['cat1'], set(['cat13', 'cat14'])) self.assertEquals(events[1]['cat2'], set(['cat21', 'cat22', 'cat23'])) # Filter by categories context.do_filter = False context.cat1 = 'cat5' context.cat2 = 'cat6' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 2) context.do_filter = True context.cat1 = '' context.cat2 = '' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 2) context.cat1 = 'cat1' context.cat2 = '' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 0) context.cat1 = 'cat11' context.cat2 = '' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 1) self.assertEquals(events[0]['cat1'], set(['cat11', 'cat12'])) context.cat1 = 'cat12' context.cat2 = '' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 1) self.assertEquals(events[0]['cat1'], set(['cat11', 'cat12'])) context.cat1 = '' context.cat2 = 'cat23' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 1) self.assertEquals(events[0]['cat2'], set(['cat21', 'cat22', 'cat23'])) context.cat1 = '' context.cat2 = 'cat24' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 0) context.do_filter = True context.cat1 = 'cat11' context.cat2 = 'cat21' source = EventsSourceSeantisJson(context) events = [event for event in source.fetch(json_string)] self.assertEquals(len(events), 1) self.assertEquals(events[0]['cat1'], set(['cat11', 'cat12'])) self.assertEquals(events[0]['cat2'], set(['cat21']))
def test_seantis_import_build_url(self): context = mock.Mock() context.url = ' http://www.ex.ch/ev/ ' context.do_filter = False context.import_imported = False context.cat1 = '' context.cat2 = '' source = EventsSourceSeantisJson(context) self.assertEquals( source.build_url(), 'http://www.ex.ch/ev/?type=json&compact=true' ) context.url = ' http://www.ex.ch/ev ' source = EventsSourceSeantisJson(context) self.assertEquals( source.build_url(), 'http://www.ex.ch/ev?type=json&compact=true' ) context.do_filter = True source = EventsSourceSeantisJson(context) self.assertEquals( source.build_url(), 'http://www.ex.ch/ev?type=json&compact=true' ) context.cat1 = 'cat1' source = EventsSourceSeantisJson(context) self.assertEquals( source.build_url(), 'http://www.ex.ch/ev?type=json&compact=true&filter=true&cat1=cat1' ) context.cat1 = '' context.cat2 = 'cat2' source = EventsSourceSeantisJson(context) self.assertEquals( source.build_url(), 'http://www.ex.ch/ev?type=json&compact=true&filter=true&cat2=cat2' ) context.cat1 = 'cat1' source = EventsSourceSeantisJson(context) self.assertEquals( source.build_url(), 'http://www.ex.ch/ev?type=json&compact=true&filter=true' '&cat1=cat1&cat2=cat2' ) context.import_imported = True source = EventsSourceSeantisJson(context) self.assertEquals( source.build_url(), 'http://www.ex.ch/ev?type=json&compact=true&imported=1&filter=true' '&cat1=cat1&cat2=cat2' )