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)
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)
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)
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)
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()
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)
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()
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)
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
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)
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)
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 }
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])
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())
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)
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)
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)
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())
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"
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)
def setUp(self): self.user = UserFactory() services.notify_user(self.user, "Test message")
def setUp(self): self.user = UserFactory() self.country = models.Country.objects.create( iso_3166_1_a2='GB', name="UNITED KINGDOM")
def setUp(self): user = UserFactory() product = create_product() self.wishlist = WishListFactory(owner=user) self.wishlist.add(product)
def setUp(self): self.staff = UserFactory(is_staff=True) create_from_breadcrumbs('A > B > C')
def setUp(self): self.customer = UserFactory(username='******', email='*****@*****.**', password='******') super(TestDetailViewForStaffUser, self).setUp()
def setUp(self): self.offer = models.ConditionalOffer(max_user_applications=1) self.user = UserFactory()
def setUp(self): user = UserFactory() product = create_product() self.alert = ProductAlert.objects.create(user=user, product=product)
def setUp(self): self.user = UserFactory(email='*****@*****.**', is_staff=True) self.user.set_password('letmein') self.user.save() self.backend = EmailBackend()
def setUp(self): self.user = UserFactory() self.product = create_product() create_stockrecord(self.product, num_in_stock=1)