Example #1
0
    def test_filter_reviews_by_status(self):
        url = reverse('dashboard:reviews-list')

        user1 = UserFactory()
        user2 = UserFactory()

        review1 = ProductReviewFactory(user=user1, status=1)
        review2 = ProductReviewFactory(user=user2, status=0)
        review3 = ProductReviewFactory(user=user2, status=2)

        response = self.get(url, params={'status': 0})
        self.assertEqual(len(response.context['review_list']), 1)
        self.assertEqual(response.context['review_list'][0], review2)

        response = self.get(url, params={'status': 1})
        self.assertEqual(len(response.context['review_list']), 1)
        self.assertEqual(response.context['review_list'][0], review1)

        response = self.get(url, params={'status': 2})
        self.assertEqual(len(response.context['review_list']), 1)
        self.assertEqual(response.context['review_list'][0], review3)

        response = self.get(url, params={'status': 3})
        reviews = response.context['review_list']
        self.assertTrue(review1 in reviews)
Example #2
0
 def setUp(self):
     self.product = create_product()
     self.user = UserFactory()
     self.voter = UserFactory()
     self.review = self.product.reviews.create(title='This is nice',
                                               score=3,
                                               body="This is the body",
                                               user=self.user)
Example #3
0
    def test_is_available_to_different_users(self):
        users, order = [UserFactory(), UserFactory()], OrderFactory()
        for user in users:
            is_voucher_available_to_user, __ = self.voucher.is_available_to_user(user=user)
            self.assertTrue(is_voucher_available_to_user)

            self.voucher.record_usage(order, user)
            is_voucher_available_to_user, __ = self.voucher.is_available_to_user(user=user)
            self.assertFalse(is_voucher_available_to_user)
Example #4
0
    def setUp(self):
        super(IndexViewTests, self).setUp()
        for i in range(1, 25):
            UserFactory(is_active=True)
        for i in range(1, 25):
            UserFactory(is_active=False)

        user_queryset = User.objects.all()
        self.active_users_ids = user_queryset.filter(
            is_active=True).values_list('id', flat=True)
        self.inactive_users_ids = user_queryset.filter(
            is_active=False).values_list('id', flat=True)
Example #5
0
 def setUp(self):
     UserFactory(username='******',
                 email='*****@*****.**',
                 first_name='Lars',
                 last_name='van der Berg')
     UserFactory(username='******',
                 email='*****@*****.**',
                 first_name='Owen',
                 last_name='Davies')
     UserFactory(username='******',
                 email='*****@*****.**',
                 first_name='Rob Alan',
                 last_name='Lewis')
     super(SearchTests, self).setUp()
Example #6
0
    def test_is_available_to_a_user_once(self):
        user, order = UserFactory(), OrderFactory()
        is_voucher_available_to_user, __ = self.voucher.is_available_to_user(user=user)
        self.assertTrue(is_voucher_available_to_user)

        self.voucher.record_usage(order, user)
        is_voucher_available_to_user, __ = self.voucher.is_available_to_user(user=user)
        self.assertFalse(is_voucher_available_to_user)
Example #7
0
 def setUp(self):
     self.user = UserFactory()
     self.product = create_product()
     self.stockrecord = create_stockrecord(self.product, num_in_stock=0)
     product_page = self.app.get(self.product.get_absolute_url(),
                                 user=self.user)
     form = product_page.forms['alert_form']
     form.submit()
Example #8
0
    def test_bulk_editing_review_status(self):
        user1 = UserFactory()
        user2 = UserFactory()

        ProductReviewFactory(pk=1, user=user1, status=0)
        ProductReviewFactory(pk=2, user=user2, status=0)
        ProductReviewFactory(pk=3, user=user2, status=0)

        assert (ProductReview.objects.count() == 3)

        list_page = self.get(reverse('dashboard:reviews-list'))
        form = list_page.forms[1]
        form['selected_review'] = [3, 2]
        form.submit('update')

        self.assertEqual(ProductReview.objects.get(pk=1).status, 0)
        self.assertEqual(ProductReview.objects.get(pk=2).status, 1)
        self.assertEqual(ProductReview.objects.get(pk=3).status, 1)
