def test_raises_error_if_name_is_blank(self): place = PizzaPlace(yelp_url=self.prince_street_pizza_url) self.assertRaises(IntegrityError, place.save)
def test_raises_error_if_url_is_blank(self): place = PizzaPlace(name=self.pizza_name1) self.assertRaises(IntegrityError, place.save)
def test_string_representation_of_pizza_place(self): place = PizzaPlace(name=self.pizza_name1, yelp_url=self.prince_street_pizza_url) self.assertEquals(self.pizza_name1, str(place))
def test_name_length_invalid_if_over_500_char(self): name = "x" * 501 place = PizzaPlace(name=name, yelp_url=self.prince_street_pizza_url) self.assertRaises(DataError, place.save)
def test_creation_of_pizza_place_with_name(self): pizza_place = PizzaPlace(name=self.pizza_name1, yelp_url=self.prince_street_pizza_url) self.assertEquals(pizza_place.name, self.pizza_name1)
def test_url_must_be_unique(self): PizzaPlace.objects.create(name="Much Pizza", yelp_url=self.prince_street_pizza_url) place2 = PizzaPlace(name=self.pizza_name1, yelp_url=self.prince_street_pizza_url) self.assertRaises(IntegrityError, place2.save)
def test_service_gets_info_from_yelp_client(self): pizzaplace = PizzaPlace(name='Prince Street Pizza', yelp_url=valid_yelp_url) client_info = YelpService(pizzaplace).get_decorated_pizza_place() self.assertEquals('🍕🍕🍕🍕', client_info.pizza_place_rating())
def test_pizza_is_real(self): pizza_place = PizzaPlace() self.assertIsInstance(pizza_place, PizzaPlace)
def test_no_error_raised_if_url_contains_no_search_query_params(self): pizza_place = PizzaPlace(name="Oh Pizza!", yelp_url='https://www.yelp.com/biz/lombardis-pizza-new-york') errors_raised_by_pizza_place = pizza_place.full_clean() self.assertIsNone(errors_raised_by_pizza_place)
def test_error_raised_if_url_has_multiple_biznames(self): pizza_place = PizzaPlace(name="Oh Pizza!", yelp_url='https://www.yelp.com/biz/lombardis-pizza-new-york/some-other-stuff') with self.assertRaisesRegexp(ValidationError, self.invalid_url_format_message): pizza_place.full_clean()
def test_error_raised_if_url_doesnt_contain_valid_business_name(self): pizza_place = PizzaPlace(name="Oh Pizza!", yelp_url='https://www.yelp.com/biz/imaginary-pizza/') with self.assertRaisesRegexp(ValidationError, self.invalid_url_format_message): pizza_place.full_clean()
def test_error_raised_if_no_biz_key_in_pizza_place_url(self): pizza_place = PizzaPlace(name="Oh Pizza!", yelp_url='https://www.yelp.com/prince-st-pizza-new-york') with self.assertRaisesRegexp(ValidationError, self.invalid_url_format_message): pizza_place.full_clean()
def test_error_raised_if_no_corresponding_business_on_yelp(self): pizza_place = PizzaPlace(name="Name", yelp_url="http://yelp.com/biz/not-a-real-business") with self.assertRaisesRegexp(ValidationError, 'Yelp Business not found on Yelp.com'): pizza_place.full_clean()
def test_error_raised_if_not_a_yelp_url(self): pizza_place = PizzaPlace(name="Name", yelp_url="http://notyelpatall.com/biz/prince-st-pizza-new-york") with self.assertRaisesRegexp(ValidationError, self.invalid_url_format_message): pizza_place.full_clean()
def test_error_raised_on_nonsense_url(self): pizza_place = PizzaPlace(name="Name", yelp_url="not.a/url?") with self.assertRaisesRegexp(ValidationError, self.invalid_url_format_message): pizza_place.full_clean()