def test_success(self, *_):
     User.create("*****@*****.**", "test_password")
     User.get("*****@*****.**").confirm(
         generate_token(SUPER_SECRET_CONFIRMATION_KEY, "*****@*****.**"))
     self.assertEqual(
         User.get("*****@*****.**").login("test_password"),
         jwt.encode({
             "user": "******"
         },
                    SUPER_SECRET_SECRET_KEY,
                    algorithm='HS256').decode())
def create_user(user):  # noqa: E501
    """create_user

    Register a new user # noqa: E501

    :param user: User to register
    :type user: dict | bytes

    :rtype: None
    """
    user = UserData.from_dict(connexion.request.get_json())  # noqa: E501

    try:
        User.create(user.email, user.password)
        logger.info("Successfully created user '{}'".format(user.email))
    except UserAlreadyExists:
        logger.info("User already exists: '{}'".format(user.email))
 def test_unconfirmed(self, *_):
     User.create("*****@*****.**", "test_password")
     with self.assertRaises(IncorrectPassword):
         User.get("*****@*****.**").login("bad_password")
 def test_wrong_password(self, *_):
     User.create("*****@*****.**", "test_password")
     User.get("*****@*****.**").confirm(
         generate_token(SUPER_SECRET_CONFIRMATION_KEY, "*****@*****.**"))
     with self.assertRaises(IncorrectPassword):
         User.get("*****@*****.**").login("bad_password")
 def test_invalid_token(self, *_):
     User.create("*****@*****.**", "test_password")
     with self.assertRaises(IncorrectConfirmationToken):
         User.get("*****@*****.**").confirm("bad_token")
 def test_success(self, *_):
     User.create("*****@*****.**", "test_password")
     User.get("*****@*****.**").confirm(
         generate_token(SUPER_SECRET_CONFIRMATION_KEY, "*****@*****.**"))
     self.assertEqual(mock_db.DB["*****@*****.**"]['confirmed'], True)
 def test_duplicate_user(self, *_):
     User.create("*****@*****.**", "test_password")
     with self.assertRaises(UserAlreadyExists):
         User.create("*****@*****.**", "test_password")
 def test_success(self, *_):
     User.create("*****@*****.**", "test_password")