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)
    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)
Esempio n. 3
0
    def test_valid_create_by_application_group(self):
        self.command = CreateMessageForApplicationGroupCommand(
            self.notification, application_group=PW_APP_GROUP_CODE)
        self.command.auth = self.auth
        response = self.client.invoke(self.command)

        self.assertEqual(response['status_code'], HTTP_200_OK)
        self.assertEqual(response['status_message'], STATUS_OK)
        self.assertEqual(True, 'Messages' in response['response'])
    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_valid_create_by_user(self):
        users_list = ['user_1', 'user_2']
        expected_result = {
            'request': {
                'application': self.code,
                'auth': self.auth,
                'notifications': [
                    {
                        'content': 'Hello world!',
                        'send_date': 'now',
                        'users': users_list,
                    }
                ]
            }
        }

        self.notification.users = users_list
        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_user(self):
        users_list = ['user_1', 'user_2']
        expected_result = {
            'request': {
                'application':
                self.code,
                'auth':
                self.auth,
                'notifications': [{
                    'content': 'Hello world!',
                    'send_date': 'now',
                    'users': users_list,
                }]
            }
        }

        self.notification.users = users_list
        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_create_message_without_application_group(self):
     self.command = CreateMessageForApplicationGroupCommand(self.notification)
     self.command.auth = self.auth
     self.assertRaises(PushwooshCommandException, self.command.compile)
Esempio n. 8
0
 def test_create_message_without_application_group(self):
     self.command = CreateMessageForApplicationGroupCommand(self.notification)
     self.command.auth = self.auth
     self.assertRaises(PushwooshCommandException, self.command.compile)