Ejemplo n.º 1
0
    def test_push_not_successful(self):
        res = Mock()
        res.status = 400
        res.read.return_value = b'{"reason": "BadDeviceToken"}'
        res.headers = {
            'apns-id': [str(uuid.uuid4())],
        }

        con = Mock()
        con.get_response.return_value = res

        c = Client(None)
        c._connection = con

        m = Message(alert='testing')

        try:
            c.push(m, 'token')
            pytest.fail('Did not raise BadDeviceToken')
        except BadDeviceToken as e:
            assert e.token == 'token'
            assert e.code == res.status
Ejemplo n.º 2
0
    def test_push(self):
        id_ = uuid.uuid4()
        res = Mock()
        res.status = 200
        res.headers = {
            'apns-id': [str(id_)],
        }

        con = Mock()
        con.get_response.return_value = res

        c = Client(None)
        c._connection = con

        m = Message(alert='testing')

        apns_id = c.push(m, 'token')
        assert apns_id == id_

        args, kwargs = con.request.call_args
        assert args[0] == 'POST'
        assert args[1] == '/3/device/token'
        assert kwargs['body'] == m.encoded
        assert kwargs['headers'] == m.headers
Ejemplo n.º 3
0
 def test_push_checks_null_or_empty_token(self, token):
     c = Client(None)
     with pytest.raises(AssertionError):
         c.push('message', token)