Exemplo n.º 1
0
    def test_local_schedule_success(self):
        with mock.patch.object(ua.Airship, '_request') as mock_request:
            response = requests.Response()
            response._content = json.dumps(
                {
                    'schedule_urls': [
                        (
                            'https://go.urbanairship.com/api/schedules/'
                            '0492662a-1b52-4343-a1f9-c6b0c72931c0'
                        )
                    ]
                }
            ).encode('utf-8')
            response.status_code = 202
            mock_request.return_value = response

            airship = ua.Airship('key', 'secret')
            sched = ua.ScheduledPush(airship)
            push = airship.create_push()
            push.audience = ua.all_
            push.notification = ua.notification(alert='Hello')
            push.device_types = ua.all_
            sched.push = push
            sched.schedule = ua.local_scheduled_time(datetime.datetime.now())
            sched.send()

            self.assertEquals(
                sched.url,
                (
                    'https://go.urbanairship.com/api/schedules/'
                    '0492662a-1b52-4343-a1f9-c6b0c72931c0'
                )
            )
Exemplo n.º 2
0
    def test_local_schedule_success(self):
        with mock.patch.object(ua.Airship, '_request') as mock_request:
            response = requests.Response()
            response._content = json.dumps(
                {
                    'schedule_urls': [
                        (
                            'https://go.urbanairship.com/api/schedules/'
                            '0492662a-1b52-4343-a1f9-c6b0c72931c0'
                        )
                    ]
                }
            ).encode('utf-8')
            response.status_code = 202
            mock_request.return_value = response

            airship = ua.Airship('key', 'secret')
            sched = ua.ScheduledPush(airship)
            push = airship.create_push()
            push.audience = ua.all_
            push.notification = ua.notification(alert='Hello')
            push.device_types = ua.all_
            sched.push = push
            sched.schedule = ua.local_scheduled_time(datetime.datetime.now())
            sched.send()

            self.assertEquals(
                sched.url,
                (
                    'https://go.urbanairship.com/api/schedules/'
                    '0492662a-1b52-4343-a1f9-c6b0c72931c0'
                )
            )
Exemplo n.º 3
0
def create_plt_obj(test, airship):
	plt = airship.create_scheduled_push()
	plt.push(test, airship)
	plt_info = test['plt']
	
	if 'name' in plt_info:
		plt.name = plt_info['name']
	
	if 'time' in plt_info:
		plt_time = datetime.datetime.strptime(plt_info['time'], 
			'%Y-%m-%dT%H:%M:%S')
		plt.schedule = ua.local_scheduled_time(plt_time)

	return plt
Exemplo n.º 4
0
    def test_local_scheduled_payload(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(alert='Hello')
        p.options = ua.options(10080)
        p.device_types = ua.all_
        p.message = ua.message(
            title='Title',
            body='Body',
            content_type='text/html',
            content_encoding='utf8',
        )

        sched = ua.ScheduledPush(None)
        sched.push = p
        sched.name = 'a schedule in device local time'
        sched.schedule = ua.local_scheduled_time(
            datetime.datetime(2015, 1, 1, 12, 0, 0))

        self.assertEqual(
            sched.payload, {
                'name': 'a schedule in device local time',
                'schedule': {
                    'local_scheduled_time': '2015-01-01T12:00:00'
                },
                'push': {
                    'audience': 'all',
                    'notification': {
                        'alert': 'Hello'
                    },
                    'device_types': 'all',
                    'options': {
                        'expiry': 10080
                    },
                    'message': {
                        'title': 'Title',
                        'body': 'Body',
                        'content_type': 'text/html',
                        'content_encoding': 'utf8'
                    },
                }
            })
Exemplo n.º 5
0
    def test_local_scheduled_payload(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(alert='Hello')
        p.options = ua.options(10080)
        p.device_types = ua.all_
        p.message = ua.message(
            title='Title',
            body='Body',
            content_type='text/html',
            content_encoding='utf8',
        )

        sched = ua.ScheduledPush(None)
        sched.push = p
        sched.name = 'a schedule in device local time'
        sched.schedule = ua.local_scheduled_time(
            datetime.datetime(2015, 1, 1, 12, 0, 0)
        )

        self.assertEqual(sched.payload, {
            'name': 'a schedule in device local time',
            'schedule': {'local_scheduled_time': '2015-01-01T12:00:00'},
            'push': {
                'audience': 'all',
                'notification': {'alert': 'Hello'},
                'device_types': 'all',
                'options': {
                    'expiry': 10080
                },
                'message': {
                    'title': 'Title',
                    'body': 'Body',
                    'content_type': 'text/html',
                    'content_encoding': 'utf8'
                },
            }
        })
Exemplo n.º 6
0
 def test_local_scheduled_time(self):
     d = datetime.datetime(2015, 1, 1, 12, 56)
     self.assertEqual(
         ua.local_scheduled_time(d),
         {'local_scheduled_time': '2015-01-01T12:56:00'}
     )
Exemplo n.º 7
0
 def test_local_scheduled_time(self):
     d = datetime.datetime(2015, 1, 1, 12, 56)
     self.assertEqual(ua.local_scheduled_time(d),
                      {'local_scheduled_time': '2015-01-01T12:56:00'})