35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from unittest import TestCase
|
|
from flask import Flask
|
|
from flask.testing import FlaskClient
|
|
from werkzeug.test import TestResponse
|
|
from rfcartography import create_app
|
|
|
|
|
|
class TestErrorHandling(TestCase):
|
|
def setUp(self):
|
|
"""create an app object for testing purposes"""
|
|
self.app:Flask = create_app()
|
|
self.app.config.update({"TESTING": True})
|
|
return
|
|
|
|
def test_400(self):
|
|
"""testing handling of malformed requests"""
|
|
client: FlaskClient = self.app.test_client()
|
|
response: TestResponse = client.get('/map?type=foo&num=bar')
|
|
self.assertEqual(response.status, '400 BAD REQUEST')
|
|
return
|
|
|
|
def test_404(self):
|
|
"""testing handling of requests for non-existing ressources"""
|
|
client: FlaskClient = self.app.test_client()
|
|
response: TestResponse = client.get('/foobar')
|
|
self.assertEqual(response.status, '404 NOT FOUND')
|
|
return
|
|
|
|
def test_405(self):
|
|
"""testing handling of invalid request methods"""
|
|
client: FlaskClient = self.app.test_client()
|
|
response: TestResponse = client.post('/')
|
|
self.assertEqual(response.status, '405 METHOD NOT ALLOWED')
|
|
return
|