def test_bone(self): self.create_admin() self.post("test", "testdesc", 100, "Male", "husky") with APP.app_context(): id = DB.session.query(Post).first().id likedbefore = DB.session.query(User).first().has_liked(id) response = self.bone(id, 'like') with APP.app_context(): likedafter = DB.session.query(User).first().has_liked(id) self.assertNotEqual(likedbefore, likedafter)
def test_comments(self): self.create_admin() self.post("test", "testdesc", 100, "Male", "husky") with APP.app_context(): id = DB.session.query(Post).first().id response = self.comment(id, "comentariutest") n = 0 with APP.app_context(): n = DB.session.query(Comment).count() self.assertEqual(1, n)
def setUp(self): with APP.app_context(): APP.config['TESTING'] = True APP.config['WTF_CSRF_ENABLED'] = False APP.config['DEBUG'] = False APP.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db' self.APP = APP.test_client() DB.init_app(APP) DB.drop_all() DB.create_all() self.assertEqual(APP.debug, False)
def test_delete_post(self): self.create_admin() self.post("test", "testdesc", 100, "Male", "husky") with APP.app_context(): id = DB.session.query(Post).first().id countbefore = DB.session.query(Post).count() response = self.APP.post(('/delete_post?id=%d' % id), follow_redirects=True) with APP.app_context(): countafter = DB.session.query(Post).count() self.assertNotEqual(countbefore, countafter)
def create_admin(self): response = self.register('*****@*****.**', 'admin123', 'admin') with APP.app_context(): DB.session.query(User).first().rank = 1 DB.session.commit() response = self.login('admin', 'admin123') self.assertEqual(response.status_code, 200)
def test_valid_posting(self): self.create_admin() response = self.post("test", "testdesc", 100, "Male", "husky") response = self.post("test2", "testdesc", 100, "Male", "husky") n = 0 with APP.app_context(): n = DB.session.query(Post).count() self.assertEqual(2, n)
def test_profile(self): self.create_admin() self.APP.post('/profile', data=dict(last_name="gigel", first_name="adminul", phone="0722222222"), follow_redirects=True) with APP.app_context(): user = DB.session.query(User).first() self.assertEqual(user.last_name, "gigel") self.assertEqual(user.first_name, "adminul") self.assertEqual(user.phone, "0722222222")
def test_socketio(): APP.config['WTF_CSRF_ENABLED'] = False flask_test_client = APP.test_client() socketio_test_client = socketio.test_client( APP, flask_test_client=flask_test_client) assert socketio_test_client.is_connected() r = flask_test_client.post('/', data={ 'email': '*****@*****.**', 'password': '******'}) assert r.status_code == 307 socketio_test_client = socketio.test_client( APP, flask_test_client=flask_test_client) socketio_test_client.send({'room': 'room1', 'data': 'This is a test'}) r = socketio_test_client.get_received() assert len(r) == 1 message = r[0].get('args').get('data') assert message == 'This is a test'
""" # here we need to serialize person schema = PersonSchema() result = schema.dump(munhu) logging.info(result) resp.media = result resp.status = falcon.HTTP_200 def on_post(self, req, res): # here we need to deserialize to a python object since we are recieving json from req.media # user_req = req.context["data"] # logger.info(req.stream.read()) schema = PersonSchema() try: result = schema.load(req.media) except ValidationError as err: err.messages['name'] = "You need to supply a {}".format(err.messages.keys()) res.media = err.messages res.status = falcon.HTTP_403 # req.context.data = req.media # person = Person(**req.media) # person_data.update(user_req) res.status = falcon.HTTP_201 person = PersonResource() app = APP() app.add_route('/people', person)
def setUp(self): self.APP = APP.test_client() self.APP.testing = True
def client(): APP.config['TESTING'] = True APP.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False with APP.test_client() as client: yield client
from main import APP from eeh.views.home import * from eeh.views.settings import * from eeh.views.add import * from eeh.views.delete import * from eeh.views.app import * from eeh.views.errors import * from eeh.api.v1 import * from eeh.views.plan import * from eeh.views.login import * from eeh.views.scout_team import * from eeh.views.scouting_troop import * if __name__ == '__main__': APP.run(debug=True)
from main import APP as application if __name__ == "__main__": application.run()
def client(): client = APP.test_client() yield client
def app(): """Yield your app with its context set up and ready""" with APP.app_context(): yield APP