Exemple #1
0
 def test_with_without_review_with_all_approved_reviews(self):
     v1 = Vendor.objects.create(name='tv1', approval_status=SF.APPROVED)
     v2 = Vendor.objects.create(name='tv2', approval_status=SF.APPROVED)
     Review.objects.create(vendor=v1, approval_status=SF.APPROVED,
                           author=get_user())
     Review.objects.create(vendor=v2, approval_status=SF.APPROVED,
                           author=get_user())
     self.assertVendorCounts(0, 2)
    def test_search_by_name_for_substring(self):
        request = self.factory.get("", {"current_query": "Bar"})

        request.user = get_user()

        response = views.vendors(request)

        self.assertEqual(response.content.count("Showing 1 vendors"), 1)

        request = self.factory.get("", {"current_query": "Vendor"})
        request.user = get_user()

        response = views.vendors(request)
        self.assertEqual(response.content.count("Showing 4 vendors"), 1)
 def test_pending_approval_count_all_approved(self):
     Vendor.objects.create(name="Test Vendor",
                           approval_status="approved")
     request = RequestFactory().get('')
     request.user = get_user(is_staff=True)
     response = pending_approval_count(request)
     self.assertEqual(response.content, "0")
 def count_option_elements():
     request = self.factory.get("")
     request.user = get_user()
     response = views.vendors(request)
     content = BeautifulSoup(response.content)
     neighborhood_element = filter(lambda x: x["name"] == "neighborhood", content.find_all("select"))[0]
     return len(neighborhood_element.find_all("option"))
Exemple #5
0
 def test_get_random_unreviewed_mixed_unreviewed_vendors_and_reviewed(self):
     v1 = Vendor.objects.create(name='tv1', approval_status='approved')
     v2 = Vendor.objects.create(name='tv2', approval_status='approved')
     v3 = Vendor.objects.create(name='tv3', approval_status='approved')
     Review.objects.create(vendor=v1, approved=True, author=get_user())
     self.assertIn(Vendor.approved_objects.get_random_unreviewed(),
                   [v2, v3])
    def test_search_by_name_approved_only(self):
        self.v4.approval_status = SF.QUARANTINED
        self.v4.save()

        request = self.factory.get("", {"current_query": "Vendor"})
        request.user = get_user()

        response = views.vendors(request)
        self.assertEqual(response.content.count("Showing 3 vendors"), 1)
 def count_option_elements():
     request = self.factory.get('')
     request.user = get_user()
     response = views.vendors(request)
     content = BeautifulSoup(response.content)
     neighborhood_element = filter(
         lambda x: x['name'] == 'neighborhood',
         content.find_all('select'))[0]
     return len(neighborhood_element.find_all('option'))
    def test_search_by_name_approved_only(self):
        self.v4.approval_status = 'quarantined'
        self.v4.save()

        request = self.factory.get('',
                                   {'current_query': 'Vendor', })
        request.user = get_user()

        response = views.vendors(request)
        self.assertEqual(response.content.count("Showing 3 vendors"), 1)
Exemple #9
0
    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_vendor_list(self):

        south_philly = Neighborhood.objects.create(name="South Philly")
        west_philly = Neighborhood.objects.create(name="West Philly")
        vegan = VegLevel.objects.create(name="vegan", description="vegan")
        vegetarian = VegLevel.objects.create(name="vegetarian",
                                             description="vegetarian")

        model_rows = [
            ("test vendor 1", "123 Main Street", south_philly, "1234567890",
             "www.example.com", vegan, "A great place to eat"),
            ("test vendor 2", "456 Main Street", west_philly, "0987654321",
             "www.example.com", vegetarian, "The food is ok"),
        ]

        expected_data = [
            ['name', 'address', 'neighborhood__name', 'phone', 'website',
             'veg_level__name', 'notes'],
            ["test vendor 1", "123 Main Street", "South Philly", "1234567890",
             "www.example.com", "vegan", "A great place to eat"],
            ["test vendor 2", "456 Main Street", "West Philly", "0987654321",
             "www.example.com", "vegetarian", "The food is ok"]
        ]

        for row in model_rows:
            Vendor.objects.create(name=row[0],
                                  address=row[1],
                                  neighborhood=row[2],
                                  phone=row[3],
                                  website=row[4],
                                  veg_level=row[5],
                                  notes=row[6],
                                  approval_status="approved")

        request = RequestFactory().get('')
        request.user = get_user(is_staff=True)

        response = vendor_list(request)

        self.assertCSVIsCorrect(response, expected_data)
