Exemplo n.º 1
0
 def post(self):
     """
     Create a board.
     """
     payload = request.get_json()
     required = ['members']
     result = validate_json(required, payload, empty=True)
     if isinstance(result, bool) is False:
         return {
             'status': 'fail',
             'message': 'Members list required.',
             'help': 'It can be empty if only oneself is a member.'
         }, 400
     else:
         members = [User.get(id=i) for i in payload['members']]
         for i in members:
             if isinstance(i, dict):
                 return {
                     'status': 'fail',
                     'message': 'The user does not exist.',
                     'missing_user': payload['members'][members.index(i)]
                 }, 404
         board = Board()
         board.insert('members', members)
         return {'status': 'success', 'data': {'board': board.view()}}, 201
Exemplo n.º 2
0
def seed_test_data():
    """
    Seed data to be used for testing.
    """
    db.drop_all()
    db.create_all()
    payment_1 = Payment()
    payment_2 = Payment()
    payment_3 = Payment()
    payment_4 = Payment()
    payment_1.insert('deposits', [Deposit(
        amount=1000.0), Deposit(amount=500.0)])
    payment_2.insert('deposits', [Deposit(
        amount=1000.0), Deposit(amount=500.0)])
    payment_3.insert('deposits', [Deposit(amount=1000.0)])
    payment_4.insert('deposits', [Deposit(amount=1000.0)])
    wallet_1 = Wallet()
    wallet_2 = Wallet()
    wallet_3 = Wallet()
    wallet_4 = Wallet()
    wallet_1.insert('payments', [payment_1, payment_2])
    wallet_2.insert('payments', [payment_3])
    wallet_3.insert('payments', [payment_4])
    estate1 = Estate(address='Casterly Rock')
    estate2 = Estate(address='Dorne')
    estate3 = Estate(address='Dragonstone')
    estate2.insert('payment', wallet_2.payments[0])
    estate3.insert('payment', wallet_3.payments[0])
    unit1 = Unit(name='No. 1')
    unit2 = Unit(name='No. 2')
    unit3 = Unit(name='No. 1')
    unit4 = Unit(name='No. 2')
    unit5 = Unit(name='No. 3')
    unit1.insert('payment', wallet_1.payments[0])
    unit2.insert('payment', wallet_1.payments[1])
    estate1.insert('estate_units', [unit1, unit2])
    estate2.insert('estate_units', [unit3])
    estate3.insert('estate_units', [unit4, unit5])
    board1 = Board()
    board2 = Board()
    board1.insert('estates_owned', [estate1, estate2])
    board2.insert('estates_owned', [estate3])
    board1.insert('units_owned', [unit5])
    user0 = User(
        name="Test User",
        phone_number="000 00 0000000",
        email="*****@*****.**",
        password=digest('ABC123!@#1'))
    user1 = User(
        name="Jaime Lannister",
        phone_number="000 12 3456781",
        email="*****@*****.**",
        password=digest('ABC123!@#1'))
    user2 = User(
        name="Oberyn Martell",
        phone_number="000 12 3456782",
        email="*****@*****.**",
        password=digest('ABC123!@#2'))
    user3 = User(
        name="Daenerys Targaryen",
        phone_number="000 12 3456783",
        email="*****@*****.**",
        password=digest('ABC123!@#3'))
    conversation1 = Conversation()
    conversation2 = Conversation()
    message1 = Message(sender=user1.name,
                       content='Content 1')
    message2 = Message(sender=user2.name,
                       content='Content 2')
    message3 = Message(sender=user3.name,
                       content='Content 3')
    conversation1.insert('messages', [message1, message2])
    conversation2.insert('messages', [message3])
    user0.insert('boards', [board1])
    user1.insert('boards', [board1])
    user2.insert('boards', [board1])
    user3.insert('boards', [board2])
    user1.insert('units', [unit1, unit2])
    user2.insert('units', [unit3])
    user3.insert('units', [unit4])
    user0.insert('wallet', wallet_4)
    user1.insert('wallet', wallet_1)
    user2.insert('wallet', wallet_2)
    user3.insert('wallet', wallet_3)
    user1.insert('conversations', [conversation1, conversation2])
    user2.insert('conversations', [conversation1, conversation2])
    user3.insert('conversations', [conversation1])
    role1 = Role(title='admin')
    role2 = Role(title='basic')
    role3 = Role(title='super_admin')
    role3.insert('users', [user0, user1])
    role2.insert('users', [user0, user1, user2, user3])
    role1.insert('users', [user0, user3])
    role1.save()
    role2.save()
    role3.save()
    print('\nTest Data Seeded.\n')