def test_retrieve_non_existent(self): """ Test GET on non existing shortened URL """ url = "nonexistenttinyurl" tester = app.test_client(self) response = tester.get('/' + url, content_type='html/text') # Should return 404 not found self.assertEqual(response.status_code, 404)
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False self.app = app.test_client() self.assertEqual(app.debug, False)
def test_retrieve_extant(self): """ Fetch an existing URL """ existing_url = db.session.query(Url).first() tester = app.test_client(self) response = tester.get('/' + existing_url.shortened, content_type='html/text') # Should return 302 moved permanently after finding existing url self.assertEqual(response.status_code, 302)
def test_play_returns_correct_result(self): response = app.test_client().post('/play', data=json.dumps({"player": 1}), content_type="application/json") self.assertEqual(response.status_code, 200) self.assertIsNotNone(response.json['computer']) self.assertIsNotNone(response.json['player']) self.assertIsNotNone(response.json['results'])
def test_schedule_route(self): #json.JSONEncoder.default = lambda self,obj: (obj.isoformat() if isinstance(obj, datetime.datetime) else None) with app.test_client() as c: response = c.get('/schedule') self.assertEqual(response.status_code, 200) print("response", response) body = json.loads(response.data) self.assertNotEqual(body, None) for k, v in body.items(): self.assertEqual(v, 'updated' or 'old')
def test_play_throws_400_when_move_is_invalid(self): response = app.test_client().post('/play', data=json.dumps({"player": 3823}), content_type="application/json") self.assertEqual(response.status_code, 400)
def test_play_throws_400_when_move_is_missing(self): response = app.test_client().post('/play') self.assertEqual(response.status_code, 400)
def test_get_choice(self): response = app.test_client().get('/choice') self.assertEqual(response.status_code, 200) self.assertIsNotNone(response.json['id']) self.assertIsNotNone(response.json['name'])
def test_index_content(self): tester = app.test_client(self) response = tester.get('/orders', content_type="html/text") self.assertEqual(response.content_type, "application/json")
def test_schedule_route_with_empty_post(self): with app.test_client() as c: response = c.post('/schedule', data=json.dumps(dict()), content_type='application/json') self.assertEqual(response.status_code, 400)
def test_result_route(self): with app.test_client() as c: response = c.get('/result') self.assertEqual(response.status_code, 405 or 404)
def new_user(step): with app.test_client() as client: lettuce.world.client = client
def test_index(self): tester = app.test_client(self) response = tester.get('/orders', content_type="html/text") self.assertEqual(response.status_code, 200)
def test_deliveries(self): tester = app.test_client(self) response = tester.get('/order_items', content_type="html/text") self.assertTrue(b'deliveries' in response.data)
def test_redirect(self): """ Test general redirect on /shorten """ tester = app.test_client(self) response = tester.get('/shorten', content_type='html/text') # Should return 301 moved permanently self.assertEqual(response.status_code, 301)
def test_unknown_route(self): with app.test_client() as c: response = c.get('/some/path/that/exists') self.assertEqual(response.status_code, 404)
def test_get_choices(self): response = app.test_client().get('/choices') self.assertEqual(response.status_code, 200) self.assertEqual(len(response.json), 5)
def test_index(self): """ Test getting the home page """ tester = app.test_client(self) response = tester.get('/', content_type='html/text') self.assertEqual(response.status_code, 200)
async def client() -> quart.app.QuartClient: app_for_testing.config['TESTING'] = True yield app_for_testing.test_client()