def test_appointment_serialize(self): appointment = Appointment(1, utils.format_date('2017-09-12 08:20:00'), 'this is test data') data = json.dumps(appointment.serialize()) expected = json.dumps({ "id": "1", "appointment_time": "2017-09-12 08:20:00", "description": "this is test data" }) assert expected == data
def get_all_appointments(): """ Returns appointment object in DB. """ db = mainappbp.get_db(current_app) cursor = db.cursor() cursor.execute('SELECT * FROM '+ __tbl_name__) result_set = cursor.fetchall() return [Appointment(result[0],utils.format_date(result[1]),result[2]) for result in result_set]
def find_by_description(keyword): """ Returns list of appointment objects selectively. @param keyword """ db = mainappbp.get_db(current_app) cursor = db.cursor() cursor.execute("SELECT * FROM "+ __tbl_name__+" WHERE instr(description,?)",(keyword,)) result_set = cursor.fetchall() return [Appointment(result[0],utils.format_date(result[1]),result[2]) for result in result_set]
def test_add_appointments_invalid_request(self): with self.app.app_context(): #empty data response = self.test_client.post('/api/v1.0/', data="", content_type="application/json") assert response.status_code == 400 #with content type default appointment = Appointment(1, utils.format_date('2017-09-12 08:20:00'), 'this is test data') data = json.dumps(appointment.serialize()) response = self.test_client.post('/api/v1.0/', data=data) assert response.status_code == 400 #with Appointment.appointment_time None data = json.dumps({"description": "this is test data"}) response = self.test_client.post('/api/v1.0/', data=data) assert response.status_code == 400 #with Appointment.description None data = json.dumps({"appointment_time": "2017-09-12 08:20:00"}) response = self.test_client.post('/api/v1.0/', data=data) assert response.status_code == 400
def test_add_appointment_happyday(self): with self.app.app_context(): db = mainappbp.get_db(self.app) date = datetime.datetime(2017, 10, 21, 12, 00) appointment = Appointment(None, date, "Birthday") service.add_appointment(appointment) cursor = db.cursor() result = cursor.execute( "SELECT * from tbl_appointments").fetchone() assert result[0] == 1 # '2017-10-21 12:00:00' assert result[1] == date.strftime(utils.SQL_DATE_TIME_FORMAT) assert result[2] == "Birthday"
def create_appointment(): """ validates incoming json data and saves """ print request.json if not request.json: abort(400) if not 'appointment_time' in request.json: abort(400) if not 'description' in request.json: abort(400) appointment = Appointment( None, utils.format_date(request.json['appointment_time']), request.json['description']) app_repository.add_appointment(appointment) return jsonify({'message': 'Appointment Saved !'}), 200
def test_add_appointment_with_null(self): with self.app.app_context(): appointment = Appointment(None, None, None) self.assertRaises(ValueError, service.add_appointment, appointment)
def test_add_appointment_exception_no_context(self): date = datetime.datetime(2017, 10, 21, 12, 00) self.assertRaises(RuntimeError, service.add_appointment, Appointment(None, date, "desc"))