def register(self, username, password): if not (isinstance(password, str) and len(password) < 4): raise ValueError("Password should be a string of 4+ characters.") password = generate_password_hash(password) user = User(username=username, password=password) self.user_repository.add_user(user)
def add_user(self, user: User) -> None: u = user.asdict() u["_id"] = user.username try: self._users.insert_one(u) except pymongo.errors.DuplicateKeyError: raise exceptions.DuplicateUser(u)
def _to_user(self, data: Dict[str, Any]) -> User: data.pop("_id") return User.fromdict(data)
def fred(): return User(username="******", password="******")
def test_pw_too_short(): """Test that a password hash must have at least 3 characters.""" with pytest.raises(ValueError): User(username="******", password="******")
def tank(): pw = generate_password_hash("passwd") return User(username="******", password=pw)