forked from themagpimag/magpi-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
125 lines (116 loc) · 4.1 KB
/
tests.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import app
import mock
import json
from nose.tools import assert_equal
from app.models.issue import Issue
from app.models.news import News
class TestMagpiApi():
def setUp(self):
self.app = app.app.test_client()
def test_issue_conversion_from_original(self):
old_issue = {
"id":848,
"title":"20",
"date":"February 3, 2014",
"url":"http:\/\/www.themagpi.com\/issue\/issue-20\/",
"issuu":"issue20final",
"pdf":"http:\/\/www.themagpi.com\/issue\/issue-20\/pdf",
"cover":"http:\/\/www.themagpi.com\/assets\/20.jpg",
"editorial":"Welcome"
}
expected = {
"id": 20,
"id_issuu":"issue20final",
"pdf_url": "http:\/\/www.themagpi.com\/issue\/issue-20\/pdf",
"image_url": "http:\/\/www.themagpi.com\/assets\/20.jpg",
"date": "February 3, 2014",
"content": "Welcome",
}
issue = Issue()
issue.fill_from_old(old_issue)
assert_equal(issue.maximize(), expected)
def test_news_conversion_from_original(self):
old_news = {
"title": "Title",
"published" : "Tue, 04 Feb 2014 12:29:32 PST",
"summary" : "My summary",
}
expected = {
"title": "Title",
"date" : "2014-02-04 12:29:32",
"content" : "My summary",
}
news = News()
news.fill_from_old(old_news)
assert_equal(news.maximize(), expected)
def test_minimize_issue(self):
expected = {
"id": 19,
"pdf_url": "https://issuee",
"image_url": "https://issuee.jpg",
"date": "Feb 2013",
}
issue = Issue()
issue.id = 19
issue.date = "Feb 2013"
issue.pdf_url = "https://issuee"
issue.image_url = "https://issuee.jpg"
assert_equal(issue.minimize(), expected)
def test_maximize_issue(self):
expected = {
"id": 19,
"id_issuu":"issuu19final",
"pdf_url": "https://issuee",
"image_url": "https://issuee.jpg",
"date": "Feb 2013",
"content": "Bla Bla Bla content"
}
issue = Issue()
issue.id = 19
issue.id_issuu = "issuu19final"
issue.date = "Feb 2013"
issue.pdf_url = "https://issuee"
issue.image_url = "https://issuee.jpg"
issue.content = "Bla Bla Bla content"
assert_equal(issue.maximize(), expected)
@mock.patch('app.views.get_issues_list_from_db')
def test_get_list_issues(self, mock_get_issues_list_from_db):
expected = {'issues':[{
"id": 18,
"pdf_url": "https://issuee",
"date": "Jan 2013",
},{
"id": 19,
"pdf_url": "https://issuee",
"date": "Feb 2013",
}]}
mock_get_issues_list_from_db.return_value = expected
rv = self.app.get('/issues')
mock_get_issues_list_from_db.assert_called_once()
assert_equal(json.loads(rv.data), expected)
@mock.patch('app.views.get_issue_from_db')
def test_get_issue(self, mock_get_issue_from_db):
expected = {
"id": 19,
"pdf_url": "https://issuee",
"date": "Feb 2013",
}
mock_get_issue_from_db.return_value = expected
rv = self.app.get('/issues/19')
mock_get_issue_from_db.assert_called_once_with(19)
assert_equal(json.loads(rv.data), expected)
@mock.patch('app.views.get_news_list_from_db')
def test_get_list_news(self, mock_get_news_list_from_db):
expected = {'news':[{
"date": "25 Feb 2011",
"title": "MagPi 20 released",
"content": "Bla bla bla",
},{
"date": "28 Feb 2011",
"title": "MagPi 21 released",
"content": "Bla bla bla",
}]}
mock_get_news_list_from_db.return_value = expected
rv = self.app.get('/news')
mock_get_news_list_from_db.assert_called_once()
assert_equal(json.loads(rv.data), expected)