-
Notifications
You must be signed in to change notification settings - Fork 0
/
taylor91-TestWCDB1.py
209 lines (189 loc) · 10 KB
/
taylor91-TestWCDB1.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
#from django.test import TestCase
import sys
import StringIO
from django.test.simple import DjangoTestSuiteRunner
from django.http import HttpResponse
from django.conf import settings
from wcdb_ie import xml_reader, xml_etree2mods, xml_mods2etree, xml_etree2xml
from models import People, Crises, Organizations, List_Item
import xml.etree.ElementTree as ET
import unittest
class SimpleTest(unittest.TestCase):
""" def setUp(self):
import MySQLdb
db_connection = MySQLdb.connect(host='z', user='zlozano', passwd='Ml6BaCJP8y')
cursor = db_connection.cursor()
try :
cursor.execute('DROP DATABASE IF EXISTS test_cs373_zlozano')
except Warning as w:
pass
cursor.execute('CREATE DATABASE test_cs373_zlozano')
sql = file('makedb.sql', 'r').read()
cursor.close()
db_connection = MySQLdb.connect(host='z', user='zlozano', passwd='Ml6BaCJP8y', db='test_cs373_zlozano')
cursor = db_connection.cursor()
cursor.execute(sql)
cursor.close()"""
def test_static_page(self):
from views import johnkerry
self.assertTrue(type(johnkerry(None)) == HttpResponse)
self.assertTrue(type(johnkerry(None).content) == str)
self.assertTrue(johnkerry(None).content[0:4] == '{% l')
def test_static_page_many(self):
from views import asean
self.assertTrue(type(asean(None)) == HttpResponse)
self.assertTrue(type(asean(None).content) == str)
from views import bnpparibas
self.assertTrue(type(bnpparibas(None)) == HttpResponse)
self.assertTrue(type(bnpparibas(None).content) == str)
from views import chinamaritime
self.assertTrue(type(chinamaritime(None)) == HttpResponse)
self.assertTrue(type(chinamaritime(None).content) == str)
from views import humantrafficking
self.assertTrue(type(humantrafficking(None)) == HttpResponse)
self.assertTrue(type(humantrafficking(None).content) == str)
from views import johnkerry
self.assertTrue(type(johnkerry(None)) == HttpResponse)
self.assertTrue(type(johnkerry(None).content) == str)
from views import mohamedmorsi
self.assertTrue(type(mohamedmorsi(None)) == HttpResponse)
self.assertTrue(type(mohamedmorsi(None).content) == str)
from views import northkorea
self.assertTrue(type(northkorea(None)) == HttpResponse)
self.assertTrue(type(northkorea(None).content) == str)
from views import polaris
self.assertTrue(type(polaris(None)) == HttpResponse)
self.assertTrue(type(polaris(None).content) == str)
from views import rickymartin
self.assertTrue(type(rickymartin(None)) == HttpResponse)
self.assertTrue(type(rickymartin(None).content) == str)
def test_xml_validate(self) :
xml = StringIO.StringIO('''<WorldCrises><Crisis ID="CRI_EGYPTR" Name="Political Unrest in Egypt">
<Kind>Political Unrest</Kind>
<Date>2013-01-16</Date>
<Time>06:00:00</Time>
<Locations>
<li>Egypt, Africa</li>
</Locations>
<HumanImpact>
<li>Human deaths, political turmoil, economic hardships for the population in general.</li>
</HumanImpact>
<EconomicImpact>
<li>Creates complications for economic reform caused by previous regime fallout. If approved, the loan will come with strict conditions. In order to receive it, the IMF instead of collateral it will require that Egypt implement economic reforms usually in the form of the unpopular austerity measures to cut Egypt's deficit. This translates into a cut in spending on public benefits, social services and development projects. It also comes with an increase in taxes on items such as food, alcohol and cigarettes and petroleum derived products which also include gasoline and cause higher fees for public services including transportation.</li>
</EconomicImpact>
<ResourcesNeeded>
<li>None used other than previous loans to help Egypt of previous political unrest.</li>
</ResourcesNeeded>
<WaysToHelp>
<li>Still pending a $4.8 billion loan from the International Monetary Fund (IMF)</li>
</WaysToHelp>
<Common>
<Images>
<li embed="http://www.csmonitor.com/var/ezflow_site/storage/images/media/content/2012/6-25-12-mohamed-morsi/12947278-1-eng-US/6-25-12-Mohamed-Morsi_full_600.jpg" text="Morsi picture"/>
</Images>
<Videos>
<li embed="http://www.youtube.com/watch?v=K9d_P58qMx4" text="Mohamed Morsi - president elect"/>
</Videos>
</Common>
</Crisis></WorldCrises>''')
emptystr = StringIO.StringIO('this breaks stuff')
self.assertEqual(xml_validate(xml, emptystr), False)
self.assertEqual(xml_validate(emptystr, xml), False)
easyschema = StringIO.StringIO("""<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="WorldCrises">
</xsd:element>
</xsd:schema>""")
self.assertTrue(xml_validate(xml, easyschema))
self.assertEqual(xml_validate(emptystr, easyschema), False)
self.assertTrue(xml_validate(xml, file('Schema.xsd.xml', 'r')))
def test_tables_exist(self) :
self.assertTrue(len(People.objects.all()) >= 0)
self.assertTrue(len(Crises.objects.all()) >= 0)
self.assertTrue(len(Organizations.objects.all()) >= 0)
self.assertTrue(len(List_Item.objects.all()) >= 0)
def test_add_to_models(self) :
xml = StringIO.StringIO('''<WorldCrises><Crisis ID="CRI_EGYPTR" Name="Political Unrest in Egypt">
<Kind>Political Unrest</Kind>
<Date>2013-01-16</Date>
<Time>06:00:00</Time>
<Locations>
<li>Egypt, Africa</li>
</Locations>
<HumanImpact>
<li>Human deaths, political turmoil, economic hardships for the population in general.</li>
</HumanImpact>
<EconomicImpact>
<li>Creates complications for economic reform caused by previous regime fallout. If approved, the loan will come with strict conditions. In order to receive it, the IMF instead of collateral it will require that Egypt implement economic reforms usually in the form of the unpopular austerity measures to cut Egypt's deficit. This translates into a cut in spending on public benefits, social services and development projects. It also comes with an increase in taxes on items such as food, alcohol and cigarettes and petroleum derived products which also include gasoline and cause higher fees for public services including transportation.</li>
</EconomicImpact>
<ResourcesNeeded>
<li>None used other than previous loans to help Egypt of previous political unrest.</li>
</ResourcesNeeded>
<WaysToHelp>
<li>Still pending a $4.8 billion loan from the International Monetary Fund (IMF)</li>
</WaysToHelp>
<Common>
<Images>
<li embed="http://www.csmonitor.com/var/ezflow_site/storage/images/media/content/2012/6-25-12-mohamed-morsi/12947278-1-eng-US/6-25-12-Mohamed-Morsi_full_600.jpg" text="Morsi picture"/>
</Images>
<Videos>
<li embed="http://www.youtube.com/watch?v=K9d_P58qMx4" text="Mohamed Morsi - president elect"/>
</Videos>
</Common>
</Crisis></WorldCrises>''')
xml_etree2mods(xml_reader(xml, file('Schema.xsd.xml', 'r')).getroot())
self.assertTrue(len(Crises.objects.all()) == 1)
self.assertEqual(Crises.objects.get(idref='CRI_EGYPTR').kind, 'Political Unrest')
self.assertEqual(List_Item.objects.get(idref='CRI_EGYPTR',list_type='Locations').body, 'Egypt, Africa')
def test_get_from_models(self):
xml = StringIO.StringIO('''<WorldCrises><Crisis ID="CRI_EGYPTR" Name="Political Unrest in Egypt">
<Kind>Political Unrest</Kind>
<Date>2013-01-16</Date>
<Time>06:00:00</Time>
<Locations>
<li>Egypt, Africa</li>
</Locations>
<HumanImpact>
<li>Human deaths, political turmoil, economic hardships for the population in general.</li>
</HumanImpact>
<EconomicImpact>
<li>Creates complications for economic reform caused by previous regime fallout. If approved, the loan will come with strict conditions. In order to receive it, the IMF instead of collateral it will require that Egypt implement economic reforms usually in the form of the unpopular austerity measures to cut Egypt's deficit. This translates into a cut in spending on public benefits, social services and development projects. It also comes with an increase in taxes on items such as food, alcohol and cigarettes and petroleum derived products which also include gasoline and cause higher fees for public services including transportation.</li>
</EconomicImpact>
<ResourcesNeeded>
<li>None used other than previous loans to help Egypt of previous political unrest.</li>
</ResourcesNeeded>
<WaysToHelp>
<li>Still pending a $4.8 billion loan from the International Monetary Fund (IMF)</li>
</WaysToHelp>
<Common>
<Images>
<li embed="http://www.csmonitor.com/var/ezflow_site/storage/images/media/content/2012/6-25-12-mohamed-morsi/12947278-1-eng-US/6-25-12-Mohamed-Morsi_full_600.jpg" text="Morsi picture"/>
</Images>
<Videos>
<li embed="http://www.youtube.com/watch?v=K9d_P58qMx4" text="Mohamed Morsi - president elect"/>
</Videos>
</Common>
</Crisis></WorldCrises>''')
xml_etree2mods(xml_reader(xml, file('Schema.xsd.xml', 'r')).getroot())
et = xml_mods2etree()
self.assertEqual(type(et), type(ET.ElementTree('')))
self.assertEqual(et.getroot().tag, 'WorldCrises')
self.assertEqual(et.getroot()[0].tag, 'Crisis')
self.assertEqual(len(et.getroot()), 1)
etstring = xml_etree2xml(et)
def do_test():
return 'nope'
settings.RUNNING_OFF_TEST_DB = True
result = StringIO.StringIO('')
suite = unittest.TestLoader().loadTestsFromTestCase(SimpleTest)
unittest.TextTestRunner(stream=result,verbosity=0).run(suite)
settings.RUNNING_OFF_TEST_DB = False
import MySQLdb
db_connection = MySQLdb.connect(host='z', user='zlozano', passwd='Ml6BaCJP8y')
cursor = db_connection.cursor()
cursor.execute('DROP DATABASE IF EXISTS test_cs373_zlozano')
return result.getvalue()