def test_no_address_no_geocode(self): vendor = Vendor(name="Test Vendor") vendor.save() self.assertEqual(vendor.location, None) self.assertEqual(vendor.neighborhood, None) self.assertFalse(vendor.needs_geocoding())
def test_address_causes_geocode(self): geocode.geocode_address = Mock(return_value=(100, 100, "South Philly")) vendor = Vendor(name="Test Vendor", address="300 Christian St, Philadelphia, PA, 19147") vendor.save() self.assertNotEqual(vendor.location, None) self.assertNotEqual(vendor.neighborhood, None)
def run_apply_geocoding_test(self, geocoder_return_value, location, neighborhood): geocode.geocode_address = Mock(return_value=geocoder_return_value) vendor = Vendor(name="Test Vendor", address="123 Main Street") vendor.save() vendor.apply_geocoding() self.assertEqual(vendor.location, location) if neighborhood: self.assertEqual(vendor.neighborhood.name, neighborhood) else: self.assertEqual(vendor.neighborhood, neighborhood)
def test_needs_geocoding(self): vendor = Vendor(name="Test Vendor") self.assertFalse(vendor.needs_geocoding()) vendor.address = "300 Christian St, Philadelphia, PA, 19147" self.assertTrue(vendor.needs_geocoding()) vendor.save() self.assertFalse(vendor.needs_geocoding())
def setUp(self): self.user = get_user() self.vendor = Vendor(name="Test Vendor", address="123 Main St") self.vendor.save() self.vegan_dish1 = VeganDish(name="Tofu Scramble") self.vegan_dish1.save() self.vegan_dish2 = VeganDish(name="Tempeh Hash") self.vegan_dish2.save() self.review1 = Review(vendor=self.vendor, author=self.user, content="ahhhh") self.review1.save() self.vendor.vegan_dishes.add(self.vegan_dish1) self.vendor.vegan_dishes.add(self.vegan_dish2)
def test_newly_approved_vendor_gets_emailed(self): """ Test that the email function is called once when a vendor is approved and then not again if its approval status changes, even if to approved. """ # not called because it is not yet approved vendor = Vendor(name="The Test Vendor", address="123 Main St", submitted_by=self.user) vendor.save() email.send_new_vendor_approval.assert_not_called() # called now because it was approved vendor.approval_status = SF.APPROVED vendor.save() email.send_new_vendor_approval.assert_called_with(vendor) # reset mock function to test it doesn't get called again email.send_new_vendor_approval.reset_mock() # not called when approval status changes away from approved vendor.approval_status = SF.QUARANTINED vendor.save() email.send_new_vendor_approval.assert_not_called() # not called when approval status is changed back to approved vendor.approval_status = SF.APPROVED vendor.save() email.send_new_vendor_approval.assert_not_called()
def test_food_and_atmosphere_rating(self): vendor = Vendor(name="Test Vendor") vendor.save() self.assertEqual(vendor.food_rating(), None) self.assertEqual(vendor.atmosphere_rating(), None) Review(vendor=vendor, approval_status=SF.APPROVED, food_rating=1, atmosphere_rating=1, author=self.user).save() self.assertEqual(vendor.food_rating(), 1) self.assertEqual(vendor.atmosphere_rating(), 1) review2 = Review(vendor=vendor, approval_status=SF.PENDING, food_rating=4, atmosphere_rating=4, author=self.user) review2.save() self.assertEqual(vendor.food_rating(), 1) self.assertEqual(vendor.atmosphere_rating(), 1) review2.approval_status = SF.APPROVED review2.save() # Floored Average self.assertEqual(vendor.food_rating(), 2) self.assertEqual(vendor.atmosphere_rating(), 2) review3 = Review(vendor=vendor, approval_status=SF.APPROVED, food_rating=4, atmosphere_rating=4, author=self.user) review3.save() # Floored Average self.assertEqual(vendor.food_rating(), 3) self.assertEqual(vendor.atmosphere_rating(), 3)
class VendorVeganDishValidationTest(TestCase): """ Tests that trying to delete vegan dish relationships for vendors that have reviews will signal an error. """ def setUp(self): self.user = get_user() self.vendor = Vendor(name="Test Vendor", address="123 Main St") self.vendor.save() self.vegan_dish1 = VeganDish(name="Tofu Scramble") self.vegan_dish1.save() self.vegan_dish2 = VeganDish(name="Tempeh Hash") self.vegan_dish2.save() self.review1 = Review(vendor=self.vendor, author=self.user, content="ahhhh") self.review1.save() self.vendor.vegan_dishes.add(self.vegan_dish1) self.vendor.vegan_dishes.add(self.vegan_dish2) def test_can_delete_relationship_without_any_reviews(self): self.assertEqual(self.vendor.vegan_dishes.count(), 2) self.vendor.vegan_dishes.remove(self.vegan_dish1) self.assertEqual(self.vendor.vegan_dishes.count(), 1) def test_can_delete_relationship_with_reviews_on_other_vegan_dish(self): self.review1.best_vegan_dish = self.vegan_dish1 self.review1.save() self.assertEqual(self.vendor.vegan_dishes.count(), 2) self.vendor.vegan_dishes.remove(self.vegan_dish2) self.assertEqual(self.vendor.vegan_dishes.count(), 1) def test_can_clear_relationship_without_any_reviews(self): self.assertEqual(self.vendor.vegan_dishes.count(), 2) self.vendor.vegan_dishes.clear() self.assertEqual(self.vendor.vegan_dishes.count(), 0) def test_cant_clear_relationship_with_any_reviews(self): self.review1.best_vegan_dish = self.vegan_dish1 self.review1.save() self.assertRaises(ValidationError, self.vendor.vegan_dishes.clear) def test_cant_delete_relationship_with_reviews(self): self.review1.best_vegan_dish = self.vegan_dish1 self.review1.save() self.assertRaises(ValidationError, self.vendor.vegan_dishes.remove, self.vegan_dish1)
def test_food_and_atmosphere_rating(self): vendor = Vendor(name="Test Vendor") vendor.save() self.assertEqual(vendor.food_rating(), None) self.assertEqual(vendor.atmosphere_rating(), None) Review(vendor=vendor, approved=True, food_rating=1, atmosphere_rating=1, author=self.user).save() self.assertEqual(vendor.food_rating(), 1) self.assertEqual(vendor.atmosphere_rating(), 1) review2 = Review(vendor=vendor, approved=False, food_rating=4, atmosphere_rating=4, author=self.user) review2.save() self.assertEqual(vendor.food_rating(), 1) self.assertEqual(vendor.atmosphere_rating(), 1) review2.approved = True review2.save() # Floored Average self.assertEqual(vendor.food_rating(), 2) self.assertEqual(vendor.atmosphere_rating(), 2) review3 = Review(vendor=vendor, approved=True, food_rating=4, atmosphere_rating=4, author=self.user) review3.save() # Floored Average self.assertEqual(vendor.food_rating(), 3) self.assertEqual(vendor.atmosphere_rating(), 3)