Пример #1
0
 def test_getItems(self):
     test = app.test_client(self)
     response = test.get("/getItems")
     status_code = response.status_code
     self.assertEqual(200,
                      status_code,
                      msg="Error occurred retrieving resource")
Пример #2
0
 def test_get_410(self, m):
     m.get('http://data.fixer.io/api/latest', status_code=503)
     response = app.test_client().get('/currency_converter',
                                      data={
                                          'amount': 10,
                                          'input_currency': 'EUR',
                                          'output_currency': 'PLN'
                                      })
     self.assertEqual(response.status_code, 410)
Пример #3
0
 def test_add(self):
     test = app.test_client(self)
     n1 = 10
     n2 = 20
     result = n1 + n2
     response = test.get(f"/add?n1={n1}&n2={n2}")
     data = response.get_data().decode(
         'utf-8'
     )  # Need to decode the string, it is returned as b'' (Bytes)
     self.assertEqual(f"The sum of {n1} and {n2} is: {str(result)}.",
                      data,
                      msg=f"Incorrect Sum, Expected: {str(result)}")
Пример #4
0
 def test_power(self):
     test = app.test_client(self)
     n1 = 2
     n2 = 4
     power = 16
     response = test.get(f"/power?n1={n1}&n2={n2}")
     data = response.get_data().decode(
         'utf-8'
     )  # Need to decode the string, it is returned as b'' (Bytes)
     self.assertEqual(f"{n1} to the power of {n2} is: {str(power)}.",
                      data,
                      msg=f"Incorrect Power, Expected: {str(power)}")
Пример #5
0
 def test_diff(self):
     test = app.test_client(self)
     n1 = 10
     n2 = 20
     result = n1 - n2
     response = test.get(f"/diff?n1={n1}&n2={n2}")
     data = response.get_data().decode(
         'utf-8'
     )  # Need to decode the string, it is returned as b'' (Bytes)
     self.assertEqual(
         f"The difference between {n1} and {n2} is: {str(result)}.",
         data,
         msg=f"Incorrect Difference, Expected: {str(result)}")
Пример #6
0
 def test_get_BAD_REQUESTS(self, m):
     json_text = dumps(
         {
             'success': True, 'base': 'EUR', 'rates':
             {
                 'AED': 4, 'BTC': 0.01, 'CAD': 1.5,\
                 'CNY': 6.25, 'CZK': 25.0, 'EUR': 1, 'GBP': 0.8,\
                 'JPY': 125.5, 'PLN': 5, 'USD': 1.25
             }
         }
     )
     m.get('http://data.fixer.io/api/latest', text=json_text)
     response = app.test_client().get('/currency_converter',
                                      data={
                                          'amount': 10,
                                          'input_currency': 'blelble',
                                          'output_currency': 'PLN'
                                      })
     self.assertEqual(response.status_code, 400)
Пример #7
0
from nose.tools import *
from web_app import app
from gothonweb.planisphere import *

app.config['TESTING'] = True
web = app.test_client()


def test_index():
    rv = web.get('/game')
    assert_in(b"Looks like you bit the dust", rv.data)

    rv = web.get('/', follow_redirects=True)
    inv_data = {"action": "0312"}
    rv = web.post('/game', data=inv_data, follow_redirects=True)
    assert_in(b'Central Corridor', rv.data)

    f_data = {"action": "tell a joke"}
    rv = web.post('/game', data=f_data, follow_redirects=True)
    assert_in(b'Laser Weapon Armory', rv.data)

    s_data = {"action": "0132"}
    rv = web.post('/game', data=s_data, follow_redirects=True)
    assert_in(b'The Bridge', rv.data)

    t_data = {"action": "slowly place the bomb"}
    rv = web.post('/game', data=t_data, follow_redirects=True)
    assert_in(b'Escape Pod', rv.data)

    frt_data = {"action": "*"}
    rv = web.post('/game', data=frt_data, follow_redirects=True)
Пример #8
0
 def test_addMissingParams(self):
     test = app.test_client(self)
     n1 = 10
     response = test.get(f"/add?n1={n1}")
     data = response.status_code
     self.assertEqual(400, data, msg="Expected: 400 Bad Request")
Пример #9
0
 def test_index(self):
     test = app.test_client(self)
     response = test.get("/")
     status_code = response.status_code
     self.assertEqual(200, status_code)
Пример #10
0
 def setUp(self):
     # creates a test client
     self.app = app.test_client()
     # propagate the exceptions to the test client
     self.app.testing = True