Exemplo n.º 1
0
    def setUp(self):
        """
        Set up test application.
        """
        self.app = create_app('testing')
        self.client = self.app.test_client()
        self.client.headers = {'Authorization': getenv('TEST_TOKEN')}
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.drop_all()
        db.create_all()

        self.board1 = Board()
        self.board2 = Board()
        self.conversation1 = Conversation()
        self.conversation2 = Conversation()
        self.deposit1 = Deposit()
        self.deposit2 = Deposit()
        self.estate1 = Estate(address="Random Address 1")
        self.estate2 = Estate(address="Random Address 2")
        self.estate3 = Estate()
        self.headers = {'Authorization': getenv('TEST_TOKEN')}
        self.message1 = Message(sender=1, content='Random Content')
        self.message2 = Message(sender=2, content='Random Content')
        self.message3 = Message()
        self.payment1 = Payment()
        self.payment2 = Payment()
        self.role1 = Role(title='basic')
        self.role2 = Role(title='admin')
        self.role3 = Role(title='super_admin')
        self.role4 = Role()
        self.unit1 = Unit(name="Random Unit 1")
        self.unit2 = Unit(name="Random Unit 2")
        self.unit3 = Unit()
        self.user1 = User(name="First1 Middle1 Last1",
                          phone_number="000 12 3456781",
                          email="*****@*****.**",
                          password=digest('ABC123!@#'))
        self.user2 = User(name="First2 Middle2 Last2",
                          phone_number="000 12 3456782",
                          email="*****@*****.**",
                          password=digest('ABC123!@#'))
        self.user3 = User()
        self.user_new_data1 = {'phone_number': "000 12 3456783"}
        self.user_new_data2 = {'bad_field': "random"}
        self.wallet1 = Wallet()
        self.wallet2 = Wallet()
        self.user1_dict = {
            "name": "First1 Middle1 Last1",
            "phone_number": "000 12 3456781",
            "email": "*****@*****.**",
            "password": "******"
        }
        self.conversation3_dict = {"participants": [1, 2]}
        self.message4_dict = {"content": "New Message."}
        self.board3_dict = {'members': [1, 2]}
Exemplo n.º 2
0
def getUnitInfo():
    import requests
    from bs4 import BeautifulSoup as bs
    from api.models import Unit
    import sys, io
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
    url = 'http://www1.szu.edu.cn/board/userlist.asp'
    a = requests.get(url)
    b = bs(a.content, 'lxml')
    c = b.find_all("option")
    Unit.objects.all().delete()
    for i in c[1:]:
        d = i.attrs['value'].split('#')
        Unit(name=d[0], user=d[1], perm=0).save()
Exemplo n.º 3
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')