Beispiel #1
0
def test_raises_internal_err_with_bad_user_creator():
  deps = SignupDependencies(
    user_getter=MockUserGetter(example_users),
    hasher=MockHasher(),
    user_creator=BadUserCreator()
  )

  with pytest.raises(exceptions.Internal):
    signup(deps, "newuser", "supersecret")
Beispiel #2
0
def test_raises_internal_err_with_bad_user_getter():
  deps = SignupDependencies(
    user_getter=BadUserGetter(Exception("foo")),
    hasher=MockHasher(),
    user_creator=MockUserCreator()
  )

  with pytest.raises(exceptions.Internal):
    signup(deps, "foo", "bar")
Beispiel #3
0
def test_raises_unique_username_err_with_existing_username():
  deps = SignupDependencies(
    user_getter=MockUserGetter(example_users),
    hasher=MockHasher(),
    user_creator=MockUserCreator()
  )

  with pytest.raises(exceptions.NeedUniqueUsername, match='phillipfry'):
    signup(deps, "phillipfry", "supersecret")
Beispiel #4
0
def test_hashes_password_and_creates_user():
  user_creator=MockUserCreator()
  deps = SignupDependencies(
    user_getter=MockUserGetter(example_users),
    hasher=MockHasher(),
    user_creator=user_creator
  )

  signup(deps, "newuser", "supersecret")

  assert user_creator.created_user == User(
    id=42,
    username="******",
    password=MockHasher().hash("supersecret")
  )
Beispiel #5
0
 def signup(self, username: str, password: str) -> None:
     deps = SignupDependencies(db, hasher, db)
     signup(deps, username, password)