Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
 def test_no_password_getter(self):
     u = User(password='******')
     with self.assertRaises(AttributeError):
         u.password
Пример #4
0
 def test_password_setter(self):
     u = User(password='******')
     self.assertTrue(u.password_hash is not None)
Пример #5
0
 def test_password_salts_are_random(self):
     u = User(password='******')
     u1 = User(password='******')
     self.assertNotEqual(u.password_hash, u1.password_hash)
Пример #6
0
 def test_password_verification(self):
     u = User(password='******')
     self.assertTrue(u.verify_password('cat'))
     self.assertFalse(u.verify_password('dog'))
Пример #7
0
def create_admin(username, password, phone_number):
    u = User(username=username, password=password, phone_number=phone_number)
    db.session.add(u)
    db.session.commit()