def test_to_binary_string_token_unhexlify_error(self):
        notification = Notification('', '0', None, 0)

        with self.assertRaises(NotificationTokenUnhexlifyError) as ctx:
            notification.to_binary_string()

        self.assertEqual(str(ctx.exception), 'Odd-length string')
示例#2
0
    def test_to_binary_string_token_unhexlify_error(self):
        notification = Notification('', '0', None, 0)

        with self.assertRaises(NotificationTokenUnhexlifyError) as ctx:
            notification.to_binary_string()

        self.assertEqual(str(ctx.exception), 'Odd-length string')
    def test_expire_immediately(self):
        stream = Notification(payload='', token='00', expire=123,
                              priority=0).to_binary_string()
        notification = Notification()
        notification.from_binary_string(stream)

        self.assertEqual(notification.expire, 123)
示例#4
0
    def test_from_binary_string_invalid_id(self):
        now = datetime.now()
        stream = Notification('', '00', now, 0, 123).to_binary_string()
        notification = Notification()
        notification.EXPIRE = -1

        with self.assertRaises(NotificationInvalidIdError):
            notification.from_binary_string(stream)
示例#5
0
    def test_expire_immediately(self):
        stream = Notification(payload='',
                              token='00',
                              expire=123,
                              priority=0).to_binary_string()
        notification = Notification()
        notification.from_binary_string(stream)

        self.assertEqual(notification.expire, 123)
    def test_from_binary_string_properties_set(self):
        now = datetime.now()
        stream = Notification('', '00', now, 0, 123).to_binary_string()
        notification = Notification()

        notification.from_binary_string(stream)

        self.assertEqual(notification.payload, '')
        self.assertEqual(notification.token, '00')
        self.assertEqual(notification.expire, now.replace(microsecond=0))
        self.assertEqual(notification.priority, 0)
        self.assertEqual(notification.iden, 123)
示例#7
0
    def test_from_binary_string_properties_set(self):
        now = datetime.now()
        stream = Notification('', '00', now, 0, 123).to_binary_string()
        notification = Notification()

        notification.from_binary_string(stream)

        self.assertEqual(notification.payload, '')
        self.assertEqual(notification.token, '00')
        self.assertEqual(notification.expire, now.replace(microsecond=0))
        self.assertEqual(notification.priority, 0)
        self.assertEqual(notification.iden, 123)
    def test_from_binary_string_invalid_id(self):
        now = datetime.now()
        stream = Notification('', '00', now, 0, 123).to_binary_string()
        notification = Notification()
        notification.EXPIRE = -1

        with self.assertRaises(NotificationInvalidIdError):
            notification.from_binary_string(stream)
    def test_invalid_priority(self):
        notification = Notification()

        with self.assertRaises(NotificationInvalidPriorityError):
            notification.to_binary_string()
    def test_to_binary_string_payload_not_json_serializable(self):
        notification = Notification(set(), '0000', None, 0)

        with self.assertRaises(NotificationPayloadNotSerializableError):
            notification.to_binary_string()
示例#11
0
    def test_from_binary_string_invalid_command(self):
        notification = Notification('', '00', datetime.now(), 0)

        with self.assertRaises(NotificationInvalidCommandError):
            notification.from_binary_string(
                struct.pack('>B', notification.COMMAND + 1))
示例#12
0
    def test_to_binary_string(self):
        notification = Notification('', '00', datetime.now(), 0)

        stream = notification.to_binary_string()

        notification.from_binary_string(stream)
    def test_to_binary_string(self):
        notification = Notification('', '00', datetime.now(), 0)

        stream = notification.to_binary_string()

        notification.from_binary_string(stream)
示例#14
0
    def test_to_binary_string_payload_not_json_serializable(self):
        notification = Notification(set(), '0000', None, 0)

        with self.assertRaises(NotificationPayloadNotSerializableError):
            notification.to_binary_string()
示例#15
0
    def test_invalid_priority(self):
        notification = Notification()

        with self.assertRaises(NotificationInvalidPriorityError):
            notification.to_binary_string()
 def test_invalid_str(self):
     notification = Notification(None, 'token', None, 0)
     self.assertEqual(str(notification), '<Notification: token>')
    def test_from_binary_string_invalid_command(self):
        notification = Notification('', '00', datetime.now(), 0)

        with self.assertRaises(NotificationInvalidCommandError):
            notification.from_binary_string(
                struct.pack('>B', notification.COMMAND + 1))