Пример #1
0
    def test_update_email(self):
        with self.current_api.app_context():
            ClientService.add('admin1', '*****@*****.**')
            client = ClientService.get_by_email('*****@*****.**')

            updated_client = ClientService.update_email(client.id, 'admin42')
            self.assertEqual(updated_client.id, client.id)

            updated_client = ClientService.update_email(987, 'admin42')
            self.assertEqual(updated_client, None)
Пример #2
0
    def test_remove(self):
        with self.current_api.app_context():
            ClientService.add('admin1', '*****@*****.**')
            client = ClientService.get_by_email('*****@*****.**')

            deleted_client = ClientService.remove(client.id)
            self.assertEqual(deleted_client.id, client.id)

            deleted_client = ClientService.remove(987)
            self.assertEqual(deleted_client, None)
Пример #3
0
def update_partial_client(client_id):
    username = request.json['username']

    if ClientService.get_by_username(username):
        return jsonify({'error': 'This username already exists!'})

    client = ClientService.update_username(client_id, username)

    if client == None:
        abort(404)

    client_schema = ClientSchema()
    return client_schema.jsonify(client)
Пример #4
0
def create_client():
    username = request.json['username']
    email = request.json['email']

    if ClientService.get_by_username(username):
        return jsonify({'error': 'This username already exists!'})

    if ClientService.get_by_email(email):
        return jsonify({'error': 'This email already exists!'})

    client = ClientService.add(username, email)

    client_schema = ClientSchema()
    return client_schema.jsonify(client)
Пример #5
0
def delete_client(client_id):
    client = ClientService.remove(client_id)

    if client == None:
        abort(404)

    client_schema = ClientSchema()
    return client_schema.jsonify(client)
Пример #6
0
 def test_get_all(self):
     with self.current_api.app_context():
         ClientService.add('admin1', '*****@*****.**')
         ClientService.add('admin2', '*****@*****.**')
         ClientService.add('admin3', '*****@*****.**')
         clients = ClientService.get_all()
         self.assertNotEqual(len(clients), 0)
Пример #7
0
from api import create_api, db
from api.clients.models import Client
from api.clients.services import ClientService
from api.finances.services import RecordService

api = create_api('config')

if __name__ == "__main__":
    with api.app_context():

        # remove todas as tabelas do banco
        db.drop_all()

        # (re)cria o banco de dados
        db.create_all()

        # Testes de consultas
        users = Client.query.all()

        # Adiciona um usuário
        for i in range(1000):
            username, email = f'admin{i}', f'admin{i}@finances.com'
            u = Client(username, email)
            db.session.add(u)
            db.session.commit()

        data = ClientService.get_all()
        print(data)

        data = RecordService.get_all()
        print(data)
Пример #8
0
current_api = create_api('config')

with current_api.app_context():

    # remove todas as tabelas do banco
    db.drop_all()

    # (re)cria o banco de dados
    db.create_all()

    # obter os registros na base de dados
    records = RecordService.get_all()
    print(f'records {list(records)}')

    # cria um usuário e o adiciona ao banco
    client_1 = ClientService.add('admin', '*****@*****.**')
    print(client_1)

    client_2 = ClientService.add('admin1', '*****@*****.**')
    print(client_1)

    client_3 = ClientService.add('admin2', '*****@*****.**')
    print(client_1)

    client_4 = ClientService.add('admin3', '*****@*****.**')
    print(client_1)

    # cria um registro
    r = RecordService.add(id_client=client_1.id,
                          descr='any',
                          amount=8.57,
Пример #9
0
 def test_get_by_email(self):
     with self.current_api.app_context():
         ClientService.add('admin1', '*****@*****.**')
         client = ClientService.get_by_email('*****@*****.**')
         self.assertNotEqual(client, None)
Пример #10
0
 def test_add(self):
     with self.current_api.app_context():
         client = ClientService.add('admin', '*****@*****.**')
         self.assertNotEqual(client.id, None)
Пример #11
0
def pag_clients(page_num):

    clients = ClientService.paginate(per_page=20, page=page_num).items

    clients_schema = ClientSchema(many=True)
    return clients_schema.jsonify(clients)
Пример #12
0
def get_client(client_id):
    client = ClientService.get_by_id(client_id)
    if client == None:
        abort(404)
    client_schema = ClientSchema()
    return client_schema.jsonify(client)
Пример #13
0
def get_clients():
    clients = ClientService.get_all()
    clients_schema = ClientSchema(many=True)
    return clients_schema.jsonify(clients)