def testSponsorUpdate(self): # valid sponsor sponsor_name = str(uuid.uuid1()) new_sponsor_name = str(uuid.uuid1()) s = Sponsor(sponsor_name) # valid update s.update(name=new_sponsor_name, link="New Link", description="new") # now bad stuff try: s.update(name=1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass try: s.update(sponsor_name, link=1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass try: s.update(sponsor_name, link="http://good-sponsor.ca", description=1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass
def testSponsorUpdate(self): # valid sponsor s = Sponsor("Good Sponsor") # valid update s.update(name="New Sponsor", link="New Link", description="new") # now bad stuff try: s.update(name=1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass try: s.update("Good Sponsor", link=1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass try: s.update("Good Sponsor", link="http://good-sponsor.ca", description=1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass
def pull_sponsors(url): """ pull_sponsors Returns a lookup of sponsors that were pulled from the website into local DB Parameters: url: the url of the main site Returns: a dictionary lookup for the website sponsor id to local sponsor object e.g. sponsor_lookup = {1: Sponsor(), etc..} """ # add all the sponsors _sponsors = requests.get(url + '/api/sponsors').json() if isinstance(_sponsors, dict): _sponsors = pull_all_pages(url, _sponsors) sponsors_lookup = {} for sponsor in tqdm(_sponsors, desc="Pulling sponsors from {}".format(url)): temp = Sponsor(sponsor['sponsor_name'], link=sponsor['link'], description=sponsor['description']) sponsors_lookup[sponsor['sponsor_id']] = temp DB.session.add(temp) DB.session.commit() return sponsors_lookup
def post(self): """ POST request for Sponsor List Route: Routes['sponsor']/<sponsor_id:int> Parameters: sponsor_name: The Sponsor's name (string) link: A link to sponsors website (string) description: a description of the sponsor (string) active: 1 if the sponsor if active otherwise 0 Returns: if successful status: 200 mimetype: application/json sponsor_id: the create sponsor_id else status: 409 mimetype: application/json data: the create sponsor_id (int) """ # create a new user args = post_parser.parse_args() sponsor_name = None description = None link = None active = True if args['sponsor_name']: sponsor_name = args['sponsor_name'] if args['description']: description = args['description'] if args['link']: link = args['link'] if args['active']: active = args['active'] == 1 if True else False sponsor = Sponsor(sponsor_name, link=link, description=description, active=active) DB.session.add(sponsor) DB.session.commit() sponsor_id = sponsor.id handle_table_change(Tables.SPONSOR, item=sponsor.json()) return Response(dumps(sponsor_id), status=201, mimetype="application/json")
def mock_sponsors(): """Mock the sponsors""" sponsor_lookup = {} for index, name in enumerate([ "Beertown", "Kik", "Pabst", "Spitz", "Tilt", "Sportszone", "Sleeman", "Ripshot", "Night School", "Heaven", "GE", "Gatorade", "Chef on Call" ]): sponsor = Sponsor(name) DB.session.add(sponsor) sponsor_lookup[index + 1] = sponsor DB.session.commit() return sponsor_lookup
def testSponsorInit(self): # valid data sponsor_name = str(uuid.uuid1()) Sponsor(sponsor_name) Sponsor(sponsor_name, link="http://good-sponsor.ca", description="Good Descript") # now bad stuff try: Sponsor(1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass try: Sponsor(sponsor_name, link=1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass try: Sponsor(sponsor_name, link="http://good-sponsor.ca", description=1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass