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_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_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_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)
    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_command(self):
        notification = Notification('', '00', datetime.now(), 0)

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

        stream = notification.to_binary_string()

        notification.from_binary_string(stream)
    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))
    def test_to_binary_string(self):
        notification = Notification('', '00', datetime.now(), 0)

        stream = notification.to_binary_string()

        notification.from_binary_string(stream)