def test_forbidden_user_get(self, mock_get): with app.app_context() as context: with app.test_request_context(): context.push() mock_get.return_value = '' resp = GateCardResourse().get(1) self.assertEqual(resp.status_code, 401)
def test_get(self): with app.app_context() as context: context.push() db.session.remove() db.drop_all() db.create_all() self.assertIsNone(User.query.get(1)) db.session.remove()
def test_get_api(self): with app.app_context() as context: context.push() db.session.remove() db.drop_all() db.create_all() client = app.test_client() response = client.get('/api') self.assertEqual(response.status_code, 200)
def test_post_new_user(self, mock_post): with app.app_context() as context: with app.test_request_context('/api', json=card1): context.push() db.session.remove() db.drop_all() db.create_all() mock_post.return_value = card1 resp = FirstResourse().post() self.assertEqual(resp["email"], card1["email"])
def test_get(self, mock_get): with app.app_context() as context: with app.test_request_context('/api'): context.push() mock_get.return_value = make_response( jsonify({ "message": "It is the Index page. To continue, please, \ use post request with 'email' and 'password' fields to register." }), 200) resp = FirstResourse().get() self.assertEqual(resp.status_code, 200)
def test_exist(self): with app.app_context() as context: context.push() db.session.remove() db.drop_all() db.create_all() card1.update({"password_hash": set_password(card1['password'])}) user = UserSchema().make_instance(card1, partial=False) db.session.add(user) db.session.commit() exist = User.query.get(card1["id"]) self.assertEqual(user.id, exist.id) db.session.remove()
def test_post_exist_user(self, mock_post): with app.app_context() as context: with app.test_request_context('/api', json=card1): context.push() db.session.remove() db.drop_all() db.create_all() card1.update( {"password_hash": set_password(card1['password'])}) user = UserSchema().make_instance(card1, partial=False) db.session.add(user) db.session.commit() mock_post.return_value = 'use different email!' resp = FirstResourse().post() self.assertEqual(resp, 'use different email!')
def test_user_get_card(self, mock_get): with app.app_context() as context: with app.test_request_context( '/api/users/1/card', headers=dict(Authorization=f"{authent}")): context.push() db.session.remove() db.drop_all() db.create_all() card1.update( {"password_hash": set_password(card1['password'])}) user = UserSchema().make_instance(card1, partial=False) db.session.add(user) db.session.commit() mock_get.return_value = make_response(jsonify([patient1]), 200) resp = GateCardResourse().get(id=1) self.assertEqual(resp.status_code, 200)
def test_post_user(self): with app.app_context() as context: with app.test_client() as client: context.push() db.session.remove() db.drop_all() db.create_all() card1.update( {"password_hash": set_password(card1['password'])}) user = UserSchema().make_instance(card1, partial=False) db.session.add(user) db.session.commit() response = client.get('/api/users/1', headers=dict(Authorization=f"{authent}")) self.assertEqual(response.status_code, 200) self.assertEqual(response.json["email"], card1["email"]) db.session.remove()