def setUp(self): self.app = app.test_client() logging.disable(logging.CRITICAL) database.connect() database.create_tables([City, State], safe=True) rv = self.app.post("/states", data=state_1) self.assertEqual(rv.status_code, 201)
def setUp(self): self.app = app.test_client() logging.disable(logging.CRITICAL) database.connect() database.create_tables([User, State, City, Place, Review, ReviewUser, ReviewPlace], safe=True) #Creating user rv = self.app.post("/users", data=user_1) self.assertEqual(rv.status_code, 201)
def setUp(self): """ Overload def setUp(self): to create a test client of airbnb app, and create amenity table in airbnb_test database. """ self.app = app.test_client() # set up test client self.app.testing = True # set testing to True logging.disable(logging.CRITICAL) # disable logs database.connect() # connect to airbnb_test db database.create_tables([Amenity], safe=True) # create amenity table
def setUp(self): """ Overload def setUp(self): to create a test client of airbnb app, and create state table in airbnb_test database. """ self.app = app.test_client() # set up test client self.app.testing = True # set testing to True logging.disable(logging.CRITICAL) # disable logs database.connect() # connect to airbnb_test db database.create_tables([State], safe=True) # create state table
def setUp(self): self.app = app.test_client() logging.disable(logging.CRITICAL) database.connect() database.create_tables( [User, State, City, Place, Review, ReviewUser, ReviewPlace], safe=True) #Creating user rv = self.app.post("/users", data=user_1) self.assertEqual(rv.status_code, 201)
def setUp(self): """ Overload def setUp(self): to create a test client of airbnb app, and create placebook table in airbnb_test database. """ self.app = app.test_client() # set up test client self.app.testing = True # set testing to True logging.disable(logging.CRITICAL) # disable logs # connect to airbnb_test database and create tables database.connect() database.create_tables([User, State, City, Place, PlaceBook], safe=True) # create user record for route user_record = User(email='anystring', password='******', first_name='anystring2', last_name='anystring3') user_record.save() # create state record for route state_record = State(name="foo-state") state_record.save() # create city record for route city_record = City(name="foo-city", state="1") city_record.save() # create place records for route place_record = Place(owner=1, city=1, name="foo", description="foo description", number_rooms=1, number_bathrooms=1, max_guest=1, price_by_night=1, latitude=20.0, longitude=22.0) place_record.save() place_record2 = Place(owner=1, city=1, name="foo", description="foo description", number_rooms=1, number_bathrooms=1, max_guest=1, price_by_night=1, latitude=20.0, longitude=22.0) place_record2.save()
def setUp(self): """ Overload def setUp(self): to create a test client of airbnb app, and create placebook table in airbnb_test database. """ self.app = app.test_client() # set up test client self.app.testing = True # set testing to True logging.disable(logging.CRITICAL) # disable logs # connect to airbnb_test database and create tables database.connect() database.create_tables([User, State, City, Place, PlaceBook], safe=True) # create user record for route user_record = User( email='anystring', password='******', first_name='anystring2', last_name='anystring3' ) user_record.save() # create state record for route state_record = State(name="foo-state") state_record.save() # create city record for route city_record = City(name="foo-city", state="1") city_record.save() # create place records for route place_record = Place( owner=1, city=1, name="foo", description="foo description", number_rooms=1, number_bathrooms=1, max_guest=1, price_by_night=1, latitude=20.0, longitude=22.0 ) place_record.save() place_record2 = Place( owner=1, city=1, name="foo", description="foo description", number_rooms=1, number_bathrooms=1, max_guest=1, price_by_night=1, latitude=20.0, longitude=22.0 ) place_record2.save()
def setUp(self): self.app = app.test_client() logging.disable(logging.CRITICAL) database.connect() database.create_tables([City, State, Place, User, PlaceBook], safe=True) rv = self.app.post('/states', data=state_1) self.assertEqual(rv.status_code, 201) rv = self.app.post('/states/1/cities', data=city_1) self.assertEqual(rv.status_code, 201) rv = self.app.post('/users', data=user_1) self.assertEqual(rv.status_code, 201)
def setUp(self): """ Overload def setUp(self): to create a test client of airbnb app, and create review table in airbnb_test database. """ self.app = app.test_client() # set up test client self.app.testing = True # set testing to True logging.disable(logging.CRITICAL) # disable logs database.connect() # connect to airbnb_test db database.create_tables( # create tables [User, State, City, Place, Review, ReviewUser, ReviewPlace], safe=True ) # create user record for routes user_record = User( email='anystring', password='******', first_name='anystring2', last_name='anystring3' ) user_record.save() user_record2 = User( email='anystring-2', password='******', first_name='anystring2', last_name='anystring3' ) user_record2.save() # create place records (and dependencies) for routes state_record = State(name='foo-statee') state_record.save() city_record = City(name='foo-city', state=1) city_record.save() place_record = Place( owner_id=1, city_id=1, name="foo", description="foo description", number_rooms=1, number_bathrooms=1, max_guest=1, price_by_night=1, latitude=20.0, longitude=22.0 ) place_record.save()
def init_database(): database.connect() database.create_tables([Post, User]) User.truncate_table() Post.truncate_table() repos = load_json('repos.json') for repo in repos: user, created = build_user(repo['owner']['login']) Post.create(title=repo['name'], slug=repo['full_name'], body=repo['description'], user=user) database.close()
def setUp(self): """ Overload def setUp(self): to create a test client of airbnb app, and create city table in airbnb_test database. """ self.app = app.test_client() # set up test client self.app.testing = True # set testing to True logging.disable(logging.CRITICAL) # disable logs # connect to airbnb_test db and create tables database.connect() database.create_tables([State, City], safe=True) # create state record for route state_record = State(name='namestring') state_record.save()
def test_create(self): """ Test proper creation (or non-creation) of state records upon POST requests to API. """ # test creation of state with all parameters provided in POST request State.drop_table() database.create_tables([State], safe=True) POST_request1 = self.app.post('/states', data=dict( name='namestring' )) self.assertEqual(POST_request1.status[:3], '200') now = datetime.now().strftime('%d/%m/%Y %H:%M') self.assertEqual(State.get(State.id == 1).name, 'namestring') self.assertEqual(State.get(State.id == 1).created_at.strftime('%d/%m/%Y %H:%M'), now) self.assertEqual(State.get(State.id == 1).updated_at.strftime('%d/%m/%Y %H:%M'), now) # test creation of state in all cases of a parameter missing in POST request POST_request2 = self.app.post('/states', data=dict()) self.assertEqual(POST_request2.status[:3], '400') # test that state ID for sole record in database is correct self.assertEqual(State.select().get().id, 1) # test that a post request with a duplicate name value is rejected POST_request3 = self.app.post('/states', data=dict( name='namestring' )) self.assertEqual(POST_request3.status[:3], '409') self.assertEqual(json.loads(POST_request3.data), {'code': 10001, 'msg': 'State already exists'})
from app.models.base import database from app.models.user import User from app.models.city import City from app.models.state import State from app.models.place import Place from app.models.place_book import PlaceBook from app.models.amenity import Amenity from app.models.place_amenity import PlaceAmenities from app.models.review import Review from app.models.review_place import ReviewPlace from app.models.review_user import ReviewUser ''' Initializes each table in the database ''' database.connect() database.create_tables([User, State, City, Place, Amenity, PlaceBook, PlaceAmenities, Review, ReviewUser, ReviewPlace], safe=True) database.close()
import peewee from app.models.base import database from app.models.user import User from app.models.city import City from app.models.state import State try: # important to user "create_tables" instead of "create_table", to create index and constraints database.create_tables([City, State, User], safe=True) except peewee.OperationalError: pass
def setUp(self): self.app = app.test_client() logging.disable(logging.CRITICAL) database.connect() database.create_tables([State], safe=True)
def create_tables(): database.connect() database.create_tables([User, State, City, Place, PlaceBook, Amenity, PlaceAmenities])
from app.models.base import database from app.models.user import User from app.models.city import City from app.models.state import State from app.models.place import Place from app.models.place_book import PlaceBook from app.models.amenity import Amenity from app.models.place_amenity import PlaceAmenities from app.models.review import Review from app.models.review_user import ReviewUser from app.models.review_place import ReviewPlace database.connect() database.create_tables([User, State, City, Place, Amenity, PlaceBook, PlaceAmenities, Review, ReviewUser, ReviewPlace], safe = True) database.close()
def setUp(self): self.app = app.test_client() logging.disable(logging.CRITICAL) database.connect() database.create_tables([Amenity, PlaceAmenities, Place, State, User, City], safe=True)