-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from the old csv API to use the new JSON API with minimal changes to the old importer. refs: LINK-2237
- Loading branch information
Showing
5 changed files
with
162 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"EventCalendar": "EventCalendar", | ||
"Events": [ | ||
{ | ||
"EventPromoterId": "999", | ||
"EventPromoterName": "Helsingin Kaupunginteatteri", | ||
"EventSerieId": "1231231", | ||
"EventId": "11116307", | ||
"EventName": "PIENET JUHLAT", | ||
"EventDate": "24.04.2020", | ||
"EventDayOfWeek": "Pe", | ||
"EventTime": "19:00", | ||
"EventDeliverable": "1", | ||
"EventStatus": "2", | ||
"EventVenue": "Testi Teatteri, Suuri näyttämö", | ||
"EventStreet": "Testitie 123", | ||
"EventZip": "1337", | ||
"EventPlace": "Tampere", | ||
"EventLinkFi": "https://www.lippu.fi/tickets.html?affiliate=adv&fun=evdetail&doc=evdetailb&key=1231231$11116307&language=fi", | ||
"EventLinkSv": "https://www.lippu.fi/tickets.html?affiliate=adv&fun=evdetail&doc=evdetailb&key=1231231$11116307&language=sv", | ||
"EventLinkEn": "https://www.lippu.fi/tickets.html?affiliate=adv&fun=evdetail&doc=evdetailb&key=1231231$11116307&language=en", | ||
"LinkEventUrlFi": "", | ||
"EventCapacity": "313", | ||
"EventAvailable": "100", | ||
"EventSold": "200", | ||
"EventReserved": "13", | ||
"EventSeriePictureSmall_60x60": "https://www.lippu.fi/obj/media/FI-eventim/teaser/blank.gif", | ||
"EventSeriePicture_142x180": "https://www.lippu.fi/obj/media/FI-eventim/teaser/blank.gif", | ||
"EventSeriePictureBig_222x222": "https://www.lippu.fi/obj/media/FI-eventim/teaser/blank.gif", | ||
"EventSerieInfo": "<b>Huom!</b>Muista ottaa liput mukaan", | ||
"EventSerieText": ",<b>Pienet juhlat</b> on klassikkonäytelmä \"hurmuri\" Taunosta", | ||
"EventSearchText": "Testi Teatteri Pienet juhlat Tampere", | ||
"EventSerieLinkFi": "https://www.lippu.fi/tickets.html?affiliate=adv&doc=erdetaila&fun=erdetail&erid=1231231&language=fi", | ||
"EventSerieLinkSv": "https://www.lippu.fi/tickets.html?affiliate=adv&doc=erdetaila&fun=erdetail&erid=1231231&language=sv", | ||
"EventSerieLinkEn": "https://www.lippu.fi/tickets.html?affiliate=adv&doc=erdetaila&fun=erdetail&erid=1231231&language=en", | ||
"TdlEventSerieId": "234234", | ||
"TdlEventId": "123123", | ||
"LiveXLinkFi": "", | ||
"LiveXLinkSv": "", | ||
"LiveXLinkEn": "", | ||
"Categories": [ | ||
{ | ||
"CategoryId": "2B", | ||
"Name": "Draama" | ||
}, | ||
{ | ||
"CategoryId": "XY", | ||
"Name": "Peruutukset ja muutokset" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import json | ||
from copy import deepcopy | ||
|
||
import pytest | ||
from django.conf import settings | ||
|
||
from events.importer.lippupiste import LippupisteImporter | ||
from events.models import Event | ||
from events.tests.factories import DataSourceFactory, KeywordFactory | ||
|
||
|
||
@pytest.fixture | ||
def importer(): | ||
importer = LippupisteImporter({"force": False}) | ||
importer.setup() | ||
return importer | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def tprek_datasource(): | ||
return DataSourceFactory(id="tprek") | ||
|
||
|
||
@pytest.fixture | ||
def yso_datasource(): | ||
return DataSourceFactory(id="yso") | ||
|
||
|
||
@pytest.fixture | ||
def drama_keyword(yso_datasource): | ||
return KeywordFactory(id="yso:p2625", data_source=yso_datasource, name="Draama") | ||
|
||
|
||
@pytest.fixture | ||
def response_with_one_event(request): | ||
with open(request.path.parent / "fixtures/lippupiste_response.json", "r") as f: | ||
return json.load(f) | ||
|
||
|
||
@pytest.fixture | ||
def response_with_two_events_same_super_event(response_with_one_event): | ||
response = deepcopy(response_with_one_event) | ||
event_2 = deepcopy(response["Events"][0]) | ||
event_2["EventId"] += "1" | ||
response["Events"].append(event_2) | ||
return response | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_lippupiste_event_parse( | ||
requests_mock, drama_keyword, importer, response_with_one_event | ||
): | ||
requests_mock.get(settings.LIPPUPISTE_EVENT_API_URL, json=response_with_one_event) | ||
importer.import_events() | ||
|
||
events = Event.objects.all() | ||
assert events.count() == 1 | ||
assert drama_keyword in events[0].keywords.all() | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_lippupiste_super_event( | ||
requests_mock, importer, response_with_two_events_same_super_event | ||
): | ||
requests_mock.get( | ||
settings.LIPPUPISTE_EVENT_API_URL, | ||
json=response_with_two_events_same_super_event, | ||
) | ||
importer.import_events() | ||
assert Event.objects.all().count() == 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters