Esempio n. 1
0
class TestCreateMessageCommand(unittest.TestCase):

    def setUp(self):
        self.client = client.PushwooshClient()
        self.notification = Notification()
        self.notification.content = 'Hello world!'
        self.auth = 'test_auth'
        self.code = '0000-0000'

    def test_valid_create_by_application(self):
        expected_result = {
            'request': {
                'application': self.code,
                'auth': self.auth,
                'notifications': [
                    {
                        'content': 'Hello world!',
                        'send_date': 'now'
                    }
                ]
            }
        }
        self.command = CreateMessageForApplicationCommand(self.notification, application=self.code)
        self.command.auth = self.auth

        command_dict = json.loads(self.command.render())
        self.assertDictEqual(command_dict, expected_result)

    def test_valid_create_by_application_group(self):
        expected_result = {
            'request': {
                'applications_group': self.code,
                'auth': self.auth,
                'notifications': [
                    {
                        'content': 'Hello world!',
                        'send_date': 'now'
                    }
                ]
            }
        }
        self.command = CreateMessageForApplicationGroupCommand(self.notification, application_group=self.code)
        self.command.auth = self.auth

        command_dict = json.loads(self.command.render())
        self.assertDictEqual(command_dict, expected_result)

    def test_create_message_without_application(self):
        self.command = CreateMessageForApplicationCommand(self.notification)
        self.command.auth = self.auth
        self.assertRaises(PushwooshCommandException, self.command.compile)

    def test_create_message_without_application_group(self):
        self.command = CreateMessageForApplicationGroupCommand(self.notification)
        self.command.auth = self.auth
        self.assertRaises(PushwooshCommandException, self.command.compile)