示例#1
0
 def test_post_route_redirects_to_user_list(self):
     with app.test_client() as client:
         res = client.post('/users/new',
                           data={'first_name': 'John',
                                 'last_name': 'Doe', 'image_url': 'hello'})
         self.assertEqual(res.status_code, 302)
         self.assertEqual(res.location, 'http://localhost/users')
示例#2
0
 def test_route_view_correct_post(self):
     with app.test_client() as client:
         res = client.get(f'/posts/{self.p1_id}')
         html = res.get_data(as_text=True)
         p1 = Post.query.get(self.p1_id)
         self.assertIn(p1.title, html)
         self.assertIn(p1.content, html)
示例#3
0
 def setUpClass(cls):
     with app.test_request_context():
         cls.client = app.test_client()
         cls.user = User()
         cls.user.username = '******'
         cls.user.password = '******'
         cls.user.save()
示例#4
0
 def setUpClass(cls):
     with app.test_request_context():
         cls.client = app.test_client()
         cls.user = User()
         cls.user.username = '******'
         cls.user.password = '******'
         cls.user.save()
示例#5
0
 def setUp(self):
     app = self.create_app()
     self.app = app.test_client()
     with app.app_context():
         self.init_db()
     self.req = ({'username': '******', 'password': '******'})
     self.bucketlist_url = '/api/v1/bucketlists/'
示例#6
0
    def get(self, *args, **kwargs):
        with app.test_client() as c:
            if 'user' in kwargs:
                user = kwargs.pop('user')
                with c.session_transaction() as session:
                    session['user'] = user.to_dict()

            return c.get(*args, **kwargs)
示例#7
0
    def test_route_deletes_user(self):
        with app.test_client() as client:
            res = client.get(
                f'/users/{self.benny_id}/delete', follow_redirects=True)

            self.assertEqual(res.status_code, 200)
            benny = User.query.get(self.benny_id)
            self.assertIsNone(benny)
示例#8
0
 def setUp(self):
     app = self.create_app()
     self.app = app.test_client()
     with app.app_context():
         self.init_db()
     self.reg_url = '/api/v1/auth/register'
     self.login_url = '/api/v1/auth/login'
     self.bucketlist_url = '/api/v1/bucketlists'
示例#9
0
 def test_post_route_redirects_to_user_details(self):
     with app.test_client() as client:
         res = client.post(f'/users/{self.u_id}/posts/new',
                           data={'title': 'New',
                                 'content': 'New post content!'})
         self.assertEqual(res.status_code, 302)
         self.assertEqual(
             res.location, f'http://localhost/users/{self.u_id}')
示例#10
0
    def test_route_deletes_user(self):
        with app.test_client() as client:
            res = client.get(f'/tags/{self.sam_id}/delete',
                             follow_redirects=True)

            self.assertEqual(res.status_code, 200)
            sam = Tag.query.get(self.sam_id)
            self.assertIsNone(sam)
示例#11
0
    def test_route_responds_with_corrent_page(self):
        with app.test_client() as client:
            res = client.get(f'/users/{self.u_id}/posts/new')
            self.assertEqual(res.status_code, 200)

            html = res.get_data(as_text=True)
            user = User.query.get(self.u_id)
            self.assertIn(f'{user.first_name} is making a post', html)
示例#12
0
 def setUp(self):
     app = self.create_app()
     self.app = app.test_client()
     with app.app_context():
         self.init_db()
     self.user = ({'username': '******', 'password': '******'})
     self.bucketlist = ({'name': 'Before the end of the Year'})
     self.item_url = '/api/v1/bucketlists/1/items/'
示例#13
0
    def test_post_route_redirects_to_tag_list(self):
        with app.test_client() as client:
            res = client.get(f'/tags/{self.fun_id}/delete')

            self.assertEqual(res.status_code, 302)
            self.assertEqual(res.location, 'http://localhost/tags')
            res = client.get(res.location)
            html = res.get_data(as_text=True)
            self.assertNotIn('fun', html)
示例#14
0
 def test_post_route_rejects_no_name(self):
     with app.test_client() as client:
         res = client.post('/tags/new',
                           data={'name': ''},
                           follow_redirects=True)
         self.assertEqual(res.status_code, 200)
         tag = Tag.query.filter_by(name="").one_or_none()
         #tag was never made
         self.assertIsNone(tag)
