Exemple #1
0
 def test_calculate(self):
     tester = app.test_client(self)
     response = tester.get('/calculate', content_type='html/text')
     self.assertIn(b'add', response.data)
     self.assertIn(b'subtract', response.data)
     self.assertIn(b'multiply', response.data)
     self.assertIn(b'divide', response.data)
     self.assertEqual(response.status_code, 200)
Exemple #2
0
 def test_editing_snack(self):
     tester = app.test_client(self)
     tester.post('/snacks/1?_method=PATCH',
                 data=dict(name="almond_snickers",
                           kind="almonds_and_chocolate"),
                 follow_redirects=True)
     self.assertEqual(snack_list[0].name, 'almond_snickers')
     self.assertEqual(snack_list[0].kind, 'almonds_and_chocolate')
     self.assertEqual(len(snack_list), 2)
Exemple #3
0
 def test_creating_snack(self):
     tester = app.test_client(self)
     tester.post('/snacks',
                 data=dict(name="hersheys", kind="chocolate"),
                 follow_redirects=True)
     self.assertEqual(snack_list[2].id, 3)
     self.assertEqual(snack_list[2].name, 'hersheys')
     self.assertEqual(snack_list[2].kind, 'chocolate')
     self.assertEqual(len(snack_list), 3)
Exemple #4
0
 def test_results(self):
     tester = app.test_client(self)
     response = tester.get('/results',
                           content_type='html/text',
                           query_string={'keyword': 'the'})
     keyword_count = response.data.count(b'the')
     li_count = response.data.count(b'<li')
     self.assertEqual(response.status_code, 200)
     self.assertGreater(li_count, 0)
     self.assertLessEqual(li_count, keyword_count)
Exemple #5
0
    def test_welcome(self):
        tester = app.test_client(self)
        response = tester.get('/person/bob/20', content_type='html/text')
        self.assertIn(b'bob', response.data)
        self.assertIn(b'20', response.data)

        response = tester.get('/person/bob/20', content_type='html/text')
        self.assertEqual(response.status_code, 200)

        response = tester.get('/person/bob', content_type='html/text')
        self.assertEqual(response.status_code, 404)

        response = tester.get('/person', content_type='html/text')
        self.assertEqual(response.status_code, 404)
    def test_all_in_one(self):
        tester = app.test_client(self)
        response = tester.get('/math/add/2/2', content_type='html/text')
        self.assertIn(b'4', response.data)
        self.assertEqual(response.status_code, 200)

        response = tester.get('/math/subtract/2/2', content_type='html/text')
        self.assertIn(b'0', response.data)
        self.assertEqual(response.status_code, 200)

        response = tester.get('/math/multiply/2/20', content_type='html/text')
        self.assertIn(b'40', response.data)
        self.assertEqual(response.status_code, 200)

        response = tester.get('/math/divide/2/2', content_type='html/text')
        self.assertIn(b'1', response.data)
        self.assertEqual(response.status_code, 200)
Exemple #7
0
    def test_math(self):
        tester = app.test_client(self)
        response = tester.get('/math?num1=10&num2=20&calculation=add',
                              content_type='html/text')
        self.assertIn(b'30', response.data)
        self.assertEqual(response.status_code, 200)

        response = tester.get('/math?num1=10&num2=20&calculation=subtract',
                              content_type='html/text')
        self.assertIn(b'-10', response.data)
        self.assertEqual(response.status_code, 200)

        response = tester.get('/math?num1=10&num2=120&calculation=multiply',
                              content_type='html/text')
        self.assertIn(b'1200', response.data)
        self.assertEqual(response.status_code, 200)

        response = tester.get('/math?num1=20&num2=20&calculation=divide',
                              content_type='html/text')
        self.assertIn(b'1', response.data)
        self.assertEqual(response.status_code, 200)
Exemple #8
0
 def test_deleting_snack(self):
     tester = app.test_client(self)
     tester.post('/snacks/1?_method=DELETE', follow_redirects=True)
     tester.post('/snacks/2?_method=DELETE', follow_redirects=True)
     self.assertEqual(len(snack_list), 0)
Exemple #9
0
 def test_show(self):
     tester = app.test_client(self)
     response = tester.get('/snacks/1/edit', content_type='html/text')
     self.assertEqual(response.status_code, 200)
 def test_welcome(self):
     tester = app.test_client(self)
     response = tester.get('/welcome', content_type='html/text')
     self.assertIn(b'welcome', response.data)
     self.assertEqual(response.status_code, 200)
Exemple #11
0
 def test_index(self):
     tester = app.test_client(self)
     response = tester.get('/', content_type='html/text')
     self.assertIn(b'<form', response.data)
     self.assertEqual(response.status_code, 200)
Exemple #12
0
def application():

    application = app.test_client()
    yield application
 def test_add(self):
     tester = app.test_client(self)
     response = tester.get('/add/2/2', content_type='html/text')
     self.assertIn(b'4', response.data)
     self.assertEqual(response.status_code, 200)
 def test_division(self):
     tester = app.test_client(self)
     response = tester.get('/divide/2/2', content_type='html/text')
     self.assertIn(b'1', response.data)
     self.assertEqual(response.status_code, 200)
 def test_multiply(self):
     tester = app.test_client(self)
     response = tester.get('/multiply/20/2', content_type='html/text')
     self.assertIn(b'40', response.data)
     self.assertEqual(response.status_code, 200)