forked from OpenZWave/python-openzwave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
95 lines (75 loc) · 2.67 KB
/
Copy pathcommon.py
File metadata and controls
95 lines (75 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
"""Unittests for the pyozwwzb Server.
Credits : https://flask-testing.readthedocs.org/en/latest/
"""
__license__ = """
This file is part of **python-openzwave** project https://github.com/OpenZWave/python-openzwave.
License : GPL(v3)
**python-openzwave** is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
**python-openzwave** is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with python-openzwave. If not, see http://www.gnu.org/licenses.
"""
__author__ = 'Sébastien GALLET aka bibi21000'
__email__ = 'bibi21000@gmail.com'
import sys, os
import time
import logging
import json as mjson
from flask import Flask
from pyozwweb.app import create_app, run_app, stop_all
from tests.common import SLEEP
from tests.common import TestPyZWave
from multiprocessing import Process
class TestServer(Process):
def __init__(self):
"""The constructor"""
Process.__init__(self)
self.socketio = None
self.app = None
self.client = None
self.app, self.socketio = create_app(config_object='pyozwweb.config.TestingConfig')
def run(self):
"""The running method"""
run_app(self.app, self.socketio)
def stop(self):
"""Stop the tread"""
print('got stop')
Process.terminate(self)
time.sleep(2.0)
self.socketio = None
self.app = None
self.client = None
class FlaskTestBase(TestPyZWave):
pass
class FlaskTestCase(FlaskTestBase):
@classmethod
def setUpClass(self):
super(FlaskTestCase, self).setUpClass()
self.testserver = TestServer()
#global socket_server
#socket_server = self.testserver
self.testserver.start()
#app, socketio = create_app(config_object='pyozwweb.config.TestingConfig')
#app.testing = True
#run_app(app, socketio)
self.app = self.testserver.app
self.socketio = self.testserver.socketio
self.client = self.testserver.app.test_client()
time.sleep(7.0)
@classmethod
def tearDownClass(self):
self.testserver.stop()
self.testserver.join()
self.socketio = None
time.sleep(2.0)
self.app = None
self.client = None
self.testserver = None
super(FlaskTestCase, self).tearDownClass()