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_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", }, )