Skip to content

Commit

Permalink
test: Add test for experiment collection with social media config, th…
Browse files Browse the repository at this point in the history
…ereby also testing the social media config serializer
  • Loading branch information
drikusroor committed Jul 2, 2024
1 parent 333fa6d commit b503358
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions backend/experiment/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ExperimentCollection,
Phase,
GroupedExperiment,
SocialMediaConfig,
)
from experiment.rules.hooked import Hooked
from participant.models import Participant
Expand All @@ -28,8 +29,9 @@ def setUpTestData(cls):
collection = ExperimentCollection.objects.create(
name='Test Series',
slug='test_series',
theme_config=theme_config
theme_config=theme_config,
)
collection.social_media_config = create_social_media_config(collection)
introductory_phase = Phase.objects.create(
name='introduction',
series=collection,
Expand Down Expand Up @@ -108,6 +110,10 @@ def test_get_experiment_collection(self):
self.assertEqual(len(response_json['theme']['header']['score']), 3)
self.assertEqual(response_json.get('theme').get('footer').get(
'disclaimer'), '<p>Test Disclaimer</p>')
self.assertEqual(response_json.get('socialMedia').get('url'), 'https://www.example.com')
self.assertEqual(response_json.get('socialMedia').get('content'), 'Test Content')
self.assertEqual(response_json.get('socialMedia').get('tags'), ['aml', 'toontjehoger'])
self.assertEqual(response_json.get('socialMedia').get('channels'), ['facebook', 'twitter', 'weibo'])

def test_get_experiment_collection_not_found(self):
# if ExperimentCollection does not exist, return 404
Expand Down Expand Up @@ -257,7 +263,7 @@ def test_get_experiment(self):
)


def create_theme_config():
def create_theme_config() -> ThemeConfig:
theme_config = ThemeConfig.objects.create(
name='test_theme',
description='Test Theme',
Expand All @@ -278,3 +284,14 @@ def create_theme_config():
footer_config.logos.add(Image.objects.create(file='test-logo.jpg'))

return theme_config


def create_social_media_config(
collection: ExperimentCollection) -> SocialMediaConfig:
return SocialMediaConfig.objects.create(
experiment_collection=collection,
url='https://www.example.com',
content='Test Content',
channels=['facebook', 'twitter', 'weibo'],
tags=['aml', 'toontjehoger']
)

0 comments on commit b503358

Please sign in to comment.