示例#1
0
    def test_save_to_database_single(self):
        uuid = str(uuid4())
        user = User(uuid=uuid, email='*****@*****.**')
        save_to_database(user)

        user = User.get(uuid)
        assert user.email == '*****@*****.**'
示例#2
0
    def test_get_by(self):
        uuid = str(uuid4())
        t2 = Table2(id=1, user_uuid=uuid)
        save_to_database(t2)

        t2 = Table2.get_by('user_uuid', uuid)
        assert t2.id == 1
示例#3
0
    def test_get_by_user(self):
        uuid = str(uuid4())
        t21 = Table2(id=1,
                     user_uuid=uuid,
                     key=1,
                     key2=1,
                     created_at=arrow.get('2011-10-21'))
        t22 = Table2(id=2,
                     user_uuid=uuid,
                     key=1,
                     key2=2,
                     created_at=arrow.get('2012-10-21'))
        t23 = Table2(id=3,
                     user_uuid=uuid,
                     key=1,
                     key2=3,
                     created_at=arrow.get('2013-10-21'))
        t24 = Table2(id=4,
                     user_uuid=uuid,
                     key=1,
                     key2=4,
                     created_at=arrow.get('2014-10-21'))
        t25 = Table2(id=5,
                     user_uuid=uuid,
                     key=1,
                     key2=5,
                     created_at=arrow.get('2015-10-21'))
        save_to_database([t21, t22, t23, t24, t25])

        results = Table2.get_by_user(uuid, offset=2, limit=2)
        assert len(results) == 2
        assert results[0].key2 == 3
        assert results[1].key2 == 2
示例#4
0
    def test_get_by_deleted_contains(self):
        uuid = str(uuid4())
        t2 = Table2(id=1, user_uuid=uuid)
        save_to_database(t2)

        t2 = Table2.get_by('user_uuid', uuid, contains_deleted=True)
        assert t2.id == 1
示例#5
0
    def test_save_to_database_multi(self):
        uuid = str(uuid4())
        user = User(uuid=uuid, email='*****@*****.**')
        t2 = Table2(id=2, user_uuid=uuid)
        save_to_database([user, t2])

        user = User.get(uuid)
        assert user.email == '*****@*****.**'
        t2 = Table2.get(2)
        assert t2.user_uuid == uuid
示例#6
0
    def test_replace_insert(self):
        uuid = str(uuid4())
        user = User(uuid=uuid, email='*****@*****.**')
        save_to_database(user)

        user = {'uuid': uuid, 'email': '*****@*****.**'}
        session = Session()
        session.execute(User.__table__.insert(mysql_replace_insert=True), user)
        session.commit()
        user = User.get(uuid)
        assert user.email == '*****@*****.**'
示例#7
0
    def test_get_by_for_update(self):
        uuid = str(uuid4())
        t2 = Table2(id=1, user_uuid=uuid)
        save_to_database(t2)

        t2 = Table2.get_by('user_uuid', uuid, for_update=True)
        assert t2.id == 1
        t2.key2 = 10
        save_to_database(t2)
        t2 = Table2.get_by('user_uuid', uuid)
        assert t2.key2 == 10
示例#8
0
    def test_get_multi(self):
        uuid = str(uuid4())
        t21 = Table2(id=1, user_uuid=uuid, key=1, key2=1)
        t22 = Table2(id=2, user_uuid=uuid, key=1, key2=2)
        t23 = Table2(id=3, user_uuid=uuid, key=1, key2=3)
        t24 = Table2(id=4, user_uuid=uuid, key=1, key2=4)
        t25 = Table2(id=5, user_uuid=uuid, key=1, key2=5)
        save_to_database([t21, t22, t23, t24, t25])

        results = Table2.get_multi('key', 1, 'key2', offset=2, limit=2)
        assert len(results) == 2
        assert results[0].key2 == 3
        assert results[1].key2 == 2

        results = Table2.get_multi('key', 1, 'key2', desc=False, limit=7)
        assert len(results) == 5
        assert results[0].key2 == 1
示例#9
0
 def test_save_to_database_noop(self):
     save_to_database(None)
示例#10
0
    def test_get_by_deleted(self):
        uuid = str(uuid4())
        t2 = Table2(id=1, user_uuid=uuid, deleted_at=arrow.get())
        save_to_database(t2)

        assert not Table2.get_by('user_uuid', uuid)
示例#11
0
 def test_get_by_empty(self):
     t2 = Table2(id=1, user_uuid=str(uuid4()))
     save_to_database(t2)
     assert not Table2.get_by('user_uuid', None)