def test_post_card(self, mock_post): with app.app_context() as context: with app.test_request_context(data=patient1): context.push() mock_post.return_value = make_response(jsonify(patient1), 200) resp = GateCardResourse().post() self.assertEqual(resp.json["user_id"], 1) self.assertEqual(resp.status_code, 200)
def test_get_card(self, mock_get): with app.app_context() as context: with app.test_client(): context.push() mock_get.return_value = make_response(jsonify(patient1), 200) resp = GateCardResourse().get(user_id=1) self.assertEqual(resp.json["user_id"], 1) self.assertEqual(resp.status_code, 200)
def test_get_no_schedule(self, mock_get): with app.app_context() as context: with app.test_request_context(data={"user_id": 2}): context.push() fake_responses = [make_response(jsonify([]), 200)] mock_get.side_effect = fake_responses resp = GateScheduleResourse().get() self.assertEqual(resp.json, {"message": "You have not any appointments."})
def test_get_doc(self, mock_get): with app.app_context() as context: with app.test_request_context(): context.push() mock_get.return_value = make_response( jsonify([doctor1, doctor2]), 200) resp = GateDocsResourse().get() self.assertEqual(len(resp.json), 2) self.assertEqual(resp.status_code, 200)
def test_put_card_schedule_update(self, mock_get, mock_put_card): with app.app_context() as context: with app.test_request_context(data=patient1): context.push() mock_put_card.return_value = make_response( jsonify(patient1), 200) mock_get.return_value = make_response(jsonify(appoint1), 200) resp = GateCardResourse().put(1) self.assertEqual(resp.json["user_id"], 1) self.assertEqual(resp.status_code, 200)
def test_get_no_schedule_doc(self, mock_get): with app.app_context() as context: with app.test_request_context(data={ "user_id": 1, "id_card": 1000 }): context.push() fake_responses = [make_response(jsonify([]), 200)] mock_get.side_effect = fake_responses resp = GateScheduleResourse().get() self.assertEqual(resp.json, {"message": "No such appointment"})
def test_del_no_schedule(self, mock_get): with app.app_context() as context: with app.test_request_context(data={ "user_id": 2, "id_card": 4000 }): context.push() fake_responses = [make_response(jsonify([]), 200)] mock_get.side_effect = fake_responses resp = GateScheduleResourse().delete() self.assertEqual(resp.get_json()["message"], "No such appointment")
def test_del_schedule(self, mock_get, mock_del): with app.app_context() as context: with app.test_request_context(data={ "user_id": 2, "id_card": 4000 }): context.push() fake_responses = [make_response(jsonify([appoint6]), 200)] mock_get.side_effect = fake_responses mock_del.return_value = make_response(jsonify([]), 200) resp = GateScheduleResourse().delete() self.assertEqual(resp, 200)
def test_get_schedule(self, mock_get): with app.app_context() as context: with app.test_request_context(data={"user_id": 1}): context.push() fake_responses = [ make_response( jsonify( [appoint1, appoint2, appoint3, appoint4, appoint6]), 200), make_response( jsonify([doctor1, doctor1, doctor3, doctor4]), 200) ] mock_get.side_effect = fake_responses resp = GateScheduleResourse().get() self.assertEqual(len(resp), 4)
def test_post_made_schedule(self, mock_get): with app.app_context() as context: with app.test_request_context(data={ "user_id": 2, "id_card": 4000 }): context.push() fake_responses = [ make_response(jsonify(patient2), 200), make_response(jsonify(doctor4), 200), make_response(jsonify([appoint6]), 200) ] mock_get.side_effect = fake_responses resp = GateScheduleResourse().post() self.assertEqual(resp.get_json()["message"], "You already made an appointment") self.assertEqual(resp.status_code, 200)
def test_post_no_usercard(self, mock_get): with app.app_context() as context: with app.test_request_context(data={ "user_id": 3, "id_card": 4000 }): context.push() fake_responses = [ make_response(jsonify([]), 200), make_response(jsonify(doctor4), 200), make_response(jsonify([appoint6, appoint4]), 200) ] mock_get.side_effect = fake_responses resp = GateScheduleResourse().post() self.assertEqual( resp.get_json(), {"message": "Please, create a user card before"}) self.assertEqual(resp.status_code, 200)
def test_post_schedule(self, mock_get, mock_post): with app.app_context() as context: with app.test_request_context(data={ "user_id": 2, "id_card": 4000 }): context.push() fake_responses = [ make_response(jsonify(patient2), 200), make_response(jsonify(doctor4), 200), make_response(jsonify([]), 200) ] mock_get.side_effect = fake_responses mock_post.return_value = make_response(jsonify([appoint6]), 200) resp = GateScheduleResourse().post() self.assertEqual(resp.get_json()["appointment"], body_sched["appointment"]) self.assertEqual(resp.status_code, 200)