def test_json_wall_fail(self): app = test_app.test_client() reply = login(app, '*****@*****.**', 'daddysflownacrosstheocean') reply = app.get('/thewall/' + '-1') self.assertIn('User NOT Found', str(reply.data))
def test_mywall(self): app = test_app.test_client() reply = login(app, '*****@*****.**', 'daddysflownacrosstheocean') reply = app.get('/wall') self.assertIn('*****@*****.**', str(reply.data))
def test_delete_story_negative(self): global _app if _app is None: tested_app = create_app(debug=True) _app = tested_app else: tested_app = _app restart_db_tables(db, tested_app) with tested_app.test_client() as client: # login reply = login(client, '*****@*****.**', 'admin') self.assertEqual(reply.status_code, 200) users = User.query.all() self.assertEqual(len(users), 1) # add reaction to a story reply = client.get('/stories/reaction/1/1') self.assertEqual(reply.status_code, 200) reply = client.post('stories/2/remove/stories', follow_redirects=True) self.assertEqual(reply.status_code, 404) story = db.session.query(Story).filter_by(id=1).first() self.assertNotEqual(story, None) reactions = Reaction.query.filter_by(story_id=1).all() self.assertEqual(len(reactions), 1) stories = Story.query.filter_by(id=1).all() self.assertEqual(len(stories), 1) users = User.query.all() self.assertEqual(len(users), 1) reply = client.post('stories/1/remove/stories', follow_redirects=True) self.assertEqual(reply.status_code, 200) assert b'The story has been canceled.' in reply.data reactions = Reaction.query.filter_by(story_id=1).all() self.assertEqual(len(reactions), 0) # logout reply = logout(client) self.assertEqual(reply.status_code, 200)
def test_wall(self): app = test_app.test_client() reply = login(app, '*****@*****.**', 'daddysflownacrosstheocean') q = db.session.query(User).filter(User.email == '*****@*****.**') user: User = q.first() reply = app.get('/wall/' + str(user.id)) self.assertIn(user.email, str(reply.data)) q = db.session.query(Story).filter(Story.author_id == user.id) for s in q: s: Story self.assertIn(s.text, str(reply.data))
def test_delete_wrong_author_story_index(self): global _app if _app is None: tested_app = create_app(debug=True) _app = tested_app else: tested_app = _app restart_db_tables(db, tested_app) with tested_app.test_client() as client: # login reply = login(client, '*****@*****.**', 'admin') self.assertEqual(reply.status_code, 200) # add reaction to a story reply = client.get('/stories/reaction/1/1') self.assertEqual(reply.status_code, 200) users = User.query.all() self.assertEqual(len(users), 1) story = db.session.query(Story).filter_by(id=1).first() self.assertNotEqual(story, None) # logout reply = logout(client) self.assertEqual(reply.status_code, 200) # signup user1 = User() user1.firstname = "Mario" user1.lastname = "Rossi" user1.email = "*****@*****.**" user1.dateofbirth = "1994" user1.password = user1.set_password("12345") reply = signup(client, user1) self.assertEqual(reply.status_code, 200) users = User.query.all() self.assertEqual(len(users), 2) story = db.session.query(Story).filter_by(id=1).first() self.assertNotEqual(story, None) stories = Story.query.filter_by(id=1).all() self.assertEqual(len(stories), 1) reactions = Reaction.query.filter_by(story_id=1).all() self.assertEqual(len(reactions), 1) story = db.session.query(Story).filter_by(id=1).first() self.assertNotEqual(story, None) reactions = Reaction.query.filter_by(story_id=1).all() self.assertEqual(len(reactions), 1) # add reaction to a story reply = client.get('/stories/reaction/1/1') self.assertEqual(reply.status_code, 200) reply = client.post('stories/1/remove/index', follow_redirects=True) self.assertEqual(reply.status_code, 200) story = db.session.query(Story).filter_by(id=1).first() self.assertNotEqual(story, None) # logout reply = logout(client) self.assertEqual(reply.status_code, 200)