def test_get_categories_fail(self): with self.assertRaises(Exception) as cm: yelp._generate_business_search_url( location='Berkeley, CA', categories='vietnamese,thai,awesomepizza,pho') self.assertEqual( '"awesomepizza" is not a valid category because it isn\'t in the yelp.get_categories() list. Please make sure that the following categories are valid (with a comma separating each of them): vietnamese,thai,awesomepizza,pho', str(cm.exception))
def test_yelp_generate_business_search_url_location(self): goal_url = 'https://api.yelp.com/v3/businesses/search?location=Berkeley%2C+CA&limit=10' url = yelp._generate_business_search_url(location='Berkeley, CA') self.assertEqual(url, goal_url) goal_url = 'https://api.yelp.com/v3/businesses/search?location=Tallahassee%2C+FL&limit=10' url = yelp._generate_business_search_url(location='Tallahassee, FL') self.assertEqual(url, goal_url)
def test_yelp_generate_business_search_url_term(self): goal_url = 'https://api.yelp.com/v3/businesses/search?location=Berkeley%2C+CA&limit=10&term=italian' url = yelp._generate_business_search_url(location='Berkeley, CA', term='italian') self.assertEqual(url, goal_url) goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=8&term=chinese' url = yelp._generate_business_search_url(limit=8, term='chinese') self.assertEqual(url, goal_url)
def test_yelp_generate_business_search_url_limit(self): goal_url = 'https://api.yelp.com/v3/businesses/search?location=Berkeley%2C+CA&limit=5' url = yelp._generate_business_search_url(location='Berkeley, CA', limit=5) self.assertEqual(url, goal_url) goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=8' url = yelp._generate_business_search_url(limit=8) self.assertEqual(url, goal_url)
def test_yelp_generate_business_search_url_open_now(self): goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=10&term=italian&open_now=true' url = yelp._generate_business_search_url(term='italian', open_now=1) self.assertEqual(url, goal_url) url = yelp._generate_business_search_url(term='italian', open_now=True) self.assertEqual(url, goal_url) goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=10&term=italian' url = yelp._generate_business_search_url(term='italian', open_now=False) self.assertEqual(url, goal_url) url = yelp._generate_business_search_url(term='italian', open_now=0) self.assertEqual(url, goal_url)
def test_yelp_generate_business_search_url_price_success(self): goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=10&term=italian&price=1,2,3,4' url = yelp._generate_business_search_url(term='italian', price='3,2,4,1') self.assertEqual(url, goal_url) goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=10&term=italian&price=1' url = yelp._generate_business_search_url(term='italian', price=1) self.assertEqual(url, goal_url) goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=10&term=italian&price=2' url = yelp._generate_business_search_url(term='italian', price=2) self.assertEqual(url, goal_url) goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=10&term=italian&price=3' url = yelp._generate_business_search_url(term='italian', price=3) self.assertEqual(url, goal_url) goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=10&term=italian&price=4' url = yelp._generate_business_search_url(term='italian', price=4) self.assertEqual(url, goal_url)
def test_yelp_generate_business_search_url_sort_by(self): goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=10&term=italian' url = yelp._generate_business_search_url(term='italian') self.assertEqual(url, goal_url) goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=10&term=italian&sort_by=best_match' url = yelp._generate_business_search_url(term='italian', sort_by='best_match') self.assertEqual(url, goal_url) goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=10&term=italian&sort_by=rating' url = yelp._generate_business_search_url(term='italian', sort_by='rating') self.assertEqual(url, goal_url) goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=10&term=italian&sort_by=distance' url = yelp._generate_business_search_url(term='italian', sort_by='distance') self.assertEqual(url, goal_url) goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=10&term=italian&sort_by=review_count' url = yelp._generate_business_search_url(term='italian', sort_by='review_count') self.assertEqual(url, goal_url) with self.assertRaises(Exception) as cm: url = yelp._generate_business_search_url(term='italian', sort_by='price') self.assertIn( "price not in ['best_match', 'rating', 'review_count', 'distance']", str(cm.exception))
def test_yelp_generate_business_search_url_price_fail(self): with self.assertRaises(Exception) as cm: yelp._generate_business_search_url(term='italian', price='$$') error_message = "The price parameter can be 1, 2, 3, 4, or some comma-separated combination (e.g. 1,2,3). You used: $$" self.assertEqual(error_message, str(cm.exception)) with self.assertRaises(Exception) as cm: yelp._generate_business_search_url(term='italian', price='3,4,5') error_message = "The price parameter can be 1, 2, 3, 4, or some comma-separated combination (e.g. 1,2,3). You used: 3,4,5" self.assertEqual(error_message, str(cm.exception)) with self.assertRaises(Exception) as cm: yelp._generate_business_search_url(term='italian', price='0') error_message = "The price parameter can be 1, 2, 3, 4, or some comma-separated combination (e.g. 1,2,3). You used: 0" self.assertEqual(error_message, str(cm.exception))
def test_yelp_generate_business_search_url_categories_error(self): with self.assertRaises(Exception) as cm: yelp._generate_business_search_url(categories='blah,italian') error_message = '"blah" is not a valid category because it isn\'t in the yelp.get_categories() list. Please make sure that the following categories are valid (with a comma separating each of them): blah,italian' self.assertEqual(error_message, str(cm.exception))
def test_yelp_generate_business_search_url_categories(self): goal_url = 'https://api.yelp.com/v3/businesses/search?location=Evanston%2C+IL&limit=8&term=chinese&categories=thai,vietnamese' url = yelp._generate_business_search_url(limit=8, term='chinese', categories='thai,vietnamese') self.assertEqual(url, goal_url)
def test_get_categories(self): goal_url = 'https://api.yelp.com/v3/businesses/search?location=Berkeley%2C+CA&limit=10&categories=vietnamese,thai' url = yelp._generate_business_search_url(location='Berkeley, CA', categories='vietnamese,thai') self.assertEqual(url, goal_url)