def test_valid_filter(self): app_code = '0000-0000' tag_name = 'test_string' tag_value = 'test value' expected_result = '(((A("%s") + T("%s", EQ, "%s")) * A("%s")) \ T("%s", EQ, "%s"))' % \ (app_code, tag_name, tag_value, app_code, tag_name, tag_value) tag_filter = StringTagFilter(tag_name, constants.TAG_FILTER_OPERATOR_EQ, tag_value) app_filter = ApplicationFilter(app_code) union_filter = app_filter.union(tag_filter) intersect_filter = union_filter.intersect(app_filter) subtract_filter = intersect_filter.subtract(tag_filter) self.assertEqual(subtract_filter.__str__(), expected_result)
def test_valid_create(self): self.command.devices_filter = ApplicationFilter(PW_APP_CODE) response = self.client.invoke(self.command) self.assertEqual(response['status_code'], HTTP_200_OK) self.assertEqual(response['status_message'], STATUS_OK) self.assertEqual(True, 'messageCode' in response['response'])
def get_message(self): command = CreateTargetedMessageCommand() command.auth = PW_TOKEN command.content = "Hello world!" command.devices_filter = ApplicationFilter(PW_APP_CODE) tomorrow = datetime.datetime.today() + datetime.timedelta(1) command.send_date = tomorrow.strftime('%Y-%m-%d %H:%M:%S') response = self.client.invoke(command) return response['response']['messageCode']
def test_valid_compile_filter(self): auth = 'test_auth' expected_result = { 'request': { 'devices_filter': 'A("%s")' % self.code, 'auth': auth } } self.command.auth = auth self.command.devices_filter = ApplicationFilter(self.code) command_dict = json.loads(self.command.render()) self.assertDictEqual(command_dict, expected_result)
def test_valid_create(self): expected_result = { 'request': { 'devices_filter': 'A("%s")' % self.code, 'auth': self.auth, 'content': 'Hello world!', 'send_date': 'now' } } self.command.devices_filter = ApplicationFilter(self.code) command_dict = json.loads(self.command.render()) self.assertDictEqual(command_dict, expected_result)
def notification_filtered(self): platforms = [constants.PLATFORM_ANDROID, constants.PLATFORM_AMAZON] devices = ['test_push_device_token1', 'test_push_device_token2'] conditions = str( filter.ApplicationFilter('0000-0000').union( ApplicationFilter('0000-0001'))) expected_result = { 'platforms': platforms, 'devices': devices, 'conditions': conditions } self.notification.platforms = platforms self.notification.devices = devices self.notification.conditions = conditions return expected_result
def test_invalid_auth(self): self.command.devices_filter = ApplicationFilter(self.code) self.assertRaises(PushwooshCommandException, self.command.render)