Skip to content

Commit

Permalink
Fixed: Add improved check for social_media_config existence and add t…
Browse files Browse the repository at this point in the history
…est (#1183)

* fix: Add improved check for social_media_config existence in experiment collection serializer

* fix(test): Update test after new experiment/block urls
  • Loading branch information
drikusroor authored Jul 12, 2024
1 parent efd6595 commit 93c3529
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
3 changes: 2 additions & 1 deletion backend/experiment/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def serialize_experiment_collection(
filter_name='markdown'
)

if experiment_collection.social_media_config:
if (hasattr(experiment_collection, 'social_media_config')
and experiment_collection.social_media_config):
serialized['socialMedia'] = serialize_social_media_config(
experiment_collection.social_media_config
)
Expand Down
30 changes: 28 additions & 2 deletions backend/experiment/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,32 @@ def test_get_experiment_collection_inactive(self):
response = self.client.get('/experiment/test_series/')
self.assertEqual(response.status_code, 404)

def test_get_experiment_without_social_media(self):
session = self.client.session
session['participant_id'] = self.participant.id
session.save()
Session.objects.create(
block=self.block1,
participant=self.participant,
finished_at=timezone.now()
)
intermediate_phase = Phase.objects.get(
name='intermediate'
)
intermediate_phase.dashboard = True
intermediate_phase.save()

ExperimentCollection.objects.create(
name='No Social Media',
slug='no_social_media',
theme_config=create_theme_config(name='no_social_media')
)

response = self.client.get('/experiment/no_social_media/')

self.assertEqual(response.status_code, 200)
self.assertNotIn('socialMedia', response.json())

def test_experiment_collection_with_dashboard(self):
# if ExperimentCollection has dashboard set True, return list of random blocks
session = self.client.session
Expand Down Expand Up @@ -271,9 +297,9 @@ def test_get_block(self):
)


def create_theme_config() -> ThemeConfig:
def create_theme_config(name='test_theme') -> ThemeConfig:
theme_config = ThemeConfig.objects.create(
name='test_theme',
name=name,
description='Test Theme',
heading_font_url='https://fonts.googleapis.com/css2?family=Architects+Daughter&family=Micro+5&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap',
body_font_url='https://fonts.googleapis.com/css2?family=Architects+Daughter&family=Micro+5&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap',
Expand Down

0 comments on commit 93c3529

Please sign in to comment.