From 6291ff26e9a21c749ddf4eb117ca05a25dcb30b4 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sun, 8 Jul 2018 22:57:02 -0400 Subject: [PATCH] Fix searchable event records having a domain and schema duplicated on the image url --- events/models/events.py | 5 ++++- events/tests/federation.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/events/models/events.py b/events/models/events.py index 49efbc6..cf10e44 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -174,7 +174,10 @@ def update_event_searchable(event): searchable.event_url = event_url - searchable.img_url = "%s://%s%s" % (schema, site.domain, event.team.card_img_url) + if event.team.card_img_url.startswith('http:') or event.team.card_img_url.startswith('https:'): + searchable.img_url = event.team.card_img_url + else: + searchable.img_url = "%s://%s%s" % (schema, site.domain, event.team.card_img_url) searchable.event_title = event.name searchable.group_name = event.team.name diff --git a/events/tests/federation.py b/events/tests/federation.py index d2f08fa..42089d1 100644 --- a/events/tests/federation.py +++ b/events/tests/federation.py @@ -3,6 +3,7 @@ from model_mommy import mommy from ..models.events import Event, delete_event_searchable from ..models.search import Searchable +from ..models.profiles import Category, Team # Create your tests here. class SearchableCreationTest(TestCase): @@ -54,4 +55,23 @@ class SearchableCreationTest(TestCase): searchables = Searchable.objects.all() assert(searchables.count() == 0) + def test_searchable_img_url(self): + category = mommy.make(Category, img_url='/test/foo.png') + team = mommy.make(Team, category=category) + event = mommy.make(Event, team=team) + event.save() + searchables = Searchable.objects.all() + assert(searchables.count() == 1) + assert(searchables[0].img_url == 'https://example.com/test/foo.png') + + category.img_url = 'http://test.com/img/bar.png' + category.save() + searchables = Searchable.objects.all() + assert(searchables.count() == 1) + assert(searchables[0].img_url == 'https://example.com/test/foo.png') + + event.save() + searchables = Searchable.objects.all() + assert(searchables.count() == 1) + assert(searchables[0].img_url == 'http://test.com/img/bar.png')