|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# -*- coding: utf-8 -*- |
|
3
|
|
|
# |
|
4
|
|
|
# Copyright (c) 2016 dotzero <[email protected]> |
|
5
|
|
|
# |
|
6
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy |
|
7
|
|
|
# of this software and associated documentation files (the "Software"), to deal |
|
8
|
|
|
# in the Software without restriction, including without limitation the rights |
|
9
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10
|
|
|
# copies of the Software, and to permit persons to whom the Software is |
|
11
|
|
|
# furnished to do so, subject to the following conditions: |
|
12
|
|
|
# |
|
13
|
|
|
# The above copyright notice and this permission notice shall be included |
|
14
|
|
|
# in all copies or substantial portions of the Software. |
|
15
|
|
|
# |
|
16
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
17
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
18
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
19
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
20
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
21
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
22
|
|
|
# SOFTWARE. |
|
23
|
|
|
|
|
24
|
|
|
"""This module contains a object that represents Tests for TildaProject""" |
|
25
|
|
|
|
|
26
|
|
|
import unittest |
|
27
|
|
|
import sys |
|
28
|
|
|
import tilda |
|
29
|
|
|
from tests.base import BaseTest |
|
30
|
|
|
|
|
31
|
|
|
sys.path.append('.') |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
class TildaProjectTest(BaseTest, unittest.TestCase): |
|
35
|
|
|
"""This object represents Tests for TildaProject.""" |
|
36
|
|
|
|
|
37
|
|
|
def setUp(self): |
|
38
|
|
|
mock_response = self.to_json("""{"status":"FOUND","result":{ |
|
39
|
|
|
"id":"12345", |
|
40
|
|
|
"title":"Blog", |
|
41
|
|
|
"descr":"I am a professional developer", |
|
42
|
|
|
"customdomain":"example.com", |
|
43
|
|
|
"css":[ |
|
44
|
|
|
"http:\/\/tilda.ws\/css\/tilda-grid-3.0.css", |
|
45
|
|
|
"http:\/\/tilda.ws\/project36354\/tilda-blocks-2.5.css" |
|
46
|
|
|
], |
|
47
|
|
|
"js":[ |
|
48
|
|
|
"http:\/\/tilda.ws\/js\/jquery-1.10.2.min.js", |
|
49
|
|
|
"http:\/\/tilda.ws\/js\/tilda-scripts-2.5.js", |
|
50
|
|
|
"http:\/\/tilda.ws\/project36354\/tilda-blocks-2.3.js", |
|
51
|
|
|
"http:\/\/tilda.ws\/js\/bootstrap.min.js" |
|
52
|
|
|
]}}""") |
|
53
|
|
|
|
|
54
|
|
|
self.response = mock_response.get('result') |
|
55
|
|
|
|
|
56
|
|
|
def test_project_init_empty(self): |
|
57
|
|
|
"""Test TildaProject.__init__() method""" |
|
58
|
|
|
print('Testing TildaProject.__init__() - Empty') |
|
59
|
|
|
|
|
60
|
|
|
project = tilda.TildaProject() |
|
61
|
|
|
|
|
62
|
|
|
self.assertEqual(project.id, 0) |
|
63
|
|
|
self.assertEqual(project.title, '') |
|
64
|
|
|
self.assertEqual(project.descr, '') |
|
65
|
|
|
self.assertEqual(project.customdomain, '') |
|
66
|
|
|
self.assertEqual(project.css, list()) |
|
67
|
|
|
self.assertEqual(project.js, list()) |
|
68
|
|
|
self.assertEqual(project.export_csspath, '') |
|
69
|
|
|
self.assertEqual(project.export_jspath, '') |
|
70
|
|
|
self.assertEqual(project.export_imgpath, '') |
|
71
|
|
|
self.assertEqual(project.indexpageid, 0) |
|
72
|
|
|
self.assertEqual(project.images, list()) |
|
73
|
|
|
self.assertEqual(project.htaccess, '') |
|
74
|
|
|
|
|
75
|
|
|
def test_project_init_non_empty(self): |
|
76
|
|
|
"""Test TildaProject.__init__() method""" |
|
77
|
|
|
print('Testing TildaProject.__init__() - Non empty') |
|
78
|
|
|
|
|
79
|
|
|
project = tilda.TildaProject(**self.response) |
|
80
|
|
|
|
|
81
|
|
|
self.assertEqual(project.id, 12345) |
|
82
|
|
|
self.assertEqual(project.title, 'Blog') |
|
83
|
|
|
self.assertEqual(project.descr, 'I am a professional developer') |
|
84
|
|
|
self.assertEqual(project.customdomain, 'example.com') |
|
85
|
|
|
self.assertEqual(len(project.css), 2) |
|
86
|
|
|
self.assertEqual(len(project.js), 4) |
|
87
|
|
|
|
|
88
|
|
|
def test_project_str(self): |
|
89
|
|
|
"""Test TildaProject.__str__() method""" |
|
90
|
|
|
print('Testing TildaProject.__str__()') |
|
91
|
|
|
|
|
92
|
|
|
project = tilda.TildaProject(**self.response) |
|
93
|
|
|
|
|
94
|
|
|
self.assertEqual(str(project), '(12345) Blog') |
|
95
|
|
|
|
|
96
|
|
|
def test_project_repr(self): |
|
97
|
|
|
"""Test TildaProject.__repr__() method""" |
|
98
|
|
|
print('Testing TildaProject.__repr__()') |
|
99
|
|
|
|
|
100
|
|
|
project = tilda.TildaProject(**self.response) |
|
101
|
|
|
|
|
102
|
|
|
self.assertIn('tilda.project.TildaProject', repr(project)) |
|
103
|
|
|
|
|
104
|
|
|
def test_project_to_dict(self): |
|
105
|
|
|
"""Test TildaProject.to_dict() method""" |
|
106
|
|
|
print('Testing TildaProject.to_dict()') |
|
107
|
|
|
|
|
108
|
|
|
project = tilda.TildaProject(**self.response) |
|
109
|
|
|
project_dict = project.to_dict() |
|
110
|
|
|
|
|
111
|
|
|
self.assertTrue(self.is_dict(project_dict)) |
|
112
|
|
|
self.assertEqual(project_dict['id'], int(self.response['id'])) |
|
113
|
|
|
self.assertEqual(project_dict['title'], self.response['title']) |
|
114
|
|
|
self.assertEqual(project_dict['descr'], self.response['descr']) |
|
115
|
|
|
self.assertEqual(project_dict['customdomain'], |
|
116
|
|
|
self.response['customdomain']) |
|
117
|
|
|
self.assertEqual(project_dict['css'], self.response['css']) |
|
118
|
|
|
self.assertEqual(project_dict['js'], self.response['js']) |
|
119
|
|
|
|
|
120
|
|
|
def test_project_to_json(self): |
|
121
|
|
|
"""Test TildaProject.to_json() method""" |
|
122
|
|
|
print('Testing TildaProject.to_json()') |
|
123
|
|
|
|
|
124
|
|
|
project = tilda.TildaProject(**self.response) |
|
125
|
|
|
|
|
126
|
|
|
self.assertTrue(self.is_json(project.to_json())) |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
if __name__ == '__main__': |
|
130
|
|
|
unittest.main() |
|
131
|
|
|
|