def test_users_model(self):
        with patch('db_helper.db', self.db):
            u1 = User(None, 1, 'name', 'surname', 'middle', 'tok1')
            u2 = User(124, 1, 'name2', 'surname2', 'middle', 'tok2')
            u3 = User(125, 1, 'name3', 'surname3', 'middle', 'tok3')
            u1upd = User(12312, 1, 'name1', 'surname1', 'middle', 'tok1')

            u1_data = {
                'chat_id': 12312,
                'type': 1,
                'name': 'name1',
                'surname': 'surname1',
                'middlename': 'middle',
                'token': 'tok1',
                'id': 1
            }
            u2_data = {
                'chat_id': 124,
                'type': 1,
                'name': 'name2',
                'surname': 'surname2',
                'middlename': 'middle',
                'token': 'tok2',
                'id': 2
            }
            u3_data = {
                'chat_id': 125,
                'type': 1,
                'name': 'name3',
                'surname': 'surname3',
                'middlename': 'middle',
                'token': 'tok3',
                'id': 3
            }

            users = Users()

            assert [asdict(u) for u in users] == [u1_data, u2_data, u3_data]
            assert asdict(users.by_token['tok2']) == u2_data
            assert asdict(users.by_id[1]) == u1_data
            assert asdict(users.by_chat_id[12312]) == u1_data
            assert users.get_by_id(123) is None
            assert asdict(users.get_by_id(1)) == u1_data
            assert len(users) == 3
示例#2
0
 def func_wrapper(message):
     id_telegram = message.from_user.id
     user = db.get_user(id_telegram)
     if not user:
         user = message.from_user
         alias = "@" + user.username if user.username else user.first_name
         user = User(id_telegram=str(user.id),
                     alias=alias,
                     first_name=str(user.first_name))
         db.add(user)
     func(message)
示例#3
0
def new_user(email, name, password_encrypted, token):
    session = Session()
    try:
        user = User(email, name, password_encrypted, token)
        session.add(user)
        session.commit()
        return successful({
            'id': user.id,
            'email': user.email,
            'password_encrypted': user.password_encrypted,
            'token': user.token,
        })
    except:
        session.rollback()
        return internal_server_error
    finally:
        session.close()
示例#4
0
 def test_init(self):
     username = "******"
     user = User(username)
     assert user.username == username
示例#5
0
def user():
    print("get user fixture")
    user = User("test_user")
    yield user
    user.delete()