comparison test/test_liveserver.py @ 6383:e9760702bf0c

Add live server test to suite. Now the testsuite starts an instance of the roundup tracker. It then uses requests to verify the main page is acessible. At some point this will be extended to use selemium or splinter to drive more extensive end to end testing.
author John Rouillard <rouilj@ieee.org>
date Tue, 20 Apr 2021 14:16:58 -0400
parents
children 66a061e52435
comparison
equal deleted inserted replaced
6382:b35a50d02890 6383:e9760702bf0c
1 import shutil, errno, pytest
2
3 from roundup.cgi.wsgi_handler import RequestDispatcher
4 from .wsgi_liveserver import LiveServerTestCase
5 from . import db_test_base
6
7 try:
8 import requests
9 skip_requests = lambda func, *args, **kwargs: func
10 except ImportError:
11 from .pytest_patcher import mark_class
12 skip_requests = mark_class(pytest.mark.skip(
13 reason='Skipping liveserver tests: requests library not available'))
14
15 @skip_requests
16 class SimpleTest(LiveServerTestCase):
17 port_range = (9001, 9010) # default is (8080, 8090)
18
19 dirname = '_test_instance'
20 backend = 'anydbm'
21
22 @classmethod
23 def setup_class(cls):
24 '''All test in this class use the same roundup instance.
25 This instance persists across all tests.
26 Create the tracker dir here so that it is ready for the
27 create_app() method to be called.
28 '''
29 # tests in this class.
30 # set up and open a tracker
31 cls.instance = db_test_base.setupTracker(cls.dirname, cls.backend)
32
33 # open the database
34 cls.db = cls.instance.open('admin')
35
36 cls.db.commit()
37 cls.db.close()
38
39 @classmethod
40 def teardown_class(cls):
41 '''Close the database and delete the tracker directory
42 now that the app should be exiting.
43 '''
44 if cls.db:
45 cls.db.close()
46 try:
47 shutil.rmtree(cls.dirname)
48 except OSError as error:
49 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
50
51 def create_app(self):
52 '''The wsgi app to start'''
53 return RequestDispatcher(self.dirname)
54
55 def test_start_page(self):
56 """ simple test that verifies that the server can serve a start page.
57 """
58 f = requests.get(self.url_base())
59 self.assertTrue(b'Roundup' in f.content)
60 self.assertTrue(b'Creator' in f.content)

Roundup Issue Tracker: http://roundup-tracker.org/