-
Notifications
You must be signed in to change notification settings - Fork 12
/
tests.py
148 lines (101 loc) · 4.7 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import os
import config
import slides
import unittest
import tempfile
import database
from models import CategoryModel
class SlidesTestCase(unittest.TestCase):
def setUp(self):
slides.app.config['TESTING'] = True
self.app = slides.app.test_client()
database.init_db()
def tearDown(self):
os.unlink("." + config.DATABASE)
def test_index(self):
rv = self.app.get('/')
assert rv.status_code == 200
def test_add_new_category(self):
rv = self.app.post('/addCategory', data=dict(
name='test'), follow_redirects=True)
assert "Category added succefully" in rv.data
def test_add_existing_category(self):
self.app.post('/addCategory', data=dict(
name='test'), follow_redirects=True)
rv = self.app.post('/addCategory', data=dict(
name='test'), follow_redirects=True)
assert "This Categorie already exists !" in rv.data
def test_update_category(self):
self.app.post('/addCategory', data=dict(
name='test'), follow_redirects=True)
c = CategoryModel.query.filter(CategoryModel.name=="test").first()
rv = self.app.post('/updatecategory', data=dict(
id=c.id, title="test2"), follow_redirects=True)
assert "Category updated succefully" in rv.data
@unittest.expectedFailure
def test_update_category_with_existing_name(self):
self.app.post('/addCategory', data=dict(
name='test'), follow_redirects=True)
self.app.post('/addCategory', data=dict(
name='test2'), follow_redirects=True)
c = CategoryModel.query.filter(CategoryModel.name=="test2").first()
rv = self.app.post('/updatecategory', data=dict(
id=c.id, title="test"), follow_redirects=True)
assert "Category updated succefully" in rv.data
def test_update_uncategorised_category(self):
self.app.get('/init')
c = CategoryModel.query.filter(CategoryModel.name=="Uncategorised").first()
rv = self.app.post('/updatecategory', data=dict(
id=c.id, name="test"), follow_redirects=True)
assert "You can't change the name of this category" in rv.data
def test_delete_category(self):
self.app.post('/addCategory', data=dict(
name='test'), follow_redirects=True)
c = CategoryModel.query.filter(CategoryModel.name=="test").first()
rv = self.app.post('/deletecategory', data=dict(
id=c.id), follow_redirects=True)
assert "Category deleted succefully" in rv.data
def test_delete_uncategorised_category(self):
self.app.get('/init')
c = CategoryModel.query.filter(CategoryModel.name=="Uncategorised").first()
rv = self.app.post('/deletecategory', data=dict(
id=c.id, name="test"), follow_redirects=True)
assert "You can't delete this category" in rv.data
@unittest.expectedFailure
def test_add_new_slide_with_valid_url(self):
self.app.post('/addCategory', data=dict(
name='test'), follow_redirects=True)
c = CategoryModel.query.filter(CategoryModel.name=="test").first()
rv = self.app.post('/addSlide', data=dict(
title='Firefox OS App Day Tunisia',
url='https://github.com/moztn/firefoxOSAppDay-Slides',
description='Firefox OS App Day Tunisia Event',
categorie=c.id)
)
print rv.data
assert "Slide added succefully" in rv.data
def test_add_new_slide_with_non_github_url(self):
self.app.post('/addCategory', data=dict(
name='test'), follow_redirects=True)
c = CategoryModel.query.filter(CategoryModel.name=="test").first()
rv = self.app.post('/addSlide', data=dict(
title='Firefox OS App Day Tunisia',
url='https://www.mozilla-tunisia.org/moztn/firefoxOSAppDay-Slides',
description='Firefox OS App Day Tunisia Event',
categorie=c.id)
)
assert "Your slides must be hosted on https://github.com/" in rv.data
@unittest.expectedFailure
def test_add_new_slide_with_non_gh_pages_branch(self):
self.app.post('/addCategory', data=dict(
name='test'), follow_redirects=True)
c = CategoryModel.query.filter(CategoryModel.name=="test").first()
rv = self.app.post('/addSlide', data=dict(
title='Firefox OS App Day Tunisia',
url='https://github.com/moztn/moztnbot',
description='Firefox OS App Day Tunisia Event',
categorie=c.id)
)
assert "You have to create a 'gh-pages' branch" in rv.data
if __name__ == '__main__':
unittest.main(verbosity=2)