예제 #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)
예제 #2
0
class TestASuccessfulTransfer(TestCase):
    def setUp(self):
        self.user = UserFactory(username="******")
        source = AccountFactory(primary_user=None, credit_limit=None)
        destination = AccountFactory()
        self.transfer = Transfer.objects.create(source,
                                                destination,
                                                D('10.00'),
                                                user=self.user)

    def test_creates_2_transactions(self):
        self.assertEqual(2, self.transfer.transactions.all().count())

    def test_records_the_transferred_amount(self):
        self.assertEqual(D('10.00'), self.transfer.amount)

    def test_updates_source_balance(self):
        self.assertEqual(-D('10.00'), self.transfer.source.balance)

    def test_updates_destination_balance(self):
        self.assertEqual(D('10.00'), self.transfer.destination.balance)

    def test_cannot_be_deleted(self):
        with self.assertRaises(RuntimeError):
            self.transfer.delete()

    def test_records_static_user_information_in_case_user_is_deleted(self):
        self.assertEqual('barry', self.transfer.authorisor_username)
        self.user.delete()
        transfer = Transfer.objects.get(id=self.transfer.id)
        self.assertEqual('barry', transfer.authorisor_username)
예제 #3
0
    def test_can_only_be_authorised_by_primary_user_when_set(self):
        primary = UserFactory()
        other = UserFactory()
        self.account.primary_user = primary
        self.account.save()

        self.assertTrue(self.account.can_be_authorised_by(primary))
        self.assertFalse(self.account.can_be_authorised_by(other))
예제 #4
0
 def setUp(self):
     self.user = UserFactory(username="******")
     source = AccountFactory(primary_user=None, credit_limit=None)
     destination = AccountFactory()
     self.transfer = Transfer.objects.create(source,
                                             destination,
                                             D('10.00'),
                                             user=self.user)
예제 #5
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)
예제 #6
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().setUp()
예제 #7
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)
예제 #8
0
    def setUp(self):
        super().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)
예제 #9
0
    def test_can_only_be_authorised_by_secondary_users_when_set(self):
        self.account.save()
        users = [UserFactory(), UserFactory()]
        other = UserFactory()
        for user in users:
            self.account.secondary_users.add(user)

        for user in users:
            self.assertTrue(self.account.can_be_authorised_by(user))
        self.assertFalse(self.account.can_be_authorised_by(other))
예제 #10
0
    def test_invoice_document_is_not_accessible_via_url(self):
        invoice = self._test_invoice_is_created()

        another_user = UserFactory(username='******')
        staff_user = UserFactory(is_staff=True)
        superuser = UserFactory(is_superuser=True)

        # Invoice document is not accessible via url for any user
        for user in [self.user, another_user, staff_user, superuser]:
            with self.assertRaisesMessage(ValueError, 'This file is not accessible via a URL.'):
                self.app.get(invoice.document.url, user=user)
예제 #11
0
 def test_is_not_deleted_when_the_authorisor_is_deleted(self):
     user = UserFactory()
     source = AccountFactory(credit_limit=None,
                             primary_user=user,
                             start_date=None,
                             end_date=None)
     destination = AccountFactory(start_date=None, end_date=None)
     txn = Transfer.objects.create(source,
                                   destination,
                                   D('20.00'),
                                   user=user)
     self.assertEqual(2, txn.transactions.all().count())
     user.delete()
     self.assertEqual(2, txn.transactions.all().count())
예제 #12
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()
예제 #13
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)
예제 #14
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])
예제 #15
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)
예제 #16
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
예제 #17
0
    def setUp(self):
        super().setUp()
        self.user = UserFactory()
        self.order = create_order(number='000042', user=self.user)

        LegalEntityAddressFactory(
            legal_entity=LegalEntityFactory(),
            country=CountryFactory(),
        )
예제 #18
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)
예제 #19
0
 def setUp(self):
     self.user = UserFactory()
     self.source = AccountFactory(credit_limit=None, primary_user=None)
     self.destination = AccountFactory()
     self.transfer = facade.transfer(self.source,
                                     self.destination,
                                     D('100'),
                                     user=self.user,
                                     description="Give money to customer")
예제 #20
0
 def test_account_exception_raised_for_runtime_error(self):
     user = UserFactory()
     source = AccountFactory(credit_limit=None)
     destination = AccountFactory()
     with mock.patch('izi_accounts.abstract_models.PostingManager._wrap'
                     ) as mock_method:
         mock_method.side_effect = RuntimeError()
         with self.assertRaises(exceptions.AccountException):
             facade.transfer(source, destination, D('100'), user)
예제 #21
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)
예제 #22
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
     }
예제 #23
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)
예제 #24
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())
예제 #25
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)
예제 #26
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)
예제 #27
0
 def test_is_permitted(self):
     self.user = UserFactory()
     now = timezone.now()
     source = AccountFactory(primary_user=None, credit_limit=None)
     destination = AccountFactory(end_date=now - timezone.timedelta(days=1))
     try:
         Transfer.objects.create(source,
                                 destination,
                                 D('20.00'),
                                 user=self.user)
     except exceptions.AccountException as e:
         self.fail("Transfer failed: %s" % e)
예제 #28
0
 def test_no_transaction_created_when_exception_raised(self):
     user = UserFactory()
     source = AccountFactory(credit_limit=None)
     destination = AccountFactory()
     with mock.patch('izi_accounts.abstract_models.PostingManager._wrap'
                     ) as mock_method:
         mock_method.side_effect = RuntimeError()
         try:
             facade.transfer(source, destination, D('100'), user)
         except Exception:
             pass
     self.assertEqual(0, Transfer.objects.all().count())
     self.assertEqual(0, Transaction.objects.all().count())
예제 #29
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())
예제 #30
0
    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())