def test_login(self): username = "******" password = "******" phone_number = "13971270000" admin = User(username=username, password=password, phone_number=phone_number) db.session.add(admin) db.session.commit() resp = self.client.post(url_for('api.login'), data=dict(username=username, password=password)) json_resp = json.loads(resp.data.decode('utf-8')) self.assertEqual(json_resp['ok'], True) self.assertEqual(json_resp['phone_number'], phone_number)
def test_change_phone_number(self): username = "******" password = "******" old_phone_number = "13971270000" admin = User(username=username, password=password, phone_number=old_phone_number) db.session.add(admin) db.session.commit() new_phone_number = "13971279099" resp = self.client.put(url_for('api.change_phone'), data=dict(username=username, password=password, phone_number=new_phone_number)) self.assertEqual(resp.status_code, 200) json_resp = json.loads(resp.data.decode('utf-8')) self.assertEqual(json_resp['ok'], True) db_user = User.query.filter_by(username=username).first() self.assertIsNotNone(db_user) self.assertNotEqual(db_user.phone_number, old_phone_number) self.assertEqual(db_user.phone_number, new_phone_number)
def test_no_password_getter(self): u = User(password='******') with self.assertRaises(AttributeError): u.password
def test_password_setter(self): u = User(password='******') self.assertTrue(u.password_hash is not None)
def test_password_salts_are_random(self): u = User(password='******') u1 = User(password='******') self.assertNotEqual(u.password_hash, u1.password_hash)
def test_password_verification(self): u = User(password='******') self.assertTrue(u.verify_password('cat')) self.assertFalse(u.verify_password('dog'))
def create_admin(username, password, phone_number): u = User(username=username, password=password, phone_number=phone_number) db.session.add(u) db.session.commit()