Exemple #11
0
 def setUp(self):
     self.user = get_user()
Exemple #12
0
 def test_get_random_unreviewed_with_only_unapproved_reviews(self):
     v1 = Vendor.objects.create(name='tv1', approval_status=SF.APPROVED)
     Review.objects.create(vendor=v1, approval_status=SF.PENDING,
                           author=get_user())
     self.assertEqual(v1, Vendor.objects.approved().get_random_unreviewed())
Exemple #13
0
 def test_get_random_unreviewed_no_unreviewed_vendors(self):
     v1 = Vendor.objects.create(name='tv1', approval_status=SF.APPROVED)
     Review.objects.create(vendor=v1,  approval_status=SF.APPROVED,
                           author=get_user())
     self.assertEqual(None,
                      Vendor.objects.approved().get_random_unreviewed())
Exemple #14
0
 def test_get_random_unreviewed_mixed_unreviewed_vendors_and_reviewed(self):
     v1 = Vendor.objects.create(name="tv1", approval_status=SF.APPROVED)
     v2 = Vendor.objects.create(name="tv2", approval_status=SF.APPROVED)
     v3 = Vendor.objects.create(name="tv3", approval_status=SF.APPROVED)
     Review.objects.create(vendor=v1, approval_status=SF.APPROVED, author=get_user())
     self.assertIn(Vendor.objects.approved().get_random_unreviewed(), [v2, v3])
Exemple #15
0
 def test_with_without_reviews_no_approved_reviews(self):
     v1 = Vendor.objects.create(name='tv1', approval_status='approved')
     Vendor.objects.create(name='tv2', approval_status='approved')
     Review.objects.create(vendor=v1, author=get_user())
     self.assertVendorCounts(2, 0)
 def test_pending_approval_count_none(self):
     request = RequestFactory().get('')
     request.user = get_user(is_staff=True)
     response = pending_approval_count(request)
     self.assertEqual(response.content, "0")
Exemple #17
0
 def test_with_without_review_with_some_approved_reviews(self):
     v1 = Vendor.objects.create(name="tv1", approval_status=SF.APPROVED)
     v2 = Vendor.objects.create(name="tv2", approval_status=SF.APPROVED)
     Review.objects.create(vendor=v1, approval_status=SF.APPROVED, author=get_user())
     Review.objects.create(vendor=v2, approval_status=SF.PENDING, author=get_user())
     self.assertVendorCounts(1, 1)
Exemple #18
0
 def setUp(self):
     # mock the email function so that we can just see if it's called
     email.send_new_vendor_approval = Mock()
     self.user = get_user()
     self.user.email = "*****@*****.**"
     self.user.save()
Exemple #19
0
 def test_with_without_review_with_some_approved_reviews(self):
     v1 = Vendor.objects.create(name='tv1', approval_status='approved')
     v2 = Vendor.objects.create(name='tv2', approval_status='approved')
     Review.objects.create(vendor=v1, approved=True, author=get_user())
     Review.objects.create(vendor=v2, approved=False, author=get_user())
     self.assertVendorCounts(1, 1)
Exemple #20
0
 def test_get_random_unreviewed_with_only_unapproved_reviews(self):
     v1 = Vendor.objects.create(name='tv1', approval_status='approved')
     Review.objects.create(vendor=v1, approved=False, author=get_user())
     self.assertEqual(v1, Vendor.approved_objects.get_random_unreviewed())
Exemple #21
0
 def setUp(self):
     self.factory = RequestFactory()
     self.user = get_user()
Exemple #22
0
 def test_with_without_reviews_no_approved_reviews(self):
     v1 = Vendor.objects.create(name="tv1", approval_status=SF.APPROVED)
     Vendor.objects.create(name="tv2", approval_status=SF.APPROVED)
     Review.objects.create(vendor=v1, author=get_user())
     self.assertVendorCounts(2, 0)