|
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 TildaPage""" |
|
25
|
|
|
|
|
26
|
|
|
import unittest |
|
27
|
|
|
import sys |
|
28
|
|
|
import tilda |
|
29
|
|
|
from datetime import datetime |
|
30
|
|
|
from tests.base import BaseTest |
|
31
|
|
|
|
|
32
|
|
|
sys.path.append('.') |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
class TildaPageTest(BaseTest, unittest.TestCase): |
|
36
|
|
|
"""This object represents Tests for TildaPage.""" |
|
37
|
|
|
|
|
38
|
|
|
def setUp(self): |
|
39
|
|
|
mock_response = self.to_json("""{"status":"FOUND","result":{ |
|
40
|
|
|
"id":"54321", |
|
41
|
|
|
"projectid":"12345", |
|
42
|
|
|
"title":"Page", |
|
43
|
|
|
"descr":"Blog post", |
|
44
|
|
|
"img":"https:\/\/ucarecdn.com\/covermain.jpg", |
|
45
|
|
|
"featureimg":"http:\/\/ucarecdn.com\/featureimg.jpg", |
|
46
|
|
|
"alias":"post", |
|
47
|
|
|
"date":"2016-03-14 17:59:12", |
|
48
|
|
|
"sort":"30", |
|
49
|
|
|
"published":"1458049840", |
|
50
|
|
|
"filename":"page54321.html", |
|
51
|
|
|
"html":"<html>"}}""") |
|
52
|
|
|
|
|
53
|
|
|
self.response = mock_response.get('result') |
|
54
|
|
|
|
|
55
|
|
|
def test_page_init_empty(self): |
|
56
|
|
|
"""Test TildaPage.__init__() method""" |
|
57
|
|
|
print('Testing TildaPage.__init__() - Empty') |
|
58
|
|
|
|
|
59
|
|
|
page = tilda.TildaPage() |
|
60
|
|
|
|
|
61
|
|
|
self.assertEqual(page.id, 0) |
|
62
|
|
|
self.assertEqual(page.projectid, 0) |
|
63
|
|
|
self.assertEqual(page.title, '') |
|
64
|
|
|
self.assertEqual(page.descr, '') |
|
65
|
|
|
self.assertEqual(page.img, '') |
|
66
|
|
|
self.assertEqual(page.featureimg, '') |
|
67
|
|
|
self.assertEqual(page.alias, '') |
|
68
|
|
|
self.assertEqual(page.date, None) |
|
69
|
|
|
self.assertEqual(page.sort, 0) |
|
70
|
|
|
self.assertEqual(page.published, None) |
|
71
|
|
|
self.assertEqual(page.filename, '') |
|
72
|
|
|
self.assertEqual(page.html, '') |
|
73
|
|
|
self.assertEqual(page.css, list()) |
|
74
|
|
|
self.assertEqual(page.js, list()) |
|
75
|
|
|
self.assertEqual(page.images, list()) |
|
76
|
|
|
|
|
77
|
|
|
def test_page_init_non_empty(self): |
|
78
|
|
|
"""Test TildaPage.__init__() method""" |
|
79
|
|
|
print('Testing TildaPage.__init__() - Non empty') |
|
80
|
|
|
|
|
81
|
|
|
page = tilda.TildaPage(**self.response) |
|
82
|
|
|
|
|
83
|
|
|
self.assertEqual(page.id, 54321) |
|
84
|
|
|
self.assertEqual(page.projectid, 12345) |
|
85
|
|
|
self.assertEqual(page.title, 'Page') |
|
86
|
|
|
self.assertEqual(page.descr, 'Blog post') |
|
87
|
|
|
self.assertEqual(page.img, 'https://ucarecdn.com/covermain.jpg') |
|
88
|
|
|
self.assertEqual(page.featureimg, 'http://ucarecdn.com/featureimg.jpg') |
|
89
|
|
|
self.assertEqual(page.alias, 'post') |
|
90
|
|
|
self.assertTrue(isinstance(page.date, datetime)) |
|
91
|
|
|
self.assertEqual(page.sort, 30) |
|
92
|
|
|
self.assertTrue(isinstance(page.published, datetime)) |
|
93
|
|
|
self.assertEqual(page.filename, 'page54321.html') |
|
94
|
|
|
self.assertEqual(page.html, '<html>') |
|
95
|
|
|
|
|
96
|
|
|
def test_page_str(self): |
|
97
|
|
|
"""Test TildaPage.__str__() method""" |
|
98
|
|
|
print('Testing TildaPage.__str__()') |
|
99
|
|
|
|
|
100
|
|
|
page = tilda.TildaPage(**self.response) |
|
101
|
|
|
|
|
102
|
|
|
self.assertEqual(str(page), '(54321) Page') |
|
103
|
|
|
|
|
104
|
|
|
def test_page_repr(self): |
|
105
|
|
|
"""Test TildaPage.__repr__() method""" |
|
106
|
|
|
print('Testing TildaPage.__repr__()') |
|
107
|
|
|
|
|
108
|
|
|
page = tilda.TildaPage(**self.response) |
|
109
|
|
|
|
|
110
|
|
|
self.assertIn('tilda.page.TildaPage', repr(page)) |
|
111
|
|
|
|
|
112
|
|
|
def test_page_to_dict(self): |
|
113
|
|
|
"""Test TildaPage.to_dict() method""" |
|
114
|
|
|
print('Testing TildaPage.to_dict()') |
|
115
|
|
|
|
|
116
|
|
|
page = tilda.TildaPage(**self.response) |
|
117
|
|
|
page_dict = page.to_dict() |
|
118
|
|
|
|
|
119
|
|
|
self.assertTrue(self.is_dict(page_dict)) |
|
120
|
|
|
self.assertEqual(page_dict['id'], int(self.response['id'])) |
|
121
|
|
|
self.assertEqual(page_dict['projectid'], |
|
122
|
|
|
int(self.response['projectid'])) |
|
123
|
|
|
self.assertEqual(page_dict['title'], self.response['title']) |
|
124
|
|
|
self.assertEqual(page_dict['descr'], self.response['descr']) |
|
125
|
|
|
self.assertEqual(page_dict['img'], self.response['img']) |
|
126
|
|
|
self.assertEqual(page_dict['featureimg'], self.response['featureimg']) |
|
127
|
|
|
self.assertEqual(page_dict['alias'], self.response['alias']) |
|
128
|
|
|
self.assertEqual(page_dict['date'].strftime('%Y-%m-%d %H:%M:%S'), |
|
129
|
|
|
self.response['date']) |
|
130
|
|
|
self.assertEqual(page_dict['sort'], int(self.response['sort'])) |
|
131
|
|
|
self.assertEqual(page_dict['published'].strftime('%s'), |
|
132
|
|
|
self.response['published']) |
|
133
|
|
|
self.assertEqual(page_dict['filename'], self.response['filename']) |
|
134
|
|
|
self.assertEqual(page_dict['html'], self.response['html']) |
|
135
|
|
|
|
|
136
|
|
|
def test_page_to_json(self): |
|
137
|
|
|
"""Test TildaPage.to_json() method""" |
|
138
|
|
|
print('Testing TildaPage.to_json()') |
|
139
|
|
|
|
|
140
|
|
|
page = tilda.TildaPage(**self.response) |
|
141
|
|
|
|
|
142
|
|
|
self.assertTrue(self.is_json(page.to_json())) |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
if __name__ == '__main__': |
|
146
|
|
|
unittest.main() |
|
147
|
|
|
|