def test_user_repo_get_user_list_should_all(session): for _ in range(20): fake = Faker() data = {"email": fake.email(), "password": fake.name()} User.create(**data) page = 1 res = UserRepository().get_all(page) assert len(res.items) == 10
def blog(user, reader_token): blog = Blog.create( title="test_blog", url="test_blog", creator=user, created_date=datetime.datetime.now(), updated_date=datetime.datetime.now(), ) BlogParticipiation.create(blog=blog, user=user, role=1) writer = User.create( username="******", password="******", email="asd", registration_date=datetime.datetime.now(), last_active_date=datetime.datetime.now(), ) BlogParticipiation.create(blog=blog, user=writer, role=2) BlogParticipiation.create(blog=blog, user=reader_token[0], role=3) from src.model import db db.db_wrapper.database.close() return blog
def users(): for i in range(30): User.create( username="******" + str(i), password="******", email="asd" + str(i), registration_date=datetime.datetime.now(), last_active_date=datetime.datetime.now(), name="name", birthday=datetime.date.today(), about="", avatar=None, ) from src.model import db db.db_wrapper.database.close()
def register(): """Регистрация""" json = request.get_json() missed_payload = [] if "username" not in json: missed_payload.append("username") if "password" not in json: missed_payload.append("password") if "email" not in json: missed_payload.append("email") if "name" not in json: missed_payload.append("name") if len(missed_payload) > 0: return errors.wrong_payload(missed_payload) username = json["username"] password = json["password"] email = json["email"] name = json["name"] user = User.get_or_none(User.username == username) if user is not None: return errors.registration_username_busy() user = User.get_or_none(User.email == email) if user is not None: return errors.registration_email_busy() user = User.create( username=username, password=salted(password, current_app.config["PASSWORD_SALT"]), email=email, registration_date=datetime.datetime.now(), last_active_date=datetime.datetime.now(), name=name, ) token = Token.generate_access_token(user) refresh_token = Token.generate_refresh_token(user) return jsonify({ "success": 1, "access_token": { "token": token.token, "valid_until": token.valid_until.timestamp(), }, "refresh_token": { "token": refresh_token.token, "valid_until": refresh_token.valid_until.timestamp(), }, })
def other_user_and_token(): user = User.create( username="******", password="******", email="asd", registration_date=datetime.datetime.now(), last_active_date=datetime.datetime.now(), ) token = Token.generate_access_token(user) from src.model import db db.db_wrapper.database.close() return [user, token]
def feedback(): user = User.create( username="******", password="******", email="asd", registration_date=datetime.datetime.now(), last_active_date=datetime.datetime.now(), name="name", birthday=datetime.date.today(), about="", avatar=None, ) Feedback.create(text="some text", user=user) from src.model import db db.db_wrapper.database.close()
def user_not_in_blog_with_token(): user = User.create( username="******", password="******", email="asd", registration_date=datetime.datetime.now(), last_active_date=datetime.datetime.now(), name="name", birthday=datetime.date.today(), about="", avatar=None, ) token = Token.generate_access_token(user) from src.model import db db.db_wrapper.database.close() return [user, token]
def tokens(): user = User.create( username="******", password="******", email="asd", registration_date=datetime.datetime.now(), last_active_date=datetime.datetime.now(), name="name", birthday=datetime.date.today(), about="", avatar=None, ) a = Token.generate_access_token(user) r = Token.generate_refresh_token(user) from src.model import db db.db_wrapper.database.close() return {"access_token": a, "refresh_token": r}
def test_is_session_work(session, name): user = {"name": name} User.create(**user) res = User.get_user_by_name(name) assert res is not None
def test_model_hybrid_function_should_works(session): User.create(name="hybrid_function", age=10) res = User.get_user_by_name("hybrid_function") res = res.contains(20) assert res is True
def test_model_hybrid_property_should_works(session): User.create(name="hybrid", age=10) res = User.get_user_by_name("hybrid") assert res.diff_age < 0
def test_custom_model_function_should_works(session): name = "custom" User.create(name=name) res = User.get_user_by_name(name) assert res.name == name
def convert(): create_app() removed = 0 for u in TuUser.select(): was_removed = False if u.user_activate == 0 and not u.user_last_session: was_removed = True has_session_in_one_day = True s = TuSession.get_or_none(TuSession.session_key == u.user_last_session) if s: if (s.session_date_last - u.user_date_register).days > 0.5: has_session_in_one_day = False if has_session_in_one_day: was_removed = True last_session_date = datetime.datetime(year=1970, month=1, day=1) for s in TuSession.select().where(TuSession.user == u.user): if s.session_date_last > last_session_date: last_session_date = s.session_date_last if was_removed: removed = removed + 1 else: year = u.user_date_register.year month = u.user_date_register.month avatar = content.create_content( u.user_profile_avatar, "profile_avatar", u.user, u.user, year, month ) user = User.create( id=u.user, username=u.user_login, password=u.user_password, email=u.user_mail, registration_date=u.user_date_register, last_active_date=last_session_date, name=u.user_profile_name, birthday=u.user_profile_birthday, about=None, avatar=avatar, is_admin=u.user_role > 1, ) about = content.replace_uploads_in_text(user, u.user_profile_about) user.about = about user.save() force_created_users = [ 5, 8, 21, 62, 97, 382, 44, 3392, 3412, 3425, 3398, 416, 383, 150, 337, 378, 398, 3427, 3434, 88, ] for id in force_created_users: if User.get_or_none(User.id == id): continue u = TuUser.get(TuUser.user == id) year = u.user_date_register.year month = u.user_date_register.month avatar = content.create_content( u.user_profile_avatar, "profile_avatar", u.user, u.user, year, month ) User.create( id=u.user, username=u.user_login, password=u.user_password, email=u.user_mail, registration_date=u.user_date_register, last_active_date=last_session_date, name=u.user_profile_name, birthday=u.user_profile_birthday, about=u.user_profile_about, avatar=avatar, is_admin=u.user_role > 1, ) print("Removed %d users" % removed)