コード例 #1
0
    def test_create_subscription(self):
        with mock.patch('stripe.Customer.create') as create_mock:
            cust_data = {'description': 'test user', 'email': '*****@*****.**',
                         'card': '4242', 'plan': 'gold'}
            Customer.create("subscription", **cust_data)

            create_mock.assert_called_with(**cust_data)
コード例 #2
0
ファイル: testCustomer.py プロジェクト: ujrc/Realpython_book3
    def test_create_subscription(self):
        with mock.patch('stripe.Customer.create') as create_mock:
            cust_data = {'description': 'test user', 'email': '*****@*****.**',
                         'card': '4242', 'plan': 'gold'}
            Customer.create("subscription", **cust_data)

            create_mock.assert_called_with(**cust_data)
コード例 #3
0
ファイル: testCustomer.py プロジェクト: Copser/DjanCommerce
    def test_create_subscription(self):
        """TODO: Docstring for test_create_subscription.
        :returns: Mock are User to see will he be subscribed,
        and testing user create bill

        """
        with mock.patch('stripe.Customer.create') as create_mock:
            cust_data = {'description': 'test user', 'email': '*****@*****.**',
                         'card': '4242', 'plan': 'gold'}
            Customer.create('subscription', **cust_data)

            create_mock.assert_called_with(**cust_data)

        def test_create_one_time_bill(self):
            """TODO: Docstring for test_create_one_time_bill.
            :returns: TODO

            """
            with mock.patch('stripe.Charge.create') as charge_mock:
                cust_data = {'description': 'email',
                             'card': '1234',
                             'amount': '5000',
                             'currency': 'usd'}
                Customer.create("one_time", **cust_data)

                charge_mock.assert_called_with(**cust_data)
コード例 #4
0
ファイル: tests.py プロジェクト: Alberick0/part3_realpython
 def test_Create_one_time_bill(self):
     with mock.patch('stripe.Charge.create') as charge_mock:
         cust_data = {'description': 'email',
                      'card': '1234',
                      'amount': '5000',
                      'currency': 'usd'}
         Customer.create('one_time', **cust_data)
         charge_mock.assert_called_with(**cust_data)
コード例 #5
0
    def test_create_one_time_bill(self):
        with mock.patch('stripe.Charge.create') as charge_mock:
            cust_data = {'description': 'email',
                         'card': '1234',
                         'amount': '5000',
                         'currency': 'usd'}
            Customer.create("one_time", **cust_data)

            charge_mock.assert_called_with(**cust_data)
コード例 #6
0
ファイル: testCustomer.py プロジェクト: Copser/DjanCommerce
        def test_create_one_time_bill(self):
            """TODO: Docstring for test_create_one_time_bill.
            :returns: TODO

            """
            with mock.patch('stripe.Charge.create') as charge_mock:
                cust_data = {'description': 'email',
                             'card': '1234',
                             'amount': '5000',
                             'currency': 'usd'}
                Customer.create("one_time", **cust_data)

                charge_mock.assert_called_with(**cust_data)
コード例 #7
0
 def test_create_yearly_billing(self):
     with mock.patch('stripe.Customer.create') as create_mock:
         
         cust_data = {'description': 'test user', 'email': '*****@*****.**',
                      'card': '4242', 'plan': 'platinum'}
         cust = Customer.create("yearly", **cust_data)
         
         create_mock.assert_called_with(**cust_data)
コード例 #8
0
 def test_create_monthly_billing(self):
     
     with mock.patch('stripe.Charge.create') as charge_mock:
         
         cust_data = {'description': 'test user', 'email': '*****@*****.**',
                      'card': '4242', 'plan': 'gold'}
         
         cust = Customer.create("monthly", **cust_data)
         
         charge_mock.assert_called_with(**cust_data)
コード例 #9
0
def post_user(request):
    form = UserForm(request.data)

    if form.is_valid():
        try:
            # update based on your billing method (subscription vs one time)
            customer = Customer.create(
                "subscription",
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )
        except Exception as exp:
            form.addError(exp)

        cd = form.cleaned_data
        try:
            with transaction.atomic():
                user = User.create(cd['name'],
                                   cd['email'],
                                   cd['password'],
                                   cd['last_4_digits'],
                                   stripe_id='')

                if customer:
                    user.stripe_id = customer.id
                    user.save()
                else:
                    UnpaidUsers(email=cd['email']).save()

        except IntegrityError:
            form.addError(cd['email'] + ' is already a member')
        else:
            request.session['user'] = user.pk
            resp = {"status": "ok", "url": '/'}
            return Response(resp, content_type="application/json")

        resp = {"status": "fail", "errors": form.non_field_errors()}
        return Response(resp)
    else:  # for not valid
        resp = {"status": "form-invalid", "errors": form.errors}
        return Response(resp)
コード例 #10
0
ファイル: json_views.py プロジェクト: Munk801/book3-exercises
def post_user(request):
    form = UserForm(request.DATA)

    print("in post user")
    if form.is_valid():
        try:
            # update based on your billing method (subscription vs one time)
            customer = Customer.create(
                "subscription",
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )
        except Exception as exp:
            form.addError(exp)

        cd = form.cleaned_data
        try:
            with transaction.atomic():
                user = User.create(
                    cd['name'], cd['email'],
                    cd['password'], cd['last_4_digits'])

                if customer:
                    user.stripe_id = customer.id
                    user.save()
                else:
                    UnpaidUsers(email=cd['email']).save()
        except IntegrityError as e:
            print("----------Integristy error")
            print(e)
            form.addError(cd['email'] + ' is already a member')
        else:
            request.session['user'] = user.pk
            resp = {"status": "ok", "url": '/'}
            return Response(resp, content_type="application/json")

        resp = {"status": "fail", "errors": form.non_field_errors()}
        return Response(resp)
    else:  # for not valid
        resp = {"status": "form-invalid", "errors": form.errors}
        return Response(resp)
コード例 #11
0
 def test_create_subscription(self):
     with mock.patch("stripe.Customer.create") as create_mock:
         cust_data = {"description": "test_user", "email": "*****@*****.**", "card": "4242", "plan": "gold"}
         Customer.create("subscription", **cust_data)
         create_mock.assert_called_with(**cust_data)
コード例 #12
0
 def test_create_one_time_bill(self):
     with mock.patch("stripe.Charge.create") as charge_mock:
         cust_data = {"description": "email", "card": "1234", "amount": "5000", "currency": "usd"}
         Customer.create("one_time", **cust_data)
         charge_mock.assert_called_with(**cust_data)