Esempio n. 1
0
 def test_add_tag(self):
     self.assertEqual(len(self.b.tags), 0)
     t = Tag("TOP2")
     db.session.add(t)
     db.session.commit()
     t2 = Tag("Cancer")
     db.session.add(t2)
     db.session.commit()
     self.b.tags.append(t)
     db.session.commit()
     self.assertEqual(len(self.b.tags), 1)
     self.b.tags.append(t2)
     db.session.commit()
     self.assertEqual(len(self.b.tags), 2)
Esempio n. 2
0
    def setUp(self):
        """Recreates the tables for a fresh start and populates them with a single user and post"""

        # Creates empty tables
        db.drop_all()
        db.create_all()

        # Adds a single user
        new_user = User(first_name='John', last_name='Doe')
        db.session.add(new_user)
        db.session.commit()

        # Adds a single post to new_user
        new_post = Post(title='A Test', content='Testing posts', user_id=1)
        db.session.add(new_post)
        db.session.commit()

        # Adds a single tag
        new_tag = Tag(name='Testing')
        db.session.add(new_tag)
        db.session.commit()

        # Tags 'A Test' as 'Testing'
        new_post_tag = PostTag(post_id=1, tag_id=1)
        db.session.add(new_post_tag)
        db.session.commit()
Esempio n. 3
0
    def test_edit_non_post_post2(self):
        with app.test_client() as client:
            new_tag = Tag(name='More Testing')
            db.session.add(new_tag)
            db.session.commit()

            resp = client.post(
                '/posts/a/edit', data={'title': 'Something Different', 'content': 'Almost not repetitive!', 'tags': ['1', '2']})

            post_tags = PostTag.query.all()
            self.assertEqual(len(post_tags), 1)

            self.assertEqual(resp.status_code, 404)
Esempio n. 4
0
    def test_edit_post_add_tag(self):
        with app.test_client() as client:
            new_tag = Tag(name='More Testing')
            db.session.add(new_tag)
            db.session.commit()

            resp = client.post('/posts/1/edit', data={'tags': ['1', '2']})

            self.assertEqual(resp.status_code, 302)
            self.assertEqual(resp.location, 'http://localhost/posts/1')

            post_tags = PostTag.query.all()
            self.assertEqual(len(post_tags), 2)

            resp2 = client.get('/posts/1')
            html = resp2.get_data(as_text=True)

            self.assertEqual(resp2.status_code, 200)
            self.assertIn('<h1>A Test</h1>', html)
            self.assertIn('<p>Testing posts</p>', html)
            self.assertIn('<i>By John Doe</i>', html)
            self.assertNotIn('WARNINGS GO HERE', html)
Esempio n. 5
0
    def test_edit_post_title_and_content_and_add_and_remove_tag(self):
        with app.test_client() as client:
            new_tag = Tag(name='More Testing')
            db.session.add(new_tag)
            db.session.commit()

            resp = client.post('/posts/1/edit', data={
                               'title': 'Something Different', 'content': 'Almost not repetitive!', 'tags': '2'})

            self.assertEqual(resp.status_code, 302)
            self.assertEqual(resp.location, 'http://localhost/posts/1')

            post_tags = PostTag.query.all()
            self.assertEqual(len(post_tags), 1)
            self.assertEqual(post_tags[0].tag_id, 2)

            resp2 = client.get('/posts/1')
            html = resp2.get_data(as_text=True)

            self.assertEqual(resp2.status_code, 200)
            self.assertIn('<h1>Something Different</h1>', html)
            self.assertIn('<p>Almost not repetitive!</p>', html)
            self.assertIn('<i>By John Doe</i>', html)
            self.assertNotIn('WARNINGS GO HERE', html)
Esempio n. 6
0
 def test_new_tag(self):
     t = Tag("TOP2")
     db.session.add(t)
     db.session.commit()
     self.assertEqual(t.name, "TOP2")