|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# |
|
3
|
|
|
# Copyright (c) 2016 dotzero <[email protected]> |
|
4
|
|
|
# |
|
5
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy |
|
6
|
|
|
# of this software and associated documentation files (the "Software"), to deal |
|
7
|
|
|
# in the Software without restriction, including without limitation the rights |
|
8
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9
|
|
|
# copies of the Software, and to permit persons to whom the Software is |
|
10
|
|
|
# furnished to do so, subject to the following conditions: |
|
11
|
|
|
# |
|
12
|
|
|
# The above copyright notice and this permission notice shall be included |
|
13
|
|
|
# in all copies or substantial portions of the Software. |
|
14
|
|
|
# |
|
15
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
16
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
17
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
18
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
19
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
20
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
21
|
|
|
# SOFTWARE. |
|
22
|
|
|
|
|
23
|
|
|
import os |
|
24
|
|
|
import sys |
|
25
|
|
|
import json |
|
26
|
|
|
import tilda |
|
27
|
|
|
|
|
28
|
|
|
sys.path.append('.') |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
class BaseTest(object): |
|
32
|
|
|
"""This object represents a Base test and its sets of functions.""" |
|
33
|
|
|
|
|
34
|
|
|
def __init__(self, *args, **kwargs): |
|
35
|
|
|
super(BaseTest, self).__init__(*args, **kwargs) |
|
36
|
|
|
|
|
37
|
|
|
self._client = tilda.Client( |
|
38
|
|
|
public=os.environ.get('PUBLICKEY'), |
|
39
|
|
|
secret=os.environ.get('SECRETKEY') |
|
40
|
|
|
) |
|
41
|
|
|
|
|
42
|
|
|
@staticmethod |
|
43
|
|
|
def is_json(string): |
|
44
|
|
|
try: |
|
45
|
|
|
json.loads(string) |
|
46
|
|
|
except ValueError: |
|
47
|
|
|
return False |
|
48
|
|
|
|
|
49
|
|
|
return True |
|
50
|
|
|
|
|
51
|
|
|
@staticmethod |
|
52
|
|
|
def is_dict(dictionary): |
|
53
|
|
|
if isinstance(dictionary, dict): |
|
54
|
|
|
return True |
|
55
|
|
|
|
|
56
|
|
|
return False |
|
57
|
|
|
|
|
58
|
|
|
@staticmethod |
|
59
|
|
|
def to_json(string): |
|
60
|
|
|
try: |
|
61
|
|
|
data = json.loads(string) |
|
62
|
|
|
except ValueError: |
|
63
|
|
|
return False |
|
64
|
|
|
|
|
65
|
|
|
return data |
|
66
|
|
|
|