Example #9
0
    def test_num_orders(self):
        voucherset = VoucherSetFactory()
        assert voucherset.num_orders == 0

        order = OrderFactory()
        user, order = UserFactory(), OrderFactory()
        voucher = voucherset.vouchers.first()
        voucher.record_usage(order, user)
        assert voucherset.num_orders == 1
Example #10
0
    def test_notify_a_single_user(self):
        user = UserFactory()
        subj = "Hello you!"
        body = "This is the notification body."

        services.notify_user(user, subj, body=body)
        user_notification = Notification.objects.get(recipient=user)
        self.assertEqual(user_notification.subject, subj)
        self.assertEqual(user_notification.body, body)
Example #11
0
    def test_notify_a_set_of_users(self):
        users = UserFactory.create_batch(3)
        subj = "Hello everyone!"
        body = "This is the notification body."

        services.notify_users(User.objects.all(), subj, body=body)
        for user in users:
            user_notification = Notification.objects.get(recipient=user)
            self.assertEqual(user_notification.subject, subj)
            self.assertEqual(user_notification.body, body)
Example #12
0
 def setUp(self):
     self.product = create_product()
     self.user = UserFactory(first_name="Tom", last_name="Thumb")
     self.data = {
         'product': self.product,
         'title': 'This product is lovely',
         'body': 'I really like this cheese',
         'score': 0,
         'user': self.user
     }
Example #13
0
    def test_filter_reviews_by_keyword(self):
        url = reverse('dashboard:reviews-list')

        user1 = UserFactory()
        user2 = UserFactory()

        review1 = ProductReviewFactory(user=user1, title='Sexy Review')
        review2 = ProductReviewFactory(user=user2,
                                       title='Anry Review',
                                       body='argh')
        ProductReviewFactory(user=user2, title='Lovely Thing')

        response = self.get(url, params={'keyword': 'argh'})
        self.assertEqual(len(response.context['review_list']), 1)
        self.assertEqual(response.context['review_list'][0], review2)

        response = self.get(url, params={'keyword': 'review'})
        self.assertQuerysetContains(response.context['review_list'],
                                    [review1, review2])
Example #14
0
    def test_can_add_a_review_when_signed_in(self):
        user = UserFactory()
        detail_page = self.app.get(self.product.get_absolute_url(), user=user)
        add_review_page = detail_page.click(linkid="write_review")
        form = add_review_page.forms['add_review_form']
        form['title'] = 'This is great!'
        form['score'] = 5
        form['body'] = 'Loving it, loving it, loving it'
        form.submit()

        self.assertEqual(1, self.product.reviews.all().count())
Example #15
0
    def test_filter_reviews_by_name(self):
        user1 = UserFactory(first_name='Peter', last_name='Griffin')
        user2 = UserFactory(first_name='Lois', last_name='Griffin')

        ProductReviewFactory(user=user1, status=0)
        ProductReviewFactory(user=user2, status=0)
        ProductReviewFactory(user=user2, status=0)

        url = reverse('dashboard:reviews-list') + '?name=peter'
        response = self.get(url)

        self.assertEqual(len(response.context['review_list']), 1)
        self.assertEqual(response.context['review_list'][0].user, user1)

        url = reverse('dashboard:reviews-list') + '?name=lois+griffin'
        response = self.get(url)

        self.assertEqual(len(response.context['review_list']), 2)
        for review in response.context['review_list']:
            self.assertEqual(review.user, user2)
Example #16
0
    def test_hurry_mode_set_when_stock_low(self):
        # Two alerts, 1 item in stock. Hurry mode should be set.
        create_stockrecord(self.product, num_in_stock=1)
        ProductAlert.objects.create(user=self.user, product=self.product)
        ProductAlert.objects.create(user=UserFactory(), product=self.product)

        send_product_alerts(self.product)

        self.assertEqual(2, len(mail.outbox))
        self.assertIn(
            'Beware that the amount of items in stock is limited',
            mail.outbox[0].body)
