def test_crud(self): with self.app_context(): address = "200 University Ave W, Waterloo, ON N2L 3G1" latitude = 43.4717512 longitude = -80.5459129 geo = "POINT({} {})".format(longitude, latitude) phone = "123456789" fax = "123456789" is_wheelchair_accessible = True is_accepting_new_patients = True start_hour = datetime.strptime( "08:00", '%H:%M').time() end_hour = datetime.strptime( "08:00", '%H:%M').time() address = AddressModel(address=address, latitude=latitude, longitude=longitude, geo=geo, phone=phone, fax=fax, is_wheelchair_accessible=is_wheelchair_accessible, is_accepting_new_patients=is_accepting_new_patients, start_hour=start_hour, end_hour=end_hour) self.assertIsNone(AddressModel.find_by_id( 1), "Found a user with address '1' before save_to_db") address.save_to_db() self.assertIsNotNone(AddressModel.find_by_id( 1), "Did not find a address with id '1' after save_to_db")
def post(cls): data = request.get_json() if CustomerModel.find_by_email(data["email"]): return {"message": ERROR_EMAIL_EXISTS}, 400 address_data = data['address'] data.pop('address', None) user = customer_schema.load(data) try: user.save_to_db() confirmation = ConfirmationModel(user.id) address = AddressModel(**address_data, customer_id=user.id) address.save_to_db() confirmation.save_to_db() link = request.url_root[:-1] + url_for( "customerconfirmation", confirmation_id=user.most_recent_confirmation.id ) # support for emails foreign to Mailgun except: traceback.print_exc() return {"message": ERROR_SAVING_USER}, 500 user.send_confirmation_email() return {"message": USER_REGISTERED, "confirmation_link": link}, 200