def test_query_obama(self): query_obama() obama = People(idref="PER_BROBMA", name="Barack Obama") steve = People(idref="PER_STEVEN", name="Steve") robert = People(idref="PER_ROBERT", name="Robert") moon = People(idref="PER_MOOOON", name="The Moon") picnic = Crises(idref="CRI_PICNIC", name="A Picnic") aliens = Organizations(idref="ORG_ALIENS", name="Aliens") obama.save() steve.save() robert.save() moon.save() picnic.save() aliens.save() picnic.people.add(obama) picnic.people.add(steve) obama.organizations.add(aliens) robert.organizations.add(aliens) result = query_obama() self.assertEqual(len(result), 3) self.assertTrue((u"PER_BROBMA",) in result) self.assertTrue((u"PER_STEVEN",) in result) self.assertTrue((u"PER_ROBERT",) in result) self.assertTrue(not (u"PER_MOOOON",) in result) self.assertTrue(not (u"CRI_PICNIC",) in result) self.assertTrue(not (u"ORG_ALIENS",) in result)
def seed_org(db, app): org = Organizations(id=1, organization='Arts', description='Arts', group_id=1) with app.app_context(): db.session.add(org) db.session.commit() org = Organizations(id=6, organization='BOC', description='BOC - Bank of Canada', group_id=2) with app.app_context(): db.session.add(org) db.session.commit()
def test_query_people_without_orgs(self): query_people_without_orgs() vader = People(name="Darth Vader", idref="PER_DVADER") luke = People(name="Luke Skywalker", idref="PER_LUKESW") empire = Organizations(name="The Empire", idref="ORG_EMPIRE") vader.organizations.add(empire) vader.save() luke.save() empire.save() result = query_people_without_orgs() self.assertEqual(len(result), 1) self.assertTrue(not (u"PER_DVADER",) in result) self.assertTrue(not (u"ORG_EMPIRE",) in result) self.assertTrue((u"PER_LUKESW",) in result)
def test_query_crises_without_things(self): query_crises_without_things() vader = People(name="Darth Vader", idref="PER_DVADER") luke = People(name="Luke Skywalker", idref="PER_LUKESW") empire = Organizations(name="The Empire", idref="ORG_EMPIRE") war = Crises(name="Intergalactic War", idref="CRI_THEWAR") war.people.add(vader) war.people.add(luke) war.organizations.add(empire) vader.organizations.add(empire) stormtroopers = Crises(name="Stormtroopers are dumb", idref="CRI_TROOPR") stormtroopers.organizations.add(empire) rebellion = Crises(name="The Rebellion", idref="CRI_REBELS") rebellion.people.add(luke) problem = Crises(name="The prequels suck", idref="CRI_PREQEL") tired = Crises(name="making these tests is tiring i'm sorry for the dumb stuff", idref="CRI_IMBORD") orphan = People(name="person w/o thing", idref="PER_ORPHAN") vader.save() luke.save() empire.save() war.save() stormtroopers.save() rebellion.save() problem.save() tired.save() orphan.save() result = query_crises_without_things() self.assertEqual(len(result), 2) self.assertTrue(("CRI_PREQEL",) in result) self.assertTrue(("CRI_IMBORD",) in result) self.assertTrue(not ("PER_DVADER",) in result) self.assertTrue(not ("PER_LUKESW",) in result) self.assertTrue(not ("ORG_EMPIRE",) in result) self.assertTrue(not ("CRI_THEWAR",) in result) self.assertTrue(not ("CRI_TROOPR",) in result) self.assertTrue(not ("CRI_REBELS",) in result) self.assertTrue(not ("PER_ORPHAN",) in result)
def test_query_people_with_red_cross_videos(self): redcross = Organizations(name="The Red Cross", idref="ORG_REDCRS") firedp = Organizations(name="Fire Department", idref="ORG_FIREDP") dracula = People(name="Dracula", idref="PER_DRACUL") fireman = People(name="Fireman", idref="PER_FIREMN") multitasker = People(name="Multitasker", idref="PER_MULTAS") joshmo = People(name="John Smith", idref="PER_BORING") lincoln = People(name="Abraham Lincoln", idref="PER_LINCLN") List_Item(list_type="Videos", idref="PER_DRACUL").save() List_Item(list_type="Videos", idref="PER_MULTAS").save() List_Item(list_type="Videos", idref="PER_LINCLN").save() dracula.organizations.add(redcross) fireman.organizations.add(firedp) multitasker.organizations.add(redcross) multitasker.organizations.add(firedp) redcross.save() firedp.save() dracula.save() fireman.save() multitasker.save() lincoln.save() result = query_people_with_red_cross_videos() self.assertEqual(len(result), 2) self.assertTrue(("PER_DRACUL",) in result) self.assertTrue(("PER_MULTAS",) in result) self.assertTrue(not ("PER_LINCLN",) in result) self.assertTrue(not ("PER_BORING",) in result) self.assertTrue(not ("PER_FIREMN",) in result) self.assertTrue(not ("ORG_REDCRS",) in result) self.assertTrue(not ("PER_FIREDP",) in result)
def test_query_things_without_pictures(self): query_things_without_pictures() obama = People(name="Barack Obama", idref="PER_BROBMA") me = People(name="James Kunze", idref="PER_JAMESK") un = Organizations(name="United Nations", idref="ORG_UNINAT") cachemoney = Organizations(name="Cache Money", idref="ORG_CACHEM") aids = Crises(name="AIDS/HIV", idref="CRI_AIDSHI") phasethree = Crises(name="CS373 Project Phase 3", idref="CRI_PROJCT") pic1 = List_Item(list_type="Images", idref="PER_BROBMA", embed="obamapic.png") pic2 = List_Item(list_type="Images", idref="ORG_UNINAT", embed="unpic.png") pic3 = List_Item(list_type="Images", idref="CRI_AIDSHI", embed="aidspic.png") obama.save() me.save() un.save() cachemoney.save() aids.save() phasethree.save() pic1.save() pic2.save() pic3.save() result = query_things_without_pictures() self.assertEqual(len(result), 3) self.assertTrue(not ("PER_BROBMA",) in result) self.assertTrue(not ("ORG_UNINAT",) in result) self.assertTrue(not ("CRI_AIDSHI",) in result) self.assertTrue(("PER_JAMESK",) in result) self.assertTrue(("ORG_CACHEM",) in result) self.assertTrue(("CRI_PROJCT",) in result)
def test_query_orgs_with_many_videos(self): query_orgs_with_many_videos() bookclub = Organizations(name="Book Club", idref="ORG_BOOKCL") firedept = Organizations(name="Fire Department", idref="ORG_FIREDP") un = Organizations(name="United Nations", idref="ORG_UNINAT") List_Item(list_type="Videos", idref="ORG_UNINAT").save() List_Item(list_type="Videos", idref="ORG_UNINAT").save() List_Item(list_type="Videos", idref="ORG_FIREDP").save() bookclub.save() firedept.save() un.save() result = query_orgs_with_many_videos() self.assertEqual(len(result), 1) self.assertTrue(("ORG_UNINAT",) in result) self.assertTrue(not ("ORG_FIREDP",) in result) self.assertTrue(not ("ORG_BOOKCL",) in result)
def test_search_one_word(self): fire = Crises(name="Arizona Wildfires", idref="CRI_AZWILD", date=date(2013, 8, 5)) china = Crises(name="Democracy in China", idref="CRI_CHINAD", date=date(2013, 8, 5)) civilwar = Crises(name="The Civil War", idref="CRI_CIVWAR", date=date(1960, 1, 1)) dracula = People(name="Dracula", idref="PER_DRACUL") firedp = Organizations(name="Arizona Fire Department", idref="ORG_FIREDP") fire.save() china.save() civilwar.save() dracula.save() firedp.save() self.assertEqual( search_one_word("Arizona", []), [ ("CRI_AZWILD", "Arizona Wildfires", "Arizona Wildfires"), ("ORG_FIREDP", "Arizona Fire Department", "Arizona Fire Department"), ], ) self.assertEqual( search_one_word("Fire", []), [ ("CRI_AZWILD", "Arizona Wildfires", "Arizona Wildfires"), ("ORG_FIREDP", "Arizona Fire Department", "Arizona Fire Department"), ], ) self.assertEqual(search_one_word("Extreme Elevator Riding", []), []) self.assertEqual(search_one_word("Dracula", []), [("PER_DRACUL", "Dracula", "Dracula")]) self.assertEqual( search_one_word("Fire", ["CRI_AZWILD"]), [("ORG_FIREDP", "Arizona Fire Department", "Arizona Fire Department")], ) self.assertEqual( search_one_word("Fire", ["ORG_FIREDP"]), [("CRI_AZWILD", "Arizona Wildfires", "Arizona Wildfires")] ) self.assertEqual(search_one_word("Fire", ["CRI_AZWILD", "ORG_FIREDP"]), []) self.assertEqual(search_one_word("Democracy in China", []), search_one_word("DeMoCrAcY In CHINA", []))
def org_test_db_build(): db.init_app(app) with app.app_context(): group = Groups( id=1, s_group='GC_A', description='Arts', ) db.session.add(group) group = Groups( id=2, s_group='GC_BF', description='Banking and Finance', ) db.session.add(group) org = Organizations(id=1, organization='Arts', description='Arts', group_id=1) db.session.add(org) org = Organizations(id=6, organization='BOC', description='BOC - Bank of Canada', group_id=2) db.session.add(org) db.session.commit() yield with app.app_context(): Organizations.query.delete() Groups.query.delete() db.session.commit()
def addOrganization(name, email, location=None, category=None, summary=None): newOrg = Organizations(name=name, email=email, location=location, category=category, summary=summary) try: db.session.add(newOrg) db.session.commit() return 1 except IntegrityError as e: print(e.__dict__) if isinstance(e.orig, UniqueViolation): return "Account associated with that email already exists" return "Could not register account"
def domain_test_db_init(): db.init_app(app) with app.app_context(): org = Organizations( id=6, organization='BOC', description='BOC - Bank of Canada', ) db.session.add(org) db.session.commit() domain = Domains(id=15, domain='bankofcanada.ca', organization_id=6) db.session.add(domain) db.session.commit() yield with app.app_context(): Domains.query.delete() Organizations.query.delete() db.session.commit()
def getAllCharities(): result = Organizations.query.all() if result == None: return "No organizations found" transformedOrgs = [] for org in result: newName = org.name.replace(" ", "-") if newName == "testName": continue transformedOrg = Organizations( name=newName, email=org.email, location=org.location, category=org.category, summary=org.summary, ).__repr__() imageId = testData.imageIdByCharityName[newName] transformedOrg["imageId"] = imageId transformedOrg["news"] = testData.newsByCharityName[newName] transformedOrg["imageName"] = str(imageId) + ".png" transformedOrgs.append(transformedOrg) return transformedOrgs