Example #17
0
    def test_hurry_mode_set_multiple_stockrecords(self):
        # Two stockrecords, low stock on both. Hurry mode should be set.
        create_stockrecord(self.product, num_in_stock=1)
        create_stockrecord(self.product, num_in_stock=1)
        ProductAlert.objects.create(user=self.user, product=self.product)
        ProductAlert.objects.create(user=UserFactory(), product=self.product)

        send_product_alerts(self.product)

        self.assertIn(
            'Beware that the amount of items in stock is limited',
            mail.outbox[0].body)
Example #18
0
 def test_adding_a_review_sends_a_signal(self):
     review_user = UserFactory()
     detail_page = self.app.get(self.product.get_absolute_url(),
                                user=review_user)
     with mock_signal_receiver(review_added) as receiver:
         add_review_page = detail_page.click(linkid="write_review")
         form = add_review_page.forms['add_review_form']
         form['title'] = 'This is great!'
         form['score'] = 5
         form['body'] = 'Loving it, loving it, loving it'
         form.submit()
         self.assertEqual(receiver.call_count, 1)
     self.assertEqual(1, self.product.reviews.all().count())
    def test_remove_dashboard_permission(self):
        user = UserFactory(is_staff=False)
        permission = PermissionFactory(codename='dashboard_access',
                                       content_type=ContentType.objects.get(
                                           app_label='partner',
                                           model='partner'))
        user.user_permissions.add(permission)
        partner = PartnerFactory()
        partner.users.add(user)

        view = views.PartnerUserUnlinkView()
        view.unlink_user(user, partner)

        self.assertEqual(partner.users.count(), 0)
        self.assertTrue(Permission.objects.filter(pk=permission.pk).exists())
Example #20
0
    def test_cleans_title(self):
        product = create_product()
        reviewer = UserFactory()
        data = {
            'title': '  This product is lovely',
            'body': 'I really like this cheese',
            'score': 0,
            'name': 'JR Hartley',
            'email': '*****@*****.**'
        }
        form = forms.ProductReviewForm(product=product,
                                       user=reviewer,
                                       data=data)

        assert form.is_valid()

        review = form.save()
        assert review.title == "This product is lovely"
Example #21
0
class AuthBackendTestCase(TestCase):
    def setUp(self):
        self.user = UserFactory(email='*****@*****.**', is_staff=True)
        self.user.set_password('letmein')
        self.user.save()
        self.backend = EmailBackend()

    def test_authentication_method_signature_post_django_1_11(self):
        auth_result = self.backend.authenticate(None, '*****@*****.**',
                                                'letmein')
        self.assertEqual(auth_result, self.user)

    def test_inactive_users_cannot_authenticate(self):
        self.user.is_active = False
        self.user.save()

        auth_result = self.backend.authenticate(None, '*****@*****.**',
                                                'letmein')
        self.assertIsNone(auth_result)
Example #22
0
 def setUp(self):
     self.user = UserFactory()
     services.notify_user(self.user, "Test message")
Example #23
0
 def setUp(self):
     self.user = UserFactory()
     self.country = models.Country.objects.create(
         iso_3166_1_a2='GB', name="UNITED KINGDOM")
Example #24
0
 def setUp(self):
     user = UserFactory()
     product = create_product()
     self.wishlist = WishListFactory(owner=user)
     self.wishlist.add(product)
Example #25
0
 def setUp(self):
     self.staff = UserFactory(is_staff=True)
     create_from_breadcrumbs('A > B > C')
Example #26
0
 def setUp(self):
     self.customer = UserFactory(username='******',
                                 email='*****@*****.**',
                                 password='******')
     super(TestDetailViewForStaffUser, self).setUp()
Example #27
0
 def setUp(self):
     self.offer = models.ConditionalOffer(max_user_applications=1)
     self.user = UserFactory()
Example #28
0
 def setUp(self):
     user = UserFactory()
     product = create_product()
     self.alert = ProductAlert.objects.create(user=user,
                                              product=product)
Example #29
0
 def setUp(self):
     self.user = UserFactory(email='*****@*****.**', is_staff=True)
     self.user.set_password('letmein')
     self.user.save()
     self.backend = EmailBackend()
Example #30
0
 def setUp(self):
     self.user = UserFactory()
     self.product = create_product()
     create_stockrecord(self.product, num_in_stock=1)