示例#1
0
class DriverAuthViewTestCase(AppTestCase):
    def setUp(self):
        super(DriverAuthViewTestCase, self).setUp()

        self.user_driver = Driver(name='Test', email='*****@*****.**')
        self.user_driver.set_password('secret123')
        Driver.insert(self.user_driver)

    def test_user_driver_auth_ok(self):
        response = self.client.post(
            url_for('auth.login'),
            data=json.dumps({
                'email': '*****@*****.**',
                'access_type': 'driver',
                'password': '******'
            }),
            headers={'Content-Type': 'application/json'})

        self.assertEqual(response.status_code, 200)
        self.assertTrue('token' in response.json)

    def test_user_driver_auth_fail(self):
        response = self.client.post(
            url_for('auth.login'),
            data=json.dumps({
                'email': '*****@*****.**',
                'access_type': 'driver',
                'password': '******'
            }),
            headers={'Content-Type': 'application/json'})

        self.assertEqual(response.status_code, 401)
        self.assertTrue('token' not in response.json)
示例#2
0
def create():
    data = request.get_json()

    print(request.headers)

    schema = DriverSchema(strict=True)
    data, errors = schema.load(data)

    if errors:
        return jsonify({'errors': errors}), 400

    user = Driver(itineraries=[], **data)
    user.set_password(data['password'])

    result = User.insert(user)

    if result['errors']:
        return jsonify({'errors': result['first_error']}), 409

    return jsonify({'email': user['email']}), 201