Exemplo n.º 1
0
 def test_echo(self):
     data = dict(jsonrpc='2.0', method='api.rpc.methods.echo', params=['Hello!'], id='test')
     result = mapper(data)
     self.assertTrue(result.get('result') == 'Hello!')
     response = self.client.post('/rpc/', data=json.dumps(data), content_type='application/json')
     self.assert200(response)
     self.assertTrue(response.json)
     self.assertTrue(response.json['result'] == 'Hello!')
Exemplo n.º 2
0
    def test_authenticate(self):
        userdata = dict(username='test', email='[email protected]', password='test')
        user = User(**userdata)
        db.session.add(user)
        db.session.commit()

        data = dict(
                jsonrpc='2.0',
                method='api.rpc.methods.authenticate',
                params=dict(**userdata), id='test')
        result = mapper(data)
        self.assertEqual(result.get('result'), 'User authenticate')

        response = self.client.post('/rpc/', data=json.dumps(data), content_type='application/json')
        self.assert200(response)
        self.assertTrue(response.json)
        self.assertTrue(response.json['result'])
Exemplo n.º 3
0
    def test_signup(self):
        data = dict(
                jsonrpc='2.0',
                method='api.rpc.methods.signup',
                params=dict(
                    username='username',
                    email='[email protected]',
                    password='password',
                ), id='test')
        result = mapper(data)
        self.assertEqual(result.get('result'), 'User created # 1')

        response = self.client.post('/rpc/', data=json.dumps(data), content_type='application/json')
        self.assert200(response)
        self.assertTrue(response.json)
        self.assertTrue(response.json['error'])

        data['params']['username'] = 'username2'
        data['params']['email'] = '[email protected]'
        response = self.client.post('/rpc/', data=json.dumps(data), content_type='application/json')
        self.assert200(response)
        self.assertTrue(response.json)
        self.assertTrue(response.json['result'])