def setUp(self): # First, create an instance of the Testbed class. self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_memcache_stub() self.handler = ArticleHandler() self.x = XMLUploadWorker() xsdFileInput = open("test/test.xsd", 'r') xmlfile = open('test/test2.xml','r') xmleval = xsv.parseAndValidateString(re.sub('&', '&', xmlfile.read()), xsdFileInput.read(), xmlIfClass=xsv.XMLIF_ELEMENTTREE) etree = xmleval.getTree() root = etree.getroot() self.x.createModels(root.find("people")) self.x.createModels(root.find("crises")) self.x.createModels(root.find("organizations")) self.x.createLinks(root.find("crises"), False) self.x.createLinks(root.find("people"), False) self.x.createLinks(root.find("organizations"), False)
class TestArticleHandler(unittest.TestCase): def setUp(self): # First, create an instance of the Testbed class. self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_memcache_stub() self.handler = ArticleHandler() self.x = XMLUploadWorker() xsdFileInput = open("test/test.xsd", 'r') xmlfile = open('test/test2.xml','r') xmleval = xsv.parseAndValidateString(re.sub('&', '&', xmlfile.read()), xsdFileInput.read(), xmlIfClass=xsv.XMLIF_ELEMENTTREE) etree = xmleval.getTree() root = etree.getroot() self.x.createModels(root.find("people")) self.x.createModels(root.find("crises")) self.x.createModels(root.find("organizations")) self.x.createLinks(root.find("crises"), False) self.x.createLinks(root.find("people"), False) self.x.createLinks(root.find("organizations"), False) def test_commonInfo1(self): dictionary = {} someEntity = db.get(db.Key.from_path("Person", "bill-clinton")) self.assert_(not (someEntity == None)) self.handler.commonInfo(dictionary, someEntity) self.assert_(dictionary['name'] == "Bill Clinton") self.assert_(dictionary['category'] == "President of The USA") self.assert_(dictionary['description']) self.assert_(dictionary['country'] == "USA") self.assert_(dictionary['city'] == "Washington D.C.") self.assert_(str(type(dictionary["image_source"])) == str(type([]))) self.assert_(len(dictionary["image_source"]) > 1) self.assert_(dictionary["image_source"][0]['src'] == 'http://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/Bill_Clinton.jpg/220px-Bill_Clinton.jpg') self.assert_(dictionary["image_source"][0]['desc']) self.assert_(dictionary["image_source"][1]['src'] == 'http://photos.state.gov/galleries/ankara/9104/between_friends_photo_exhibit/clinton_and_kids.jpg') self.assert_(dictionary["image_source"][1]['desc']) self.assert_(str(type(dictionary["external_source"])) == str(type([]))) self.assert_(len(dictionary["external_source"]) > 0) self.assert_(dictionary["external_source"][0]['src'] == 'http://en.wikipedia.org/wiki/Clinton_Foundation') self.assert_(dictionary["external_source"][0]['desc']) self.assert_(str(type(dictionary["external_source"])) == str(type([]))) self.assert_(len(dictionary["citation_source"]) > 0) self.assert_(dictionary["citation_source"][0]['src'] == 'http://politicalhumor.about.com/cs/quotethis/a/clintonquotes.htm') self.assert_(dictionary["citation_source"][0]['desc']) def test_commonInfo2(self): dictionary = {} someEntity = db.get(db.Key.from_path("Person", "yao-ming")) self.assert_(not (someEntity == None)) self.handler.commonInfo(dictionary, someEntity) self.assert_(dictionary['name'] == "Yao Ming") self.assert_(dictionary['category']) self.assert_(dictionary['description']) self.assert_(dictionary['country'] == "USA") self.assert_(str(type(dictionary["image_source"])) == str(type([]))) self.assert_(len(dictionary["image_source"]) > 1) self.assert_(dictionary["image_source"][0]['src'] == 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/YaoMingonoffense2.jpg/399px-YaoMingonoffense2.jpg') self.assert_(dictionary["image_source"][0]['desc']) self.assert_(dictionary["image_source"][1]['src'] == 'http://saceweb.com/yahoo_site_admin/assets/images/Yaoming_Earthquate_Donation_resize.13594706.JPG') self.assert_(dictionary["image_source"][1]['desc']) self.assert_(str(type(dictionary["external_source"])) == str(type([]))) self.assert_(len(dictionary["external_source"]) > 0) self.assert_(dictionary["external_source"][0]['src'] == 'http://en.wikipedia.org/wiki/Yao_Ming') self.assert_(dictionary["external_source"][0]['desc']) self.assert_(str(type(dictionary["external_source"])) == str(type([]))) self.assert_(len(dictionary["citation_source"]) > 0) self.assert_(dictionary["citation_source"][0]['src'] == 'http://www.brainyquote.com/quotes/authors/y/yao_ming.html') self.assert_(dictionary["citation_source"][0]['desc']) def test_commonInfo3(self): dictionary = {} someEntity = db.get(db.Key.from_path("Crisis", "beslan-school-siege")) self.assert_(not (someEntity == None)) self.handler.commonInfo(dictionary, someEntity) self.assert_(dictionary['name'] == "Beslan School Siege") self.assert_(dictionary['category'] == "Terrorist Attack") self.assert_(dictionary['description']) self.assert_(dictionary['country'] == "Russian Federation") self.assert_(str(type(dictionary["image_source"])) == str(type([]))) self.assert_(len(dictionary["image_source"]) > 1) self.assert_(dictionary["image_source"][0]['src'] == 'http://www.zindamagazine.com/html/archives/2004/9.21.04/pix/beslan.jpg') self.assert_(len(dictionary["image_source"][0]['desc']) > 0) self.assert_(dictionary["image_source"][1]['src'] == 'http://thefamilywithoutborders.com/wp-content/uploads/2010/07/beslan-school-gymnasium.jpg') self.assert_(len(dictionary["image_source"][1]['desc']) > 0) self.assert_(str(type(dictionary["external_source"])) == str(type([]))) self.assert_(len(dictionary["external_source"]) > 0) self.assert_(dictionary["external_source"][0]['src'] == 'http://en.wikipedia.org/wiki/Beslan_school_hostage_crisis') self.assert_(len(dictionary["external_source"][0]['desc']) > 0) self.assert_(str(type(dictionary["external_source"])) == str(type([]))) self.assert_(len(dictionary["map_source"]) > 0) self.assert_(dictionary["map_source"][0] == 'https://maps.google.com/maps?q=%D0%B1%D0%B5%D1%81%D0%BB%D0%B0%D0%BD+%D0%BA%D0%B0%D1%80%D1%82%D0%B0&ie=UTF-8&hq=&hnear=0x40507a3d42902631:0x44b473c66c3f5648,Beslan,+Respublika+Severnaya+Osetiya-Alaniya,+Russia&gl=us&ei=VFWIUK6WCOfE2gXb_IGABg&ved=0CB8Q8gEwAA') def test_createHtmlLinks1(self): dictionary = {} someEntity = db.get(db.Key.from_path("Person", "george-w-bush")) self.assert_(not (someEntity == None)) self.handler.createHtmlLinks(dictionary, someEntity) self.assert_(str(type(dictionary["videos_youtube"])) == str(type([]))) self.assert_(dictionary["videos_youtube"][0]['src'] == 'http://www.youtube.com/embed/4RbAZj9RB94') self.assert_(dictionary["videos_youtube"][0]['img_src'] == 'http://img.youtube.com/vi/4RbAZj9RB94/0.jpg') self.assert_(str(type(dictionary["social_facebook"])) == str(type([]))) self.assert_("http://www.facebook.com/georgewbush" in dictionary["social_facebook"][0]) self.assert_(str(type(dictionary["social_twitter"])) == str(type([]))) self.assert_("https://www.twitter.com/@GeorgeBush" in dictionary["social_twitter"][0]) def test_createHtmlLinks2(self): dictionary = {} someEntity = db.get(db.Key.from_path("Person", "vladimir-putin")) self.assert_(not (someEntity == None)) self.handler.createHtmlLinks(dictionary, someEntity) self.assert_(str(type(dictionary["videos_youtube"])) == str(type([]))) self.assert_(len(dictionary["videos_youtube"]) == 2) self.assert_(dictionary["videos_youtube"][0]['src'] == 'http://www.youtube.com/embed/TNiWnSOsAnE') self.assert_(dictionary["videos_youtube"][0]['img_src'] == 'http://img.youtube.com/vi/TNiWnSOsAnE/0.jpg') self.assert_(dictionary["videos_youtube"][1]['src'] == 'http://www.youtube.com/embed/ZR84oXysqoA') self.assert_(dictionary["videos_youtube"][1]['img_src'] == 'http://img.youtube.com/vi/ZR84oXysqoA/0.jpg') self.assert_(len(dictionary["videos_vimeo"]) > 0) self.assert_(dictionary["videos_vimeo"][0]['src'] == 'http://www.player.vimeo.com/video/38458300?') self.assert_(str(type(dictionary["social_facebook"])) == str(type([]))) self.assert_("http://www.facebook.com/vladimirputinandrussia" in dictionary["social_facebook"][0]) self.assert_(str(type(dictionary["social_twitter"])) == str(type([]))) self.assert_("https://www.twitter.com/@kremlinrussia_e" in dictionary["social_twitter"][0]) def test_createHtmlLinks3(self): dictionary = {} someEntity = db.get(db.Key.from_path("Crisis", "beslan-school-siege")) self.assert_(not (someEntity == None)) self.handler.createHtmlLinks(dictionary, someEntity) self.assert_(str(type(dictionary["videos_youtube"])) == str(type([]))) self.assert_(len(dictionary["videos_youtube"]) > 0) self.assert_(dictionary["videos_youtube"][0]['src'] == 'http://www.youtube.com/embed/csr9TPGPoxs') self.assert_(dictionary["videos_youtube"][0]['img_src'] == 'http://img.youtube.com/vi/csr9TPGPoxs/0.jpg') self.assert_(len(dictionary["videos_vimeo"]) > 0) self.assert_(dictionary["videos_vimeo"][0]['src'] == 'http://www.player.vimeo.com/video/34659973?') self.assert_(str(type(dictionary["social_facebook"])) == str(type([]))) self.assert_("http://www.facebook.com/vladimirputinandrussia" in dictionary["social_facebook"][0]) self.assert_(str(type(dictionary["social_twitter"])) == str(type([]))) self.assert_("https://www.twitter.com/@SOssetia" in dictionary["social_twitter"][0]) def test_createHtmlLinks4(self): dictionary = {} someEntity = db.get(db.Key.from_path("Organization", "nyfd")) self.assert_(not (someEntity == None)) self.handler.createHtmlLinks(dictionary, someEntity) self.assert_(str(type(dictionary["videos_youtube"])) == str(type([]))) self.assert_(len(dictionary["videos_youtube"]) == 2) self.assert_(dictionary["videos_youtube"][0]['src'] == 'http://www.youtube.com/embed/YZ4hK1aGY7Q') self.assert_(dictionary["videos_youtube"][0]['img_src'] == 'http://img.youtube.com/vi/YZ4hK1aGY7Q/0.jpg') self.assert_(dictionary["videos_youtube"][1]['src'] == 'http://www.youtube.com/embed/UINW1Ls64T8') self.assert_(dictionary["videos_youtube"][1]['img_src'] == 'http://img.youtube.com/vi/UINW1Ls64T8/0.jpg') self.assert_(str(type(dictionary["social_facebook"])) == str(type([]))) self.assert_("http://www.facebook.com/FDNY" in dictionary["social_facebook"][0]) self.assert_(str(type(dictionary["social_twitter"])) == str(type([]))) self.assert_("https://www.twitter.com/@FDNY" in dictionary["social_twitter"][0])