Ejemplo n.º 1
0
  def test_user(self):
    """ User creation and authentication
    Create new user
    Add to database
    Login and out"""
    # Make a new user
    u = User(username, password, email)
    with self.app.app_context():
      # Add to db
      db.session.add(u)
      db.session.commit()
      # Test queries
      self.assertIsNotNone(User.query.filter_by(username=username).first())
      self.assertIsNotNone(User.query.filter_by(email=email).first())
    # Test password secturity
    self.assertNotEqual(u.password, password)
    self.assertTrue(u.check_password(password))

    # Try an incorrect log in
    rv = self.login(username, 'not_correct')
    self.assertIn(b'Invalid username or password', rv.data)
    # Try correct login
    rv = self.login(username, password)
    # Test if log in was succsessful
    self.assertEqual(rv.status_code, 200)
    self.assertIn(b"logged in", rv.data)

    # Try logout
    rv = self.logout()
    self.assertIn(b'You were logged out', rv.data)
Ejemplo n.º 2
0
 def test_password_hashing(self):
     u = User(username='******')
     u.set_password('cat')
     self.assertFalse(u.check_password('dog'))
     self.assertTrue(u.check_password('cat'))