示例#15
0
 def test_post_route_redirects_to_all_tags_page(self):
     with app.test_client() as client:
         res = client.post(f'/tags/{self.sam_id}/edit',
                           data={'name': 'John'})
         self.assertEqual(res.status_code, 302)
         self.assertEqual(res.location, 'http://localhost/tags')
         res = client.get(res.location)
         html = res.get_data(as_text=True)
         self.assertIn('John', html)
示例#16
0
    def test_route_edit_form_contains_post_info(self):
        with app.test_client() as client:
            res = client.get(f'/posts/{self.p1_id}/edit')
            html = res.get_data(as_text=True)
            p1 = Post.query.get(self.p1_id)

            self.assertIn(f'value="{p1.title}"', html)
            self.assertIn(f'value="{p1.content}"', html)
            self.assertIn(p1.creator.first_name, html)
示例#17
0
    def test_post_route_redirects_to_user_list(self):
        with app.test_client() as client:
            res = client.get(f'/users/{self.sam_id}/delete')

            self.assertEqual(res.status_code, 302)
            self.assertEqual(res.location, 'http://localhost/users')
            res = client.get(res.location)
            html = res.get_data(as_text=True)
            self.assertNotIn('Sam Crewe-Sullam', html)
示例#18
0
 def test_post_route_edits_tag_info(self):
     with app.test_client() as client:
         fun_tag = Tag.query.get(self.fun_id)
         self.assertEqual(fun_tag.name, 'fun')
         res = client.post(f'/tags/{self.fun_id}/edit',
                           data={'name': 'Benny'},
                           follow_redirects=True)
         self.assertEqual(res.status_code, 200)
         fun_tag = Tag.query.get(self.fun_id)
         self.assertEqual(fun_tag.name, 'Benny')
示例#19
0
 def test_post_route_rejects_no_first_name(self):
     with app.test_client() as client:
         res = client.post('/users/new',
                           data={'first_name': '',
                                 'last_name': 'Doe', 'image_url': ''},
                           follow_redirects=True)
         self.assertEqual(res.status_code, 200)
         user = User.query.filter_by(last_name="doe").one_or_none()
         # user was never made
         self.assertIsNone(user)
示例#20
0
 def test_post_route_redirects_to_user_description_page(self):
     with app.test_client() as client:
         res = client.post(f'/users/{self.sam_id}/edit',
                           data={'first_name': 'John',
                                 'last_name': 'Doe', 'image_url': 'hello'})
         self.assertEqual(res.status_code, 302)
         self.assertEqual(
             res.location, f'http://localhost/users/{self.sam_id}')
         res = client.get(res.location)
         html = res.get_data(as_text=True)
         self.assertIn('John Doe', html)
示例#21
0
 def test_post_route_edits_user_info(self):
     with app.test_client() as client:
         benny = User.query.get(self.benny_id)
         self.assertEqual(benny.last_name, 'G')
         res = client.post(f'/users/{self.benny_id}/edit',
                           data={'first_name': 'Benny',
                                 'last_name': 'Gee', 'image_url': ''},
                           follow_redirects=True)
         self.assertEqual(res.status_code, 200)
         benny = User.query.get(self.benny_id)
         self.assertEqual(benny.last_name, 'Gee')
示例#22
0
    def test_post_route_gives_an_image_if_one_was_not_provided(self):
        with app.test_client() as client:
            res = client.post('/users/new',
                              data={'first_name': 'John',
                                    'last_name': 'Doe', 'image_url': ''},
                              follow_redirects=True)
            user = User.query.filter_by(
                first_name='John', last_name='Doe').one_or_none()

            self.assertNotEqual(user.image_url, '')
            self.assertEqual(user.image_url, DEFAULT_IMAGE_URL)
示例#23
0
    def test_post_route_rejects_no_name(self):
        with app.test_client() as client:

            res = client.post(f'/tags/{self.sam_id}/edit',
                              data={'name': ''},
                              follow_redirects=True)
            self.assertEqual(res.status_code, 200)

            sam = Tag.query.get(self.sam_id)
            self.assertNotEqual(sam.name, '')
            # No change was made
            self.assertEqual(sam.name, 'Sam')
