Skip to content

Commit

Permalink
Finished first complete version of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvaro del Castillo committed Nov 11, 2013
1 parent ac9c91e commit 6f8da0b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
6 changes: 3 additions & 3 deletions mediawiki_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def process_revision_by_id(cursor, revid):
api_url = opts.url + "/" + "api.php"
allchanges_query = "action=query&prop=revisions&revids="+revid+"&format=xml"
rev_query = api_url + "?" + allchanges_query
if (opts.debug): print("Rev query: " + rev_query)
# if (opts.debug): print("Rev query: " + rev_query)
revision = urllib2.urlopen(rev_query)
revision_data = revision.read().strip('\n')
xmlrevision = parseString(revision_data)
Expand All @@ -162,7 +162,7 @@ def process_revisions(cursor, pageid, xmlrevs):
if rev.hasAttribute('user'):
user = rev.attributes['user'].value
else: user = rev.attributes['userhidden'].value
if (opts.debug): print (pageid +" " + revid+" "+user+" "+timestamp+" "+comment)
# if (opts.debug): print (pageid +" " + revid+" "+user+" "+timestamp+" "+comment)
insert_revision (cursor, pageid, revid, user, timestamp, comment)
except:
print rev.attributes.items()
Expand Down Expand Up @@ -205,7 +205,7 @@ def process_changes(cursor, xmlchanges):
for entry in xmlchanges.getElementsByTagName('recentchanges'):
if entry.hasAttribute('rccontinue'):
rccontinue = entry.attributes['rccontinue'].value.encode('utf-8')
if (opts.debug): print("Continue changes from:"+rccontinue)
# if (opts.debug): print("Continue changes from:"+rccontinue)
break
for change in xmlchanges.getElementsByTagName('rc'):
revtype = change.attributes['type'].value.encode('utf-8')
Expand Down
25 changes: 16 additions & 9 deletions test/test_mediawiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,34 @@ class Config:

class MediaWikiTest(unittest.TestCase):

# Changes API not tested because it needs URL API omline
def testZAll(self):
# look test/data/README
total_pages = 17
total_reviews = 23
total_changes = 47
total_revisions = 47
pageid_reviews = "1428"
# total_changes = 23
cursor = MediaWikiTest.db.cursor()
pages = open(os.path.join(MediaWikiTest.tests_data_dir, "pages.xml"))
reviews = open(os.path.join(MediaWikiTest.tests_data_dir, "revisions.xml"))
changes = open (os.path.join(MediaWikiTest.tests_data_dir, "changes.xml"))
revisions = open(os.path.join(MediaWikiTest.tests_data_dir, "revisions.xml"))
# changes = open (os.path.join(MediaWikiTest.tests_data_dir, "changes.xml"))
mediawiki_analysis.process_pages(cursor, parseString(pages.read()), None, False)
# print (reviews.read())
# print (changes.read())
mediawiki_analysis.process_revisions(cursor, pageid_reviews, parseString(revisions.read()))
pages.close()
revisions.close()
MediaWikiTest.db.commit()
sql = "SELECT COUNT(*) FROM wiki_pages"
cursor.execute(sql)
self.assertEqual(cursor.fetchall()[0][0], total_pages)
sys.exit(0)
sql = "SELECT COUNT(*) FROM wiki_pages_revs"
cursor.execute(sql)
self.assertEqual(cursor.fetchall()[0][0], total_reviews)

self.assertEqual(cursor.fetchall()[0][0], total_revisions)
# mediawiki_analysis.process_changes(cursor, parseString(changes.read()))
# changes.close()
# sql = "SELECT COUNT(*) FROM wiki_pages_revs"
# cursor.execute(sql)
# self.assertEqual(cursor.fetchall()[0][0], total_revisions+total_changes)

def setUp(self):
pass

Expand Down

0 comments on commit 6f8da0b

Please sign in to comment.