def test_multiple_notification_preference(self): """ Test to check for the notification preferences list values """ notification_preference_daily = NotificationPreference( name='daily-digest-emails', display_name='Daily Emails', display_description='Daily Digestion Email ', default_value='false') notification_preference_weekly = NotificationPreference( name='weekly-digest-emails', display_name='Weekly Emails', display_description='Weekly Digestion Email ', default_value='false') notification_preference1 = set_notification_preference( notification_preference_daily) notification_preference2 = set_notification_preference( notification_preference_weekly) response = self.client.get( reverse('edx_notifications.consumer.notification_preferences')) self.assertEqual(response.status_code, 200) results = json.loads(response.content.decode('utf-8')) self.assertEqual(len(results), 2) self._compare_notification_preference_to_result( notification_preference1, results[0]) self._compare_notification_preference_to_result( notification_preference2, results[1])
def test_multiple_notification_preference(self): """ Test to check for the notification preferences list values """ notification_preference_daily = NotificationPreference( name='daily-digest-emails', display_name='Daily Emails', display_description='Daily Digestion Email ', default_value='false' ) notification_preference_weekly = NotificationPreference( name='weekly-digest-emails', display_name='Weekly Emails', display_description='Weekly Digestion Email ', default_value='false' ) notification_preference1 = set_notification_preference(notification_preference_daily) notification_preference2 = set_notification_preference(notification_preference_weekly) response = self.client.get(reverse('edx_notifications.consumer.notification_preferences')) self.assertEqual(response.status_code, 200) results = json.loads(response.content) self.assertEqual(len(results), 2) self._compare_notification_preference_to_result(notification_preference1, results[0]) self._compare_notification_preference_to_result(notification_preference2, results[1])
def test_single_digest(self): """ Make sure when we select one digest, the other preference is de-selected """ notification_preference_daily = NotificationPreference( name=const.NOTIFICATION_DAILY_DIGEST_PREFERENCE_NAME, display_name='Daily Emails', display_description='Daily Digestion Email ', default_value='false') set_notification_preference(notification_preference_daily) notification_preference_weekly = NotificationPreference( name=const.NOTIFICATION_WEEKLY_DIGEST_PREFERENCE_NAME, display_name='Daily Emails', display_description='Daily Digestion Email ', default_value='false') set_notification_preference(notification_preference_weekly) response = self.client.post(reverse( 'edx_notifications.consumer.user_preferences.detail', args=[const.NOTIFICATION_DAILY_DIGEST_PREFERENCE_NAME]), data={'value': 'true'}) self.assertEqual(response.status_code, 200) response = self.client.post(reverse( 'edx_notifications.consumer.user_preferences.detail', args=[const.NOTIFICATION_WEEKLY_DIGEST_PREFERENCE_NAME]), data={'value': 'false'}) self.assertEqual(response.status_code, 200) # now set the weekly and make sure the daily gets turned off response = self.client.post(reverse( 'edx_notifications.consumer.user_preferences.detail', args=[const.NOTIFICATION_WEEKLY_DIGEST_PREFERENCE_NAME]), data={'value': 'true'}) self.assertEqual(response.status_code, 200) response = self.client.get( reverse('edx_notifications.consumer.user_preferences.detail', args=[const.NOTIFICATION_DAILY_DIGEST_PREFERENCE_NAME])) self.assertEqual(response.status_code, 200) results = json.loads(response.content.decode('utf-8')) self.assertEqual(len(results), 1) self.assertEqual(results[0]['value'], 'false') response = self.client.get( reverse('edx_notifications.consumer.user_preferences.detail', args=[const.NOTIFICATION_WEEKLY_DIGEST_PREFERENCE_NAME])) self.assertEqual(response.status_code, 200) results = json.loads(response.content.decode('utf-8')) self.assertEqual(len(results), 1) self.assertEqual(results[0]['value'], 'true')
def test_get_specific_user_preferences(self): """ Test specific preference setting for the user """ # test bad preference name send 400 error response response = self.client.get( reverse('edx_notifications.consumer.user_preferences.detail', args=['bad-name'])) self.assertEqual(response.status_code, 404) notification_preference_daily = NotificationPreference( name='daily-digest-emails', display_name='Daily Emails', display_description='Daily Digestion Email ', default_value='false') notification_preference = set_notification_preference( notification_preference_daily) user_preference = set_user_notification_preference( 1, notification_preference.name, 'Test User 1') # hit the api with the valid preference name response = self.client.get( reverse('edx_notifications.consumer.user_preferences.detail', args=['daily-digest-emails'])) self.assertEqual(response.status_code, 200) results = json.loads(response.content.decode('utf-8')) self.assertEqual(len(results), 1) self.assertEqual(user_preference.user_id, results[0]['user_id']) self.assertEqual(user_preference.value, results[0]['value']) self._compare_notification_preference_to_result( user_preference.preference, results[0]['preference'])
def test_user_preferences_list(self): """ Test User Preferences List """ notification_preference_daily = NotificationPreference( name='daily-digest-emails', display_name='Daily Emails', display_description='Daily Digestion Email ', default_value='false') notification_preference = set_notification_preference( notification_preference_daily) user_preference = set_user_notification_preference( 1, notification_preference.name, 'Test User 1') response = self.client.get( reverse('edx_notifications.consumer.user_preferences')) self.assertEqual(response.status_code, 200) results = json.loads(response.content.decode('utf-8')) self.assertEqual(len(results), 1) self.assertEqual(user_preference.user_id, results[0]['user_id']) self.assertEqual(user_preference.value, results[0]['value']) self._compare_notification_preference_to_result( user_preference.preference, results[0]['preference'])
def test_get_specific_user_preferences(self): """ Test specific preference setting for the user """ # test bad preference name send 400 error response response = self.client.get( reverse('edx_notifications.consumer.user_preferences.detail', args=['bad-name'])) self.assertEqual(response.status_code, 404) notification_preference_daily = NotificationPreference( name='daily-digest-emails', display_name='Daily Emails', display_description='Daily Digestion Email ', default_value='false' ) notification_preference = set_notification_preference(notification_preference_daily) user_preference = set_user_notification_preference( 1, notification_preference.name, 'Test User 1' ) # hit the api with the valid preference name response = self.client.get( reverse('edx_notifications.consumer.user_preferences.detail', args=['daily-digest-emails'])) self.assertEqual(response.status_code, 200) results = json.loads(response.content) self.assertEqual(len(results), 1) self.assertEqual(user_preference.user_id, results[0]['user_id']) self.assertEqual(user_preference.value, results[0]['value']) self._compare_notification_preference_to_result(user_preference.preference, results[0]['preference'])
def test_user_preferences_list(self): """ Test User Preferences List """ notification_preference_daily = NotificationPreference( name='daily-digest-emails', display_name='Daily Emails', display_description='Daily Digestion Email ', default_value='false' ) notification_preference = set_notification_preference(notification_preference_daily) user_preference = set_user_notification_preference( 1, notification_preference.name, 'Test User 1' ) response = self.client.get(reverse('edx_notifications.consumer.user_preferences')) self.assertEqual(response.status_code, 200) results = json.loads(response.content) self.assertEqual(len(results), 1) self.assertEqual(user_preference.user_id, results[0]['user_id']) self.assertEqual(user_preference.value, results[0]['value']) self._compare_notification_preference_to_result(user_preference.preference, results[0]['preference'])
def test_set_specific_user_preferences(self): """ Test to set the specific user preferences. """ notification_preference_daily = NotificationPreference( name='daily-digest-emails', display_name='Daily Emails', display_description='Daily Digestion Email ', default_value='false') set_notification_preference(notification_preference_daily) data = {'value': "true"} # post the api with the valid data # this will create a new user preference response = self.client.post(reverse( 'edx_notifications.consumer.user_preferences.detail', args=['daily-digest-emails']), data=data) self.assertEqual(response.status_code, 200) data = {'value': "false"} # post the api with the valid data # this will create a new user preference response = self.client.post(reverse( 'edx_notifications.consumer.user_preferences.detail', args=['daily-digest-emails']), data=data) self.assertEqual(response.status_code, 200) data = {} # missing value in json gives 404 error response = self.client.post(reverse( 'edx_notifications.consumer.user_preferences.detail', args=['daily-digest-emails']), data=data) self.assertEqual(response.status_code, 404) # valid data and invalid arg in the url gives 404 error data.clear() data = {'value': 'User Preference updated Value'} response = self.client.post(reverse( 'edx_notifications.consumer.user_preferences.detail', args=['invalid-value']), data=data) self.assertEqual(response.status_code, 404) # post the api with the valid data response = self.client.post(reverse( 'edx_notifications.consumer.user_preferences.detail', args=['daily-digest-emails']), data=data) self.assertEqual(response.status_code, 200) # now check if the data is updated response = self.client.get( reverse('edx_notifications.consumer.user_preferences.detail', args=['daily-digest-emails'])) self.assertEqual(response.status_code, 200) results = json.loads(response.content.decode('utf-8')) self.assertEqual(len(results), 1) self.assertEqual(data['value'], results[0]['value'])
def test_single_digest(self): """ Make sure when we select one digest, the other preference is de-selected """ notification_preference_daily = NotificationPreference( name=const.NOTIFICATION_DAILY_DIGEST_PREFERENCE_NAME, display_name='Daily Emails', display_description='Daily Digestion Email ', default_value='false' ) set_notification_preference(notification_preference_daily) notification_preference_weekly = NotificationPreference( name=const.NOTIFICATION_WEEKLY_DIGEST_PREFERENCE_NAME, display_name='Daily Emails', display_description='Daily Digestion Email ', default_value='false' ) set_notification_preference(notification_preference_weekly) response = self.client.post( reverse( 'edx_notifications.consumer.user_preferences.detail', args=[const.NOTIFICATION_DAILY_DIGEST_PREFERENCE_NAME] ), data={ 'value': 'true' } ) self.assertEqual(response.status_code, 200) response = self.client.post( reverse( 'edx_notifications.consumer.user_preferences.detail', args=[const.NOTIFICATION_WEEKLY_DIGEST_PREFERENCE_NAME] ), data={ 'value': 'false' } ) self.assertEqual(response.status_code, 200) # now set the weekly and make sure the daily gets turned off response = self.client.post( reverse( 'edx_notifications.consumer.user_preferences.detail', args=[const.NOTIFICATION_WEEKLY_DIGEST_PREFERENCE_NAME] ), data={ 'value': 'true' } ) self.assertEqual(response.status_code, 200) response = self.client.get( reverse( 'edx_notifications.consumer.user_preferences.detail', args=[const.NOTIFICATION_DAILY_DIGEST_PREFERENCE_NAME] )) self.assertEqual(response.status_code, 200) results = json.loads(response.content) self.assertEqual(len(results), 1) self.assertEqual(results[0]['value'], 'false') response = self.client.get( reverse( 'edx_notifications.consumer.user_preferences.detail', args=[const.NOTIFICATION_WEEKLY_DIGEST_PREFERENCE_NAME] )) self.assertEqual(response.status_code, 200) results = json.loads(response.content) self.assertEqual(len(results), 1) self.assertEqual(results[0]['value'], 'true')
def test_set_specific_user_preferences(self): """ Test to set the specific user preferences. """ notification_preference_daily = NotificationPreference( name='daily-digest-emails', display_name='Daily Emails', display_description='Daily Digestion Email ', default_value='false' ) set_notification_preference(notification_preference_daily) data = {'value': "true"} # post the api with the valid data # this will create a new user preference response = self.client.post( reverse('edx_notifications.consumer.user_preferences.detail', args=['daily-digest-emails']), data=data ) self.assertEqual(response.status_code, 200) data = {'value': "false"} # post the api with the valid data # this will create a new user preference response = self.client.post( reverse('edx_notifications.consumer.user_preferences.detail', args=['daily-digest-emails']), data=data ) self.assertEqual(response.status_code, 200) data = {} # missing value in json gives 404 error response = self.client.post( reverse('edx_notifications.consumer.user_preferences.detail', args=['daily-digest-emails']), data=data ) self.assertEqual(response.status_code, 404) # valid data and invalid arg in the url gives 404 error data.clear() data = {'value': 'User Preference updated Value'} response = self.client.post( reverse('edx_notifications.consumer.user_preferences.detail', args=['invalid-value']), data=data ) self.assertEqual(response.status_code, 404) # post the api with the valid data response = self.client.post( reverse('edx_notifications.consumer.user_preferences.detail', args=['daily-digest-emails']), data=data ) self.assertEqual(response.status_code, 200) # now check if the data is updated response = self.client.get( reverse('edx_notifications.consumer.user_preferences.detail', args=['daily-digest-emails'])) self.assertEqual(response.status_code, 200) results = json.loads(response.content) self.assertEqual(len(results), 1) self.assertEqual(data['value'], results[0]['value'])