Exemplo n.º 1
0
 def test_get_many_units(self):
     self.assertEqual(True, isinstance(Unit.get_all(), dict))
     self.unit1.save()
     self.unit2.save()
     self.assertEqual(True, isinstance(Unit.get_all()[0], Unit))
     self.assertEqual(True, isinstance(Unit.get_all()[1], Unit))
     self.assertEqual(2, len(Unit.get_all()))
Exemplo n.º 2
0
 def test_update_unit(self):
     self.unit1.save()
     unit1 = Unit.get(id=1)
     unit1.update({'name': 'new_unit_name'})
     self.assertEqual('new_unit_name', Unit.get(id=1).name)
     self.assertTrue(isinstance(unit1.update({'random': 'bad field'}),
                                dict))
Exemplo n.º 3
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.º 4
0
 def test_add_and_remove_payment_from_unit(self):
     self.unit1.save()
     self.payment1.save()
     unit1 = Unit.get(id=1)
     self.assertEqual(None, unit1.payment)
     payment1 = Payment.get(id=1)
     unit1.insert('payment', payment1)
     unit1 = Unit.get(id=1)
     self.assertEqual(True, isinstance(unit1.payment, Payment))
     unit1.remove('payment')
     self.assertEqual(None, unit1.payment)
Exemplo n.º 5
0
 def test_add_and_remove_units_from_estate(self):
     self.estate1.save()
     self.unit1.save()
     self.unit2.save()
     estate1 = Estate.get(id=1)
     self.assertEqual(0, len(estate1.estate_units))
     estate1.insert('estate_units', [Unit.get(id=1), Unit.get(id=2)])
     self.assertEqual(2, len(estate1.estate_units))
     self.assertEqual(True, isinstance(estate1.estate_units[0], Unit))
     self.assertEqual(True, isinstance(estate1.estate_units[1], Unit))
     estate1.remove('estate_units', id=1)
     self.assertEqual(1, len(estate1.estate_units))
Exemplo n.º 6
0
 def test_add_and_remove_units_owned_to_board(self):
     self.board1.save()
     self.unit1.save()
     self.unit2.save()
     board1 = Board.get(id=1)
     board1.insert('units_owned', [Unit.get(id=1), Unit.get(id=2)])
     units = Board.get(id=1).units_owned
     self.assertEqual("Random Unit 1", units[0].name)
     self.assertEqual("Random Unit 2", units[1].name)
     self.assertEqual(2, len(units))
     self.assertEqual(True, isinstance(units[0], Unit))
     self.assertEqual(True, isinstance(units[1], Unit))
     board1.remove('units_owned', id=1)
     self.assertEqual(1, len(Board.get(id=1).units_owned))
Exemplo n.º 7
0
 def test_add_and_remove_deposit_estate_unit_wallet(self):
     self.deposit1.save()
     self.deposit2.save()
     self.estate1.save()
     self.unit1.save()
     self.wallet1.save()
     self.payment1.save()
     payment1 = Payment.get(id=1)
     payment1.estate = Estate.get(id=1)
     payment1.unit = Unit.get(id=1)
     payment1.wallet = Wallet.get(id=1)
     payment1.insert('deposits', [Deposit.get(id=1), Deposit.get(id=2)])
     self.assertEqual(True, isinstance(payment1.estate, Estate))
     self.assertEqual(True, isinstance(payment1.unit, Unit))
     self.assertEqual(True, isinstance(payment1.wallet, Wallet))
     self.assertEqual(True, isinstance(payment1.deposits[0], Deposit))
     self.assertEqual(True, isinstance(payment1.deposits[1], Deposit))
     self.assertEqual(2, len(payment1.deposits))
     payment1.remove('estate')
     payment1.remove('unit')
     payment1.remove('wallet')
     self.assertEqual(None, payment1.estate)
     self.assertEqual(None, payment1.unit)
     self.assertEqual(None, payment1.wallet)
     payment1.remove('deposits', id=1)
     self.assertEqual(1, len(payment1.deposits))
Exemplo n.º 8
0
 def test_delete_board(self):
     self.board1.save()
     self.estate1.save()
     self.unit1.save()
     board1 = Board.get(id=1)
     board1.insert('estates_owned', [Estate.get(id=1)])
     board1.units_owned.append(Unit.get(id=1))
     self.assertEqual(True, Board.get(id=1).delete())
     self.assertEqual(True, isinstance(Board.get(id=1), dict))
Exemplo n.º 9
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.º 10
0
 def test_add_and_remove_board_estate_resident(self):
     self.board1.save()
     self.estate1.save()
     self.user1.save()
     self.unit1.save()
     unit1 = Unit.get(id=1)
     unit1.insert('resident', User.get(id=1))
     unit1.insert('board', Board.get(id=1))
     unit1.insert('estate', Estate.get(id=1))
     self.assertEqual(True, isinstance(unit1.board, Board))
     self.assertEqual(True, isinstance(unit1.resident, User))
     self.assertEqual(True, isinstance(unit1.estate, Estate))
     unit1.remove('resident')
     unit1.remove('board')
     unit1.remove('estate')
     self.assertEqual(None, unit1.board)
     self.assertEqual(None, unit1.estate)
     self.assertEqual(None, unit1.resident)
Exemplo n.º 11
0
 def test_unit_exists(self):
     self.assertFalse(Unit.check_exists(id=1))
     self.unit1.save()
     self.assertTrue(Unit.check_exists(id=1))
Exemplo n.º 12
0
 def test_get_unit(self):
     self.assertEqual(True, isinstance(Unit.get(id=1), dict))
     self.unit1.save()
     self.assertEqual(True, isinstance(Unit.get(id=1), Unit))
Exemplo n.º 13
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')