Fix searchable event records having a domain and schema duplicated on the image url

This commit is contained in:
Michael Hall 2018-07-08 22:57:02 -04:00
parent 6ca8c22569
commit 6291ff26e9
2 changed files with 24 additions and 1 deletions

View file

@ -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

View file

@ -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')