lodgeit/tests/__init__.py
Clark Boylan 9e2d54bb5a Modernize test suite
This modernizes the lodgeit testsuite to use stestr instead of nose. The
primary reason for this is nose is not python3.10 compatible and we
would like to use newer python with lodgeit.

Change-Id: I8ae480d22bbef0258afc9d6ffd6cd820993430a1
2022-11-10 10:30:15 -08:00

36 lines
909 B
Python

import unittest
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse
from lodgeit.application import db, make_app
from lodgeit.models import Paste
from json import loads
def is_json(response):
"""True if the response is JSON and the HTTP status was 200."""
return (response.status_code == 200 and
response.headers.get('Content-Type', '') == 'application/json')
def json(response):
"""The response parsed as JSON.
No attempt is made to ensure the response is valid or even looks
like JSON before parsing.
"""
return loads(response.data)
class BaseTestCase(unittest.TestCase):
def setUp(self):
self.client = Client(
make_app('sqlite://', 'NONE', False, True), BaseResponse)
def teardown(self):
Paste.query.delete()
db.session.commit()
db.session.remove()
super().teardown()