def test_update_existing_email_destination(self): destination = DestinationConfigFactory( user=self.user, media_id="email", settings={ "email_address": "*****@*****.**", "synced": False }, ) request = self.request_factory.post("/") request.user = self.user validated_data = { "media_id": "email", "settings": { "email_address": "*****@*****.**", "synced": False, }, "user": self.user, } serializer = RequestDestinationConfigSerializer( context={"request": request}, ) obj = serializer.update(destination, validated_data) self.assertEqual(obj.settings["email_address"], "*****@*****.**")
def test_validate_new_email_destination_with_empty_settings(self): request = self.request_factory.post("/") request.user = self.user data = { "media": "email", "settings": {}, } serializer = RequestDestinationConfigSerializer( data=data, context={"request": request}, ) self.assertFalse(serializer.is_valid()) self.assertTrue(serializer.errors)
def test_validate_new_email_destination(self): request = self.request_factory.post("/") request.user = self.user data = { "media": "email", "settings": { "email_address": "*****@*****.**", }, } serializer = RequestDestinationConfigSerializer( data=data, context={"request": request}, ) self.assertTrue(serializer.is_valid(), serializer.errors)
def test_validate_new_sms_destination_with_empty_settings(self): if not "sms" in MEDIA_CLASSES_DICT.keys(): self.skipTest("No sms plugin available") request = self.request_factory.post("/") request.user = self.user data = { "media": "sms", "settings": {}, } serializer = RequestDestinationConfigSerializer( data=data, context={"request": request}, ) self.assertFalse(serializer.is_valid()) self.assertTrue(serializer.errors)
def test_create_new_sms_destination(self): if not "sms" in MEDIA_CLASSES_DICT.keys(): self.skipTest("No sms plugin available") request = self.request_factory.post("/") request.user = self.user validated_data = { "media_id": "sms", "settings": { "phone_number": "+4747474747", }, "user": self.user, } serializer = RequestDestinationConfigSerializer( context={"request": request}, ) obj = serializer.create(validated_data) self.assertEqual( obj.settings, { "phone_number": "+4747474747", }, )
def test_create_new_email_destination(self): request = self.request_factory.post("/") request.user = self.user validated_data = { "media_id": "email", "settings": { "email_address": "*****@*****.**", "synced": False, }, "user": self.user, } serializer = RequestDestinationConfigSerializer( context={"request": request}, ) obj = serializer.create(validated_data) self.assertEqual( obj.settings, { "email_address": "*****@*****.**", "synced": False, }, )
def test_validate_new_email_destination_with_additional_settings(self): request = self.request_factory.post("/") request.user = self.user data = { "media": "email", "settings": { "email_address": "*****@*****.**", "extra_key": "something", }, } serializer = RequestDestinationConfigSerializer( data=data, context={"request": request}, ) self.assertTrue(serializer.is_valid()) self.assertEqual( serializer.validated_data["settings"], { "email_address": "*****@*****.**", "synced": False, }, )
def test_validate_new_sms_destination_with_additional_settings(self): if not "sms" in MEDIA_CLASSES_DICT.keys(): self.skipTest("No sms plugin available") request = self.request_factory.post("/") request.user = self.user data = { "media": "sms", "settings": { "phone_number": "+4747474747", "extra_key": "something", }, } serializer = RequestDestinationConfigSerializer( data=data, context={"request": request}, ) self.assertTrue(serializer.is_valid()) self.assertEqual( serializer.validated_data["settings"], { "phone_number": "+4747474747", }, )