示例#24
0
 def test_post_route_edits_post_info(self):
     with app.test_client() as client:
         post = Post.query.get(self.p1_id)
         self.assertEqual(post.title, 'SuperCool')
         res = client.post(f'/posts/{self.p1_id}/edit',
                           data={'title': 'A Different Title',
                                 'content': 'Different Content'},
                           follow_redirects=True)
         self.assertEqual(res.status_code, 200)
         post = Post.query.get(self.p1_id)
         self.assertEqual(post.title, 'A Different Title')
         self.assertEqual(post.content, 'Different Content')
示例#25
0
    def test_post_route_rejects_no_first_name(self):
        with app.test_client() as client:

            res = client.post(f'/users/{self.sam_id}/edit',
                              data={'first_name': '',
                                    'last_name': 'Doe', 'image_url': ''},
                              follow_redirects=True)
            self.assertEqual(res.status_code, 200)

            sam = User.query.get(self.sam_id)
            self.assertNotEqual(sam.first_name, '')
            # No change was made
            self.assertEqual(sam.first_name, 'Sam')
示例#26
0
    def test_post_route_rejects_repeats(self):
        with app.test_client() as client:
            res = client.post('/tags/new',
                              data={'name': 'Sam'},
                              follow_redirects=True)
            self.assertEqual(res.status_code, 200)
            res = client.post('/tags/new',
                              data={'name': 'Sam'},
                              follow_redirects=True)
            self.assertEqual(res.status_code, 200)

            html = res.get_data(as_text=True)
            self.assertIn('I think We already got that Tag!', html)
示例#27
0
    def test_post_route_adds_tag(self):
        with app.test_client() as client:
            tags = Tag.query.filter_by(name='Unique Tag').all()
            #user doesn't exist yet
            self.assertEqual(tags, [])

            res = client.post('/tags/new',
                              data={'name': 'Unique Tag'},
                              follow_redirects=True)
            self.assertEqual(res.status_code, 200)
            self.assertIn('Unique Tag', res.get_data(as_text=True))
            tag = Tag.query.filter_by(name='Unique Tag').one_or_none()
            self.assertEqual(tag.name, 'Unique Tag')
示例#28
0
    def test_post_route_adds_post(self):
        post = Post.query.filter_by(
            title='New', content='New post content!').one_or_none()
        self.assertIsNone(post)

        with app.test_client() as client:
            res = client.post(f'/users/{self.u_id}/posts/new',
                              data={'title': 'New',
                                    'content': 'New post content!'},
                              follow_redirects=True)

            self.assertEqual(res.status_code, 200)

            post = Post.query.filter_by(
                title='New', content='New post content!').first()
            self.assertEqual(post.user_id, self.u_id)
示例#29
0
    def test_post_route_gives_an_image_if_one_was_not_provided(self):
        with app.test_client() as client:
            toni = User.query.get(self.toni_id)
            self.assertEqual(toni.image_url,
                             'https://mysite.com/myimg.jpg')

            res = client.post(f'/users/{self.toni_id}/edit',
                              data={'first_name': 'Toni',
                                    'last_name': '', 'image_url': ''},
                              follow_redirects=True)

            self.assertEqual(res.status_code, 200)
            toni = User.query.get(self.toni_id)
            self.assertNotEqual(toni.image_url, 'https://mysite.com/myimg.jpg')
            self.assertNotEqual(toni.image_url, '')
            self.assertEqual(toni.image_url, DEFAULT_IMAGE_URL)
示例#30
0
    def test_post_route_adds_user(self):
        with app.test_client() as client:
            users = User.query.filter_by(
                first_name='John', last_name='Doe').all()
            # user doesn't exist yet
            self.assertEqual(users, [])

            res = client.post('/users/new',
                              data={'first_name': 'John',
                                    'last_name': 'Doe', 'image_url': 'hello'},
                              follow_redirects=True)
            self.assertEqual(res.status_code, 200)
            self.assertIn('John Doe', res.get_data(as_text=True))
            user = User.query.filter_by(
                first_name='John', last_name='Doe').one_or_none()
            self.assertEqual(user.image_url, 'hello')
示例#31
0
 def setUpClass(cls):
     cls.client = app.test_client()
示例#32
0
def client():
    with app.test_client() as client:
        yield client
示例#33
0
def client_form():
    with app.test_client() as client:
        yield client, get_header(client, content_type='multipart/form-data')
    db.session.commit()
示例#34
0
 def setUp(self):
     self.client = app.test_client()