Пример #1
0
class UserResource(Resource):
    @responds(schema=UserSchema(many=True), status_code=200)
    def get(self) -> List[User]:
        return UserService.get_all()

    @accepts(schema=UserSchema, api=api)
    @responds(schema=UserSchema, status_code=201)
    def post(self) -> User:
        return UserService.create(request.parsed_obj)
Пример #2
0
 def test_get(self, client: FlaskClient):
     with client:
         results = client.get(f'/api/{BASE_ROUTE}',
                              follow_redirects=True).get_json()
         expected = (UserSchema(many=True).dump([
             make_user(),
             make_user(2, 'John', '*****@*****.**', b'metallica', 2)
         ]))
         for r in results:
             assert r in expected
Пример #3
0
 def test_post(self, client: FlaskClient):
     with client:
         payload = dict(name='John',
                        email='*****@*****.**',
                        password='******')
         result = client.post(f'/api/{BASE_ROUTE}/',
                              json=payload).get_json()
         expected = (UserSchema().dump(
             User(
                 name=payload['name'],
                 email=payload['email'],
                 password=payload['password'],
             )))
         assert result == expected
Пример #4
0
 def test_get(self, client: FlaskClient):
     with client:
         results = client.get(f'/api/{BASE_ROUTE}/location/1',
                              follow_redirects=True).get_json()
         expected = (UserSchema(many=True).dump([
             make_user(),
             make_user(user_id=2,
                       name='Augustinho Carrara',
                       email='*****@*****.**',
                       password='******',
                       location_id=1)
         ]))
         for r in results:
             assert r in expected
Пример #5
0
    def test_put(self, client: FlaskClient):
        with client:
            result = client.put(f'/api/{BASE_ROUTE}/1',
                                json={
                                    'name': 'Beck Dylan',
                                    'email': '*****@*****.**',
                                    'password': '******'
                                }).get_json()

            expected = (UserSchema().dump(
                make_user(name='Beck Dylan',
                          email='*****@*****.**',
                          password='******',
                          location_id=1)))

            assert result == expected
Пример #6
0
import json
from flask import redirect, render_template, request, jsonify
from sqlalchemy import or_

from . import user
from app import db
from app.user.models import User
from app.user.schema import UserSchema

user_schema = UserSchema()
users_schema = UserSchema(many=True)


@user.route('/users', methods=['POST'])
def add_user():
    form = json.loads(request.data)
    #print('Register: ' + str(form))

    firstname = form['firstname']
    lastname = form['lastname']
    email = form['email'].lower()
    age = form['age']
    gender = form['gender'].lower()

    try:
        if User.query.filter_by(email=email).first():
            message = {'message': 'User {} already exists'.format(email)}
            return jsonify(message), 500
        else:
            new_user = User(firstname=firstname,
                            lastname=lastname,
Пример #7
0
from app.user.service import Service as S
from app.user.schema import UserSchema

from app.repository.mongo import MongoRepository
import flask as Flask

if __name__ == "__main__":
    print('Trying to query the server')

    s = UserSchema()
    s.name = 'MyUser'
    s.password = '******'

    print(s)

    # mr = MongoRepository()
    # data = mr.db.users.find_one({'name':'bear'})
    # print(data)
    # data = UserSchema(exclude=['_id']).dump(data).data
    # print(data)
    # newData = data
    # newData['id'] = '123'
    # print(newData)

    data = S().find_user('bear')
    print(data)
    # # data = S.Service('bear').find_user()
    # data = mr.db.users.find_one({'name':'superBear'})
    # data = UserSchema(exclude=['_id']).dump(data).data
    # print(data)
    # mr.db.users.insert_one({'name':'superBear', 'password':'******'})