/
ajw2232-TestWCDB3.py
679 lines (578 loc) · 30.1 KB
/
ajw2232-TestWCDB3.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 04 22:11:29 2013
@author: TechKnuckle Support
"""
import StringIO
import unittest
import _mysql
from WCDB4 import *
class TestWCDB2 (unittest.TestCase) :
#----
# login
#----
def test_login_1 (self) :
c = _mysql.connect(
host = "z",
user = "coe78",
passwd = "Oxt3emCwAR",
db = "cs327e_coe78")
self.assert_(str(type(c)) == "<type '_mysql.connection'>")
def test_login_2 (self) :
c = _mysql.connect(
host = "z",
user = "jstevens",
passwd = "1JdQHwNNzr",
db = "cs327e_jstevens")
self.assert_(str(type(c)) == "<type '_mysql.connection'>")
def test_login_3 (self) :
c = login()
self.assert_(str(type(c)) == "<type '_mysql.connection'>")
#------
# query
#------
def test_query_1 (self) :
c = login()
t = query(c, "DROP TABLE IF EXISTS Test1;")
x = query(c, """
create table Test1(
name text);
""")
fill_tables('Test1', [{'name': "Sally"}, {'name': "Tom"}], c)
t = query(c, "SELECT name FROM Test1;")
self.assert_(t) == (('Sally',),('Tom',),)
def test_query_2 (self) :
c = login()
t = query(c, "DROP TABLE IF EXISTS Test2;")
x = query(c, """
create table Test2(
animal text,
sound text);
""")
fill_tables('Test2', [{'animal': "horse", 'sound': "neigh"}, {'sound': "quack", 'animal': "duck"}], c)
t = query( c, "SELECT animal, sound FROM Test2")
self.assert_(t) == (('horse', 'neigh',),('duck', 'quack',),)
def test_query_3 (self) :
c = login()
t = query(c, "DROP TABLE IF EXISTS Test3;")
x = query(c, """
create table Test3(
furniture text,
color text,
usefulness int);
""")
fill_tables('Test3', [{'furniture': "table", 'color': "white", 'usefulness': '8'} ,\
{'color': "purple", 'usefulness': '9', 'furniture': "couch"},\
{'usefulness': '1', 'furniture': "vase", 'color': "blue"}], c)
t = query( c, "SELECT furniture, color, usefulness FROM Test3")
self.assert_(t)== (('table', 'white', '8',),('couch', 'purple', '9',),('vase', 'blue', '1',),)
# ----
# read
# ----
def test_read_1 (self):
r = StringIO.StringIO("Test String")
a = [""]
p= WCDB_read(r, a)
self.assert_(a[0] == "Test String")
self.assert_(p == True)
def test_read_2 (self):
r = StringIO.StringIO("Test String\n Second Line")
a = [""]
p= WCDB_read(r, a)
self.assert_(p == True)
self.assert_(a[0] == "Test String\n")
def test_read_3 (self):
r = StringIO.StringIO("")
a = [""]
p= WCDB_read(r, a)
self.assert_(p == False)
self.assert_(a[0] == "")
#------------
# fill_tables
#------------
def test_fill_tables1 (self):
c = login()
x = query(c, "DROP TABLE IF EXISTS Test;")
t = query(c, """
create table Test(
name text,
age int);
""")
info = [{'name': "Joseph Stevens", 'age': '12'}, {'name': "Annie Wu", 'age':'14'}]
fill_tables('Test', info, c)
sel = query(c, "SELECT name, age FROM Test")
self.assert_(sel) == (('Joseph Stevens', '12'),('Annie Wu', '14'),)
def test_fill_tables2 (self):
c = login()
x = query(c, "DROP TABLE IF EXISTS Test;")
t = query(c, """
create table Test(
name text,
age int);
""")
info = [{'name': "Joseph Stevens", 'age': '12'}, {'name': "Annie Wu", 'age':'14'}, {'age':'100', 'name':"Isaiah"}]
fill_tables('Test', info, c)
sel = query(c, "SELECT name, age FROM Test")
self.assert_(sel) == (('Joseph Stevens', '12',),('Annie Wu', '14',),('Isaiah', '100',),)
def test_fill_tables3 (self):
c = login()
x = query(c, "DROP TABLE IF EXISTS Test;")
t = query(c, """
create table Test(
name text,
age int);
""")
info = [{'age': '12', 'name': "Joseph Stevens"}]
fill_tables('Test', info, c)
sel = query(c, "SELECT name, age FROM Test")
self.assert_(sel) == (('Joseph Stevens', '12',),)
#-------------
# create_table
#-------------
def test_create_table1 (self):
c = create_table()
t = query(c, "SHOW TABLES like 'Crisis';")
self.assert_(t) == (('Crisis',),)
def test_create_table2 (self):
c = create_table()
t = query(c, "SHOW TABLES like 'Organization';")
self.assert_(t) != (('Persons',),)
def test_create_table3 (self):
c = create_table()
t = query(c, "SHOW TABLES like 'HelloWorld';")
self.assert_(str(t)) == "()"
## #----------------------
## # generate_dictionaries
## #----------------------
import unittest
import xml.etree.cElementTree as et
from WCDB2 import generate_dictionaries
xml_file = """
<WorldCrises>
<Crisis crisisIdent = "E2001">
<Name> Syrian Civil War </Name>
<Kind crisisKindIdent="FC" />
<Location>
<Locality> Houston </Locality>
<Region> TX </Region>
<Country> United States </Country>
</Location>
<StartDateTime>
<Date> 2001-08-14 </Date>
</StartDateTime>
<HumanImpact>
<Type> Financial Loss </Type>
<Number> 60000000000 </Number>
</HumanImpact>
<EconomicImpact> Greatest stock value loss in peaceful times and the largest bankruptcy in American history. </EconomicImpact>
<ExternalResources>
<ImageURL>http://rememberinghistory.files.wordpress.com/2012/11/enron_logo.jpg%3Fw%3D610 </ImageURL>
<VideoURL>http://www.youtube.com/watch?v=QS5aosxUfvY</VideoURL>
<MapURL>https://maps.google.com/maps?hl=enampq=1400+smith+street+houston+77002ampbav=on.2,or.r_gc.r_pw.r_cp.r_qf.ampbvm=bv.43287494,d.b2Iampbiw=640ampbih=679ampum=1ampie=UTF-8ampsa=Namptab=wl </MapURL>
</ExternalResources>
<RelatedPersons>
<RelatedPerson personIdent="KLay" />
<RelatedPerson personIdent="AGreenspan" />
</RelatedPersons>
<RelatedOrganizations>
<RelatedOrganization organizationIdent = "SEC" />
</RelatedOrganizations>
</Crisis>
<Organization organizationIdent="USDA">
<Name>United States Department of Agriculture</Name>
<Kind organizationKindIdent="AD"/>
<Location>
<Locality>Washington</Locality>
<Region>D.C.</Region>
<Country>United States</Country>
</Location>
<History>On May 15, 1862, Abraham Lincoln signed into law the Agricultural Act that established the U.S. Department of Agriculture. Since then, the Department has had a rich and varied history. The resources below explore that history, along with the history and organization of USDA's associated agencies and staff offices.</History>
<ContactInfo>
<Telephone>202 720 2791</Telephone>
<Fax></Fax>
<Email></Email>
<PostalAddress>
<StreetAddress>1400 Independence Ave., S.W.</StreetAddress>
<Locality>Washington</Locality>
<Region>D.C.</Region>
<PostalCode>20250</PostalCode>
<Country>United States</Country>
</PostalAddress>
</ContactInfo>
<ExternalResources>
<ImageURL>https://www.google.com/search?hl=enamprlz=1C2DVCR_enUS407US456ampq=USDA+imagesampbav=on.2,or.r_gc.r_pw.r_qf.ampbvm=bv.43287494,d.b2Iampbiw=1241ampbih=584ampum=1ampie=UTF-8amptbm=ischampsource=ogampsa=Namptab=wiampei=w_M3UfOvN4rA2AXRtoDYBQ#imgrc=3587T5k4YZYdfM%3A%3BDip-rsLNM2aALM%3Bhttp%253A%252F%252Fionenewsone.files.wordpress.com%252F2011%252F05%252Fusda_logo_rev.gif%3Bhttp%253A%252F%252Fnewsone.com%252F1227425%252Fusda-civil-rights-shirley-sherrod%252F%3B1233%3B850; </ImageURL>
<VideoURL>http://video.foxbusiness.com/v/2174388754001/usda-under-fire-for-controversial-cultural-sensitivity-training/; </VideoURL>
<MapURL>https://maps.google.com/maps?hl=enampq=1400+Independence+Ave.,+S.W.ampie=UTF-8amphq=amphnear=0x89b7b79fa4334315:0xfb36514e8557abaf,1400+Independence+Ave+SW,+Washington,+DC+20024ampgl=usampei=ePY3UeLYCqOU2wWR4IGoCgampved=0CDMQ8gEwAQ; </MapURL>
<SocialNetworkURL>http://www.facebook.com/pages/USDA/106119542761892?fref=ts</SocialNetworkURL>
</ExternalResources>
<RelatedCrises>
<RelatedCrisis crisisIdent="CE1970"></RelatedCrisis>
</RelatedCrises>
<RelatedPersons>
<RelatedPerson personIdent="GWBush"></RelatedPerson>
<RelatedPerson personIdent="BHObama"></RelatedPerson>
<RelatedPerson personIdent="CHardin"></RelatedPerson>
</RelatedPersons>
</Organization>
<Person personIdent="FDRoosevelt">
<Name>
<FirstName>Franklin</FirstName>
<MiddleName>Delano</MiddleName>
<LastName>Roosevelt</LastName>
<Suffix></Suffix>
</Name>
<Kind personKindIdent="PR"/>
<Location>
<Locality>Hyde Park</Locality>
<Region>New York</Region>
<Country>United States</Country>
</Location>
<ExternalResources>
<ImageURL>http://media.npr.org/assets/img/2012/12/18/ap07021209188_wide-5c891c581ba4583ae9dd3c2f9e16e95121c37d12-s6-c10.jpg </ImageURL>
<VideoURL>http://www.history.com/topics/franklin-d-roosevelt/videos#fdr-a-voice-of-hope </VideoURL>
</ExternalResources>
<RelatedCrises>
<RelatedCrisis crisisIdent="GD1929"></RelatedCrisis>
<RelatedCrisis crisisIdent="WWII1939"></RelatedCrisis>
</RelatedCrises>
<RelatedOrganizations>
<RelatedOrganization organizationIdent="FDIC"></RelatedOrganization>
<RelatedOrganization organizationIdent="FR"></RelatedOrganization>
</RelatedOrganizations>
</Person>
<CrisisKind crisisKindIdent = "EC">
<Name> Economic Crisis </Name>
<Description> Crisis that significantly alters and threatens the economic state of the region. </Description>
</CrisisKind>
<CrisisKind crisisKindIdent = "FC">
<Name> Financial Crisis </Name>
<Description> Crisis that results in a significant loss of money. </Description>
</CrisisKind>
<CrisisKind crisisKindIdent = "MC">
<Name> Military Crisis </Name>
<Description> Crisis that requires military involvement, often war. </Description>
</CrisisKind>
<CrisisKind crisisKindIdent = "E">
<Name> Epidemic </Name>
<Description> Crisis that results in widespread disease and sickness. </Description>
</CrisisKind>
<OrganizationKind organizationKindIdent="AD">
<Name>Agricultural Department</Name>
<Description>Responsible for developing and executing U.S. federal government policy on farming, agriculture, forestry, and food.</Description>
</OrganizationKind>
<OrganizationKind organizationKindIdent="NS">
<Name>National Security</Name>
<Description>Maintain the survival of the state through the use of economic power, diplomacy, power projection and political power.</Description>
</OrganizationKind>
<OrganizationKind organizationKindIdent="IC">
<Name>Insurance Corporation</Name>
<Description>It provides deposit insurance guaranteeing the safety of a depositor's accounts.</Description>
</OrganizationKind>
<OrganizationKind organizationKindIdent="CB">
<Name>Central Bank</Name>
<Description>Is a public institution that manages a state's currency, money supply, and interest rates. Central banks also usually oversee the commercial banking system of their respective countries.</Description>
</OrganizationKind>
<OrganizationKind organizationKindIdent="MA">
<Name>Military Alliance</Name>
<Description>A security arrangement, regional or global, in which each state in the system accepts that the security of one is the concern of all, and agrees to join in a collective response to threats to, and breaches of, the peace.</Description>
</OrganizationKind>
<OrganizationKind organizationKindIdent="IB">
<Name>Investment Bank</Name>
<Description>Is a financial institution that assists individuals, corporations, and governments in raising capital by underwriting and/or acting as the client's agent in the issuance of securities.</Description>
</OrganizationKind>
<OrganizationKind organizationKindIdent="TO">
<Name>Terrorist Organization</Name>
<Description>A political movement that uses terror as a weapon to achieve its goals.</Description>
</OrganizationKind>
<PersonKind personKindIdent="PR">
<Name>President</Name>
<Description>Is a leader of an organization, company, community, club, trade union, university, country, a division or part of any of these, or, more generally, anything else.</Description>
</PersonKind>
<PersonKind personKindIdent="TL">
<Name>Terrorist Leader</Name>
<Description>A leader of a group who uses or advocates terrorism.</Description>
</PersonKind>
<PersonKind personKindIdent="FRC">
<Name>Federal Reserve Chairman</Name>
<Description>Is the head of the central banking system of the United States.</Description>
</PersonKind>
<PersonKind personKindIdent="BM">
<Name>Businessman</Name>
<Description>Is someone involved in a particular undertaking of activities, commercial or industrial, for the purpose of generating revenue from a combination of human, financial, and physical capital.</Description>
</PersonKind>
<PersonKind personKindIdent="SA">
<Name>Secretary of Agriculture</Name>
<Description>Is the head of the United States Department of Agriculture.</Description>
</PersonKind>
</WorldCrises>
"""
xml_file2="""
<WorldCrises>
<Crisis crisisIdent = "c2">
<Name>name2</Name>
<Kind crisisKindIdent = "ck2" />
<Location>
<Locality>locality2</Locality>
<Region>region2</Region>
<Country>country2</Country>
</Location>
<StartDateTime>
<Date>2222-02-02</Date>
</StartDateTime>
<HumanImpact>
<Type>type2</Type>
<Number>2222222222</Number>
</HumanImpact>
<EconomicImpact>economicimpact2</EconomicImpact>
<ExternalResources>
<ImageURL>http://22.com</ImageURL>
<VideoURL>http://www.222.com</VideoURL>
<MapURL>https://www.222222.org</MapURL>
</ExternalResources>
<RelatedPersons>
<RelatedPerson personIdent = "p2" />
</RelatedPersons>
<RelatedOrganizations>
<RelatedOrganization organizationIdent = "o2" />
</RelatedOrganizations>
</Crisis>
<Organization organizationIdent="o2">
<Name>name2</Name>
<Kind organizationKindIdent="ok2"/>
<Location>
<Locality>locality2</Locality>
<Region>region2</Region>
<Country>country2</Country>
</Location>
<History>history2</History>
<ContactInfo>
<Telephone/>
<Fax/>
<Email/>
<PostalAddress>
<StreetAddress/>
<Locality>locality2</Locality>
<Region>region2</Region>
<PostalCode>22222</PostalCode>
<Country>country2</Country>
</PostalAddress>
</ContactInfo>
<ExternalResources>
<ImageURL>https://22.2222.edu</ImageURL>
</ExternalResources>
<RelatedCrises>
<RelatedCrisis crisisIdent="c2"></RelatedCrisis>
</RelatedCrises>
<RelatedPersons>
<RelatedPerson personIdent="p2"></RelatedPerson>
</RelatedPersons>
</Organization>
<Person personIdent="p2">
<Name>
<FirstName>firstname2</FirstName>
<MiddleName>middlename2</MiddleName>
<LastName>lastname2</LastName>
</Name>
<Kind personKindIdent="pk2"/>
<Location>
<Locality>locality2</Locality>
<Region>region2</Region>
<Country>unitedstates2</Country>
</Location>
<ExternalResources>
<ImageURL>http://22.222.org/22/222/2/22/2/2222/22.jpg</ImageURL>
<VideoURL>http://2.com</VideoURL>
</ExternalResources>
<RelatedCrises>
<RelatedCrisis crisisIdent="c2"></RelatedCrisis>
</RelatedCrises>
<RelatedOrganizations>
<RelatedOrganization organizationIdent="o2"></RelatedOrganization>
</RelatedOrganizations>
</Person>
<CrisisKind crisisKindIdent = "ck2">
<Name>crisis name 2</Name>
<Description>crisiskindIdent for acceptance test 2</Description>
</CrisisKind>
<OrganizationKind organizationKindIdent="ok2">
<Name>organization name 2</Name>
<Description>organizationkindIdent for acceptance test 2</Description>
</OrganizationKind>
<PersonKind personKindIdent="pk2">
<Name>person name 2</Name>
<Description>personkindIdent for acceptance test 2</Description>
</PersonKind>
</WorldCrises>
"""
xml_file3="""
<WorldCrises>
<Crisis crisisIdent = "c2">
<Name>name2</Name>
<Kind crisisKindIdent = "ck2" />
<Location>
<Locality>locality2</Locality>
<Region>region2</Region>
<Country>country2</Country>
</Location>
<StartDateTime>
<Date>2222-02-02</Date>
</StartDateTime>
<HumanImpact>
<Type>type2</Type>
<Number>2222222222</Number>
</HumanImpact>
<EconomicImpact>economicimpact2</EconomicImpact>
<ExternalResources>
<ImageURL>http://22.com</ImageURL>
<VideoURL>http://www.222.com</VideoURL>
<MapURL>https://www.222222.org</MapURL>
</ExternalResources>
<RelatedPersons>
<RelatedPerson personIdent = "p2" />
</RelatedPersons>
<RelatedOrganizations>
<RelatedOrganization organizationIdent = "o2" />
</RelatedOrganizations>
</Crisis>
<Crisis crisisIdent = "c2">
<Name>name2</Name>
<Kind crisisKindIdent = "ck2" />
<Location>
<Locality>locality2</Locality>
<Region>region2</Region>
<Country>country2</Country>
</Location>
<StartDateTime>
<Date>2222-02-02</Date>
</StartDateTime>
<HumanImpact>
<Type>type2</Type>
<Number>2222222222</Number>
</HumanImpact>
<EconomicImpact>economicimpact2</EconomicImpact>
<ExternalResources>
<ImageURL>http://22.com</ImageURL>
<VideoURL>http://www.222.com</VideoURL>
<MapURL>https://www.222222.org</MapURL>
</ExternalResources>
<RelatedPersons>
<RelatedPerson personIdent = "p2" />
</RelatedPersons>
<RelatedOrganizations>
<RelatedOrganization organizationIdent = "o2" />
</RelatedOrganizations>
</Crisis>
</WorldCrises>
"""
xml_file4="""
<WorldCrises>
<Crisis crisisIdent = "c2">
<Name>name2</Name>
<Kind crisisKindIdent = "ck2" />
<Location>
<Locality>locality2</Locality>
<Region>region2</Region>
<Country>country2</Country>
</Location>
<StartDateTime>
<Date>2222-02-02</Date>
</StartDateTime>
<HumanImpact>
<Type>type2</Type>
<Number>2222222222</Number>
</HumanImpact>
<EconomicImpact>economicimpact2</EconomicImpact>
<ExternalResources>
<ImageURL>http://22.com</ImageURL>
<VideoURL>http://www.222.com</VideoURL>
<MapURL>https://www.222222.org</MapURL>
</ExternalResources>
<RelatedPersons>
<RelatedPerson personIdent = "p2" />
</RelatedPersons>
<RelatedOrganizations>
<RelatedOrganization organizationIdent = "o2" />
</RelatedOrganizations>
</Crisis>
</WorldCrises>
"""
xml_file5 = """
<WorldCrises>
<Crisis crisisIdent="Enron_EC_2001"><Name>Enron Collapse</Name><Kind crisisKindIdent="EC" /><Location><Locality>Houston</Locality><Region>TX</Region><Country>United States</Country></Location><StartDateTime><Date>2001-08-14</Date></StartDateTime><HumanImpact><Type>Financial Loss</Type><Number>60000000000</Number></HumanImpact><EconomicImpact>Greatest stock value loss in peaceful times and the largest bankruptcy in American history.</EconomicImpact><WaysToHelp /><ResourceNeeded /><ExternalResources><ImageURL>http://rememberinghistory.files.wordpress.com/2012/11/enron_logo.jpg%3Fw%3D610</ImageURL><VideoURL>http://www.youtube.com/watch?v=QS5aosxUfvY</VideoURL><MapURL>https://maps.google.com/maps?hl=enampq=1400+smith+street+houston+77002ampbav=on.2,or.r_gc.r_pw.r_cp.r_qf.ampbvm=bv.43287494,d.b2Iampbiw=640ampbih=679ampum=1ampie=UTF-8ampsa=Namptab=wl</MapURL></ExternalResources><RelatedPersons><RelatedPerson personIdent="KLay" /><RelatedPerson personIdent="AGreenspan" /></RelatedPersons><RelatedOrganizations><RelatedOrganization organizationIdent="SEC" /></RelatedOrganizations></Crisis><Crisis crisisIdent="Enron_EC_2001"><Name>Enron Collapse</Name><Kind crisisKindIdent="EC" /><Location><Locality>Houston</Locality><Region>TX</Region><Country>United States</Country></Location><StartDateTime><Date>2001-08-14</Date></StartDateTime><HumanImpact><Type /><Number /></HumanImpact><EconomicImpact /><WaysToHelp>Better Investing and pricing values</WaysToHelp><ResourceNeeded>Data on stocks and more exhaustive analysis</ResourceNeeded><ExternalResources><ImageURL>http://rememberinghistory.files.wordpress.com/2012/11/enron_logo.jpg%3Fw%3D610</ImageURL><VideoURL>http://www.youtube.com/watch?v=QS5aosxUfvY</VideoURL><MapURL>https://maps.google.com/maps?hl=enampq=1400+smith+street+houston+77002ampbav=on.2,or.r_gc.r_pw.r_cp.r_qf.ampbvm=bv.43287494,d.b2Iampbiw=640ampbih=679ampum=1ampie=UTF-8ampsa=Namptab=wl</MapURL></ExternalResources><RelatedPersons><RelatedPerson personIdent="KLay" /><RelatedPerson personIdent="AGreenspan" /></RelatedPersons><RelatedOrganizations><RelatedOrganization organizationIdent="SEC" /></RelatedOrganizations></Crisis>
</WorldCrises>
"""
xml_file6 = """
<WorldCrises>
<Crisis crisisIdent="Enron_EC_2001"><Name>Enron Collapse</Name><Kind crisisKindIdent="EC" /><Location><Locality>Houston</Locality><Region>TX</Region><Country>United States</Country></Location><StartDateTime><Date>2001-08-14</Date></StartDateTime><HumanImpact><Type>Financial Loss</Type><Number>60000000000</Number></HumanImpact><EconomicImpact>Greatest stock value loss in peaceful times and the largest bankruptcy in American history.</EconomicImpact><WaysToHelp>Better Investing and pricing values</WaysToHelp><ResourceNeeded>Data on stocks and more exhaustive analysis</ResourceNeeded><ExternalResources><ImageURL>http://rememberinghistory.files.wordpress.com/2012/11/enron_logo.jpg%3Fw%3D610</ImageURL><VideoURL>http://www.youtube.com/watch?v=QS5aosxUfvY</VideoURL><MapURL>https://maps.google.com/maps?hl=enampq=1400+smith+street+houston+77002ampbav=on.2,or.r_gc.r_pw.r_cp.r_qf.ampbvm=bv.43287494,d.b2Iampbiw=640ampbih=679ampum=1ampie=UTF-8ampsa=Namptab=wl</MapURL></ExternalResources><RelatedPersons><RelatedPerson personIdent="KLay" /><RelatedPerson personIdent="AGreenspan" /></RelatedPersons><RelatedOrganizations><RelatedOrganization organizationIdent="SEC" /></RelatedOrganizations></Crisis><Crisis crisisIdent="Enron_EC_2001"><Name>Enron Collapse</Name><Kind crisisKindIdent="EC" /><Location><Locality>Houston</Locality><Region>TX</Region><Country>United States</Country></Location><StartDateTime><Date>2001-08-14</Date></StartDateTime><HumanImpact><Type>Financial Loss</Type><Number>60000000000</Number></HumanImpact><EconomicImpact>Greatest stock value loss in peaceful times and the largest bankruptcy in American history.</EconomicImpact><WaysToHelp>Better Investing and pricing values</WaysToHelp><ResourceNeeded>Data on stocks and more exhaustive analysis</ResourceNeeded><ExternalResources><ImageURL>http://rememberinghistory.files.wordpress.com/2012/11/enron_logo.jpg%3Fw%3D610</ImageURL><VideoURL>http://www.youtube.com/watch?v=QS5aosxUfvY</VideoURL><MapURL>https://maps.google.com/maps?hl=enampq=1400+smith+street+houston+77002ampbav=on.2,or.r_gc.r_pw.r_cp.r_qf.ampbvm=bv.43287494,d.b2Iampbiw=640ampbih=679ampum=1ampie=UTF-8ampsa=Namptab=wl</MapURL></ExternalResources><RelatedPersons><RelatedPerson personIdent="KLay" /><RelatedPerson personIdent="AGreenspan" /></RelatedPersons><RelatedOrganizations><RelatedOrganization organizationIdent="SEC" /></RelatedOrganizations></Crisis>
</WorldCrises>
"""
xml_file7 = """
<WorldCrises>
<Crisis crisisIdent="Enron_EC_2001"><Name>Enron Collapse</Name><Kind crisisKindIdent="EC" /><Location><Locality>Houston</Locality><Region>TX</Region><Country>United</Country></Location><StartDateTime><Date>2001-08-14</Date></StartDateTime><HumanImpact><Type>Financial Loss</Type><Number>60000000000</Number></HumanImpact><EconomicImpact>Greatest stock value loss in peaceful times and the largest bankruptcy in American history.</EconomicImpact><WaysToHelp>Better Investing and pricing values</WaysToHelp><ResourceNeeded>Data on stocks and more exhaustive analysis</ResourceNeeded><ExternalResources><ImageURL>http://rememberinghistory.files.wordpress.com/2012/11/enron_logo.jpg%3Fw%3D610</ImageURL><VideoURL>http://www.youtube.com/watch?v=QS5aosxUfvY</VideoURL><MapURL>https://maps.google.com/maps?hl=enampq=1400+smith+street+houston+77002ampbav=on.2,or.r_gc.r_pw.r_cp.r_qf.ampbvm=bv.43287494,d.b2Iampbiw=640ampbih=679ampum=1ampie=UTF-8ampsa=Namptab=wl</MapURL></ExternalResources><RelatedPersons><RelatedPerson personIdent="KLay" /><RelatedPerson personIdent="AGreenspan" /></RelatedPersons><RelatedOrganizations><RelatedOrganization organizationIdent="SEC" /></RelatedOrganizations></Crisis><Crisis crisisIdent="Enron_EC_2001"><Name>Enron Collapse</Name><Kind crisisKindIdent="EC" /><Location><Locality>Houston</Locality><Region>TX</Region><Country>United States</Country></Location><StartDateTime><Date>2001-08-14</Date></StartDateTime><HumanImpact><Type>Financial Loss</Type><Number>60000000000</Number></HumanImpact><EconomicImpact>Greatest stock value loss in peaceful times and the largest bankruptcy in American history.</EconomicImpact><WaysToHelp>Better Investing and pricing values</WaysToHelp><ResourceNeeded>Data on stocks and more exhaustive analysis</ResourceNeeded><ExternalResources><ImageURL>http://rememberinghistory.files.wordpress.com/2012/11/enron_logo.jpg%3Fw%3D610</ImageURL><VideoURL>http://www.youtube.com/watch?v=QS5aosxUfvY</VideoURL><MapURL>https://maps.google.com/maps?hl=enampq=1400+smith+street+houston+77002ampbav=on.2,or.r_gc.r_pw.r_cp.r_qf.ampbvm=bv.43287494,d.b2Iampbiw=640ampbih=679ampum=1ampie=UTF-8ampsa=Namptab=wl</MapURL></ExternalResources><RelatedPersons><RelatedPerson personIdent="KLay" /><RelatedPerson personIdent="AGreenspan" /></RelatedPersons><RelatedOrganizations><RelatedOrganization organizationIdent="SEC" /></RelatedOrganizations></Crisis>
</WorldCrises>
"""
class MyTest(unittest.TestCase):
def test_WCDB2_generater_dictionaries_1(self):
root = et.fromstring(xml_file)
crisis_list,location_list,organization_list, person_list, crisis_kind_list, person_kind_list, organization_kind_list = generate_dictionaries(root)
x = crisis_list[0]
self.assert_( x['start_date_time'] == ' 2001-08-14 ')
def test_WCDB2_generater_dictionaries_2(self):
root = et.fromstring(xml_file)
crisis_list,location_list,organization_list, person_list, crisis_kind_list, person_kind_list, organization_kind_list = generate_dictionaries(root)
x = organization_list[0]
self.assert_( x['organizationIdent'] == 'USDA')
def test_WCDB2_generater_dictionaries_3(self):
root = et.fromstring(xml_file)
crisis_list,location_list,organization_list, person_list, crisis_kind_list, person_kind_list, organization_kind_list = generate_dictionaries(root)
x = location_list[0]
self.assert_( x['country'] == ' United States ')
#----------------------
# WCDB2_print
#----------------------
def test_WCDB_print_1(self):
w=StringIO.StringIO()
root= et.fromstring(xml_file)
r= WCDB_print(w,xml_file2)
xml = et.tostring(root)
self.assert_(r != xml)
def test_WCDB_print_2(self):
w=StringIO.StringIO()
xml= xml_file
r= WCDB_print(w,xml)
self.assert_(r != xml)
def test_WCDB_print_3(self):
w=StringIO.StringIO()
root= et.fromstring(xml_file2)
xml = et.tostring(root)
r = WCDB_print(w,xml)
self.assert_(r == xml)
def test_merge_1(self):
root= et.fromstring(xml_file5)
x= merge(root)
y= et.fromstring(xml_file6)
z=et.tostring(y)
string = et.tostring(x)
self.assert_(string == z)
def test_merge_2(self):
root= et.fromstring(xml_file3)
x= merge(root)
self.assert_(x != xml_file4)
def test_merge_3(self):
root= et.fromstring(xml_file5)
x= merge(root)
result = et.fromstring(xml_file7)
self.assert_(et.tostring(x) != et.tostring(result))
## def test_export_table(self):
## element_list= [{'id':'E2001','name':'Syrian Civil War','economic_impact':'Greatest stock value loss in peaceful times and the largest bankruptcy in American history.'}]
## c= create_table()
## table_name= 'Crisis'
## fill_tables(
## xTable= export_table(c, table_name)
## xml= et.tostring(xTable)
##
##
if __name__=='__main__':
print ("MyTest.py")
unittest.main()
print ('Done.')