Пример #1
0
 def test_update(self):
     new_acc = Account(username="******",password_hash="1234",balance=10000)
     new_acc2 = Account(username="******",password_hash="4321",balance=20000)
     new_acc.save()
     new_acc2.save()
     new_acc.username = "******"
     new_acc2.username = "******"
     new_acc.save()
     new_acc2.save()
     item1 = Account.one_from_pk(1)
     item2 = Account.one_from_pk(2)
     self.assertEqual(item1.username, "test")
     self.assertEqual(item2.username, "test2")
Пример #2
0
    def test_save_and_pk_load(self):
        user = Account(username="******")
        user.save()
        self.assertIsInstance(user.pk, int, 'save sets pk')
        
        pk = user.pk
        same_user = Account.one_from_pk(pk)

        self.assertIsInstance(same_user, Account, "one_from_pk loads an Account object")

        self.assertEqual(same_user.username, "Samuel", "save creates database row")
        same_user.username = "******"
        same_user.save()

        same_again = Account.one_from_pk(pk)

        self.assertEqual(same_again.username, "Sam", "save updates an existing row")
Пример #3
0
    def test_key_creation(self):
        #Create new account record incl. api_key and save to DB
        new_user = Account(username="******")
        new_user.set_password("test_password")
        new_user.create_api_key()
        new_user.save()

        #Retrieve new account record and evaluate api_key pop'd
        pk = new_user.pk
        same_user = Account.one_from_pk(pk)
        self.assertEqual(len(same_user.api_key), 15, "api key populated")
Пример #4
0
    def test_save_and_pk_load(self):
        user = Account(username='******')
        user.save()
        self.assertIsInstance(user.pk, int, 'save sets pk')

        pk = user.pk
        same_user = Account.one_from_pk(pk)

        self.assertIsInstance(same_user, Account,
                              'one_from_pk loads Account object')

        self.assertEqual(same_user.username, 'Samuel',
                         'save creates database row')
        same_user.username = '******'
        same_user.save()

        same_again = Account.one_from_pk(pk)

        self.assertEqual(same_again.username, 'Sam',
                         'save updates an existing row')
Пример #5
0
 def test_password_hash(self):
     hashed_pass = hash_password("1234")
     new_acc = Account(username="******",password_hash=hashed_pass,balance=10000)
     new_acc.save()
     item = Account.one_from_pk(1)
     self.assertEqual(item.password_hash, hashed_pass)
Пример #6
0
 def test_select_one_by_pk(self):
     new_acc = Account(username="******",password_hash="1234",balance=10000)
     new_acc.save()
     item = Account.one_from_pk(1)
     self.assertEqual(item.username, "dan.m")
     self.assertEqual(item.balance, 10000)
Пример #7
0
def user(id):
    user = Account.one_from_pk(id)
    if user.balance is None:
        user.balance = 0
    return jsonify({"user": user.username, "balance": user.balance})
Пример #8
0
 def test_get_positions(self):
     user = Account.one_from_pk(1)
     positions = user.get_positions()
Пример #9
0
 def test_get_positions(self):
     user = Account.one_from_pk(1)
     positions = user.get_positions()
     self.assertIsInstance(positions, list, "get positions returns a list")
     self.assertIsInstance(positions[0], Position, "list contains Position objects")