def setUp(self): db.drop_all() db.create_all() self.success = {'code': 200} self.success_create = {'code': 201} self.not_json = {'code': 400, 'error': 'post type must be json'} self.field_not_complete = {'code': 400, 'error': 'fields not complete'} self.error_need_login = {'code': 403, 'error': 'need to login'} self.error_need_csrf = {'code': 400, 'error': 'needs csrf token'} self.error_wrong_csrf = {'code': 400, 'error': 'wrong csrf token'} user = User.create('*****@*****.**', 'strong_password') another_user = User.create('*****@*****.**', 'strong_password') event = Event.create('dinner', datetime(2017, 7, 7, 18, 30, 0)) another_event = Event.create('lunch', datetime(2017, 7, 7, 18, 30, 0)) self.user_id = user.user_id self.event_id = event.event_id self.another_user_id = another_user.user_id self.another_event_id = another_event.event_id user.events.append(event) another_user.events.append(another_event) db.session.add(user) db.session.add(another_user) db.session.commit()
def test_add_user(self): self.assertEqual(len(User.query.all()), 0) user = User.create('*****@*****.**', 'strong_password') db.session.add(user) db.session.commit() self.assertEqual(len(User.query.all()), 1) user = User.create('*****@*****.**', 'strong_password') db.session.add(user) db.session.commit() self.assertEqual(len(User.query.all()), 2)
def setUp(self): db.create_all() user = User.create('*****@*****.**', 'strong_password') user2 = User.create('*****@*****.**', 'strong_password') event = Event.create('dinner', datetime(2018, 7, 5, 18, 30, 0)) event2 = Event.create('dinner', datetime(2018, 7, 5, 18, 30, 0)) user.events.append(event) user2.events.append(event2) self.user_id = user.user_id self.user_id2 = user2.user_id self.event_id = event.event_id self.event_id2 = event2.event_id db.session.add(user) db.session.add(user2) db.session.commit()
def setUp(self): db.create_all() user = User.create('*****@*****.**', 'strong_password') self.user_id = user.user_id db.session.add(user) db.session.commit()
def test_query_user_id(self): self.assertEqual(len(User.query.all()), 0) email, password = '******', 'strong_password' user = User.create(email, password) user_id = user.user_id db.session.add(user) db.session.commit() self.assertEqual(len(User.query.all()), 1) query_email = User.query.filter_by(user_id=user_id).first() self.assertEqual(query_email.email, email) self.assertEqual(query_email.user_id, user_id) self.assertTrue(query_email.verify(password))
def setUp(self): db.drop_all() db.create_all() self.success = {'code': 200} self.success_create = {'code': 201} self.not_json = {'code': 400, 'error': 'post type must be json'} self.error_need_login = {'code': 403, 'error': 'need to login'} self.error_need_csrf = {'code': 400, 'error': 'needs csrf token'} self.error_wrong_csrf = {'code': 400, 'error': 'wrong csrf token'} user = User.create('*****@*****.**', 'strong_password') self.user_id = user.user_id db.session.add(user) db.session.commit()
def setUp(self): db.drop_all() db.create_all() self.success = {'code': 200} self.success_create = {'code': 201} self.not_json = {'code': 403, 'error': 'post type must be json'} self.field_not_complete = {'code': 403, 'error': 'fields not complete'} self.wrong_email = {'code': 403, 'error': "format check of email failed: got today's dinner"} user = User.create('*****@*****.**', 'strong_password') event = Event.create('dinner', datetime.now()) self.user_id = user.user_id self.event_id = event.event_id user.events.append(event) db.session.add(user) db.session.commit()
def setUp(self): db.drop_all() db.create_all() self.success = {'code': 200} self.success_create = {'code': 201} self.not_json = {'code': 400, 'error': 'post type must be json'} self.field_not_complete = {'code': 400, 'error': 'fields not complete'} self.wrong_email = { 'code': 400, 'error': "format check of email failed: got today's dinner" } self.error_need_csrf = {'code': 400, 'error': 'needs csrf token'} self.error_wrong_csrf = {'code': 400, 'error': 'wrong csrf token'} user = User.create('*****@*****.**', 'strong_password') self.user_id = user.user_id db.session.add(user) db.session.commit()
def test_delete_user_and_events(self): self.assertEqual(len(User.query.all()), 0) user = User.create('*****@*****.**', 'strong_password') user.events = [ Event.create('dinner', datetime.now()), Event.create('lunch', datetime.now()), Event.create('breakfast', datetime.now()), ] user_id = user.user_id db.session.add(user) db.session.commit() self.assertEqual(len(User.query.all()), 1) self.assertEqual(len(Event.query.all()), 3) user = User.query.filter_by(user_id=user_id).first() db.session.delete(user) db.session.commit() self.assertEqual(len(User.query.all()), 0) self.assertEqual(len(Event.query.all()), 0)