• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python factories.SubscriptionFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中silver.tests.factories.SubscriptionFactory的典型用法代码示例。如果您正苦于以下问题:Python SubscriptionFactory类的具体用法?Python SubscriptionFactory怎么用?Python SubscriptionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SubscriptionFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_get_subscription_list

    def test_get_subscription_list(self):
        customer = CustomerFactory.create()
        SubscriptionFactory.create_batch(40, customer=customer)

        url = reverse('subscription-list',
                      kwargs={'customer_pk': customer.pk})

        response = self.client.get(url)

        full_url = None
        for field in response.data:
            full_url = field.get('url', None)
            if full_url:
                break
        if full_url:
            domain = full_url.split('/')[2]
            full_url = full_url.split(domain)[0] + domain + url

        assert response.status_code == status.HTTP_200_OK
        assert response._headers['link'] == \
            ('Link', '<' + full_url + '?page=2; rel="next">, ' +
             '<' + full_url + '?page=1; rel="first">, ' +
             '<' + full_url + '?page=2; rel="last">')

        response = self.client.get(url + '?page=2')

        assert response.status_code == status.HTTP_200_OK
        assert response._headers['link'] == \
            ('Link', '<' + full_url + '; rel="prev">, ' +
             '<' + full_url + '?page=1; rel="first">, ' +
             '<' + full_url + '?page=2; rel="last">')
开发者ID:Athenolabs,项目名称:silver,代码行数:31,代码来源:test_subscription.py


示例2: test_post_proforma_with_proforma_entries

    def test_post_proforma_with_proforma_entries(self):
        customer = CustomerFactory.create()
        provider = ProviderFactory.create()
        SubscriptionFactory.create()

        url = reverse('proforma-list')
        provider_url = build_absolute_test_url(reverse('provider-detail', [provider.pk]))
        customer_url = build_absolute_test_url(reverse('customer-detail', [customer.pk]))

        data = {
            'provider': provider_url,
            'customer': customer_url,
            'series': None,
            'number': None,
            'currency': 'RON',
            'transaction_xe_rate': 1,
            'proforma_entries': [{
                "description": "Page views",
                "unit_price": 10.0,
                "quantity": 20
            }]
        }

        response = self.client.post(url, data=json.dumps(data),
                                    content_type='application/json')

        assert response.status_code == status.HTTP_201_CREATED
开发者ID:PressLabs,项目名称:silver,代码行数:27,代码来源:test_proforma.py


示例3: test_post_proforma_without_proforma_entries

    def test_post_proforma_without_proforma_entries(self):
        customer = CustomerFactory.create()
        provider = ProviderFactory.create()
        SubscriptionFactory.create()

        url = reverse('proforma-list')
        provider_url = build_absolute_test_url(reverse('provider-detail', [provider.pk]))
        customer_url = build_absolute_test_url(reverse('customer-detail', [customer.pk]))

        data = {
            'provider': provider_url,
            'customer': customer_url,
            'series': "",
            'number': "",
            'currency': 'RON',
            'proforma_entries': []
        }

        response = self.client.post(url, data=data)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        proforma = get_object_or_None(Proforma, id=response.data["id"])
        self.assertTrue(proforma)

        self.assertEqual(response.data, {
            "id": response.data["id"],
            "series": "ProformaSeries",
            "number": None,
            "provider": provider_url,
            "customer": customer_url,
            "archived_provider": '{}',
            "archived_customer": '{}',
            "due_date": None,
            "issue_date": None,
            "paid_date": None,
            "cancel_date": None,
            "sales_tax_name": "VAT",
            "sales_tax_percent": "1.00",
            "currency": "RON",
            "transaction_currency": proforma.transaction_currency,
            "transaction_xe_rate": (str(proforma.transaction_xe_rate)
                                    if proforma.transaction_xe_rate else None),
            "transaction_xe_date": proforma.transaction_xe_date,
            "pdf_url": None,
            "state": "draft",
            "invoice": None,
            "proforma_entries": [],
            "total": 0,
            "total_in_transaction_currency": 0,
            "transactions": []
        })
开发者ID:PressLabs,项目名称:silver,代码行数:52,代码来源:test_proforma.py


示例4: test_new_active_sub_trial_end_different_month_from_start_date_w_cb

    def test_new_active_sub_trial_end_different_month_from_start_date_w_cb(self):
        plan = PlanFactory.create(generate_after=100)
        subscription = SubscriptionFactory.create(
            plan=plan,
            state=Subscription.STATES.ACTIVE,
            start_date=datetime.date(2015, 8, 12),
            trial_end=datetime.date(2015, 9, 12)
        )
        correct_billing_date = datetime.date(2015, 9, 1)
        incorrect_billing_date_1 = datetime.date(2015, 8, 12)
        incorrect_billing_date_2 = datetime.date(2015, 8, 13)
        incorrect_billing_date_3 = datetime.date(2015, 8, 31)

        true_property = PropertyMock(return_value=True)
        mocked_bucket_end_date = MagicMock(
            return_value=datetime.date(2015, 8, 31)
        )
        with patch.multiple(
            Subscription,
            is_billed_first_time=true_property,
            _has_existing_customer_with_consolidated_billing=true_property,
            bucket_end_date=mocked_bucket_end_date
        ):
            assert subscription.should_be_billed(correct_billing_date) is True
            assert subscription.should_be_billed(incorrect_billing_date_1) is False
            assert subscription.should_be_billed(incorrect_billing_date_2) is False
            assert subscription.should_be_billed(incorrect_billing_date_3) is False
开发者ID:Athenolabs,项目名称:silver,代码行数:27,代码来源:test_subscription.py


示例5: test_create_subscription_mf_units_log

    def test_create_subscription_mf_units_log(self):
        subscription = SubscriptionFactory.create()
        metered_feature = MeteredFeatureFactory.create()

        subscription.plan.metered_features.add(metered_feature)

        subscription.activate()
        subscription.save()

        url = reverse('mf-log-units',
                      kwargs={'subscription_pk': subscription.pk,
                              'customer_pk': subscription.customer.pk,
                              'mf_product_code': metered_feature.product_code})

        date = str(datetime.date.today())

        response = self.client.patch(url, json.dumps({
            "count": 150,
            "date": date,
            "update_type": "absolute"
        }), content_type='application/json')

        assert response.status_code == status.HTTP_200_OK
        assert response.data == {'count': 150}

        response = self.client.patch(url, json.dumps({
            "count": 29,
            "date": date,
            "update_type": "relative"
        }), content_type='application/json')

        assert response.status_code == status.HTTP_200_OK
        assert response.data == {'count': 179}
开发者ID:Athenolabs,项目名称:silver,代码行数:33,代码来源:test_subscription.py


示例6: test_get_subscription_list_reference_filter

    def test_get_subscription_list_reference_filter(self):
        customer = CustomerFactory.create()
        subscriptions = SubscriptionFactory.create_batch(3, customer=customer)

        url = reverse('subscription-list',
                      kwargs={'customer_pk': customer.pk})

        references = [subscription.reference for subscription in subscriptions]

        reference = '?reference=' + references[0]
        response = self.client.get(url + reference)

        assert len(response.data) == 1
        assert response.status_code == status.HTTP_200_OK

        reference = '?reference=' + ','.join(references)
        response = self.client.get(url + reference)

        assert len(response.data) == 3
        assert response.status_code == status.HTTP_200_OK

        reference = '?reference=' + ','.join(references[:-1]) + ',invalid'
        response = self.client.get(url + reference)
        assert len(response.data) == 2
        assert response.status_code == status.HTTP_200_OK
开发者ID:oucsaw,项目名称:silver,代码行数:25,代码来源:test_subscription.py


示例7: test_create_subscription_mf_units_log_with_insufficient_data

    def test_create_subscription_mf_units_log_with_insufficient_data(self):
        subscription = SubscriptionFactory.create()
        metered_feature = MeteredFeatureFactory.create()

        subscription.plan.metered_features.add(metered_feature)

        subscription.activate()
        subscription.save()

        url = reverse('mf-log-units',
                      kwargs={'subscription_pk': subscription.pk,
                              'customer_pk': subscription.customer.pk,
                              'mf_product_code': metered_feature.product_code})

        data = {
            "count": 150,
            "date": "2008-12-24",
            "update_type": "absolute"
        }

        for field in data:
            data_copy = data.copy()
            data_copy.pop(field)

            response = self.client.patch(url, json.dumps(data_copy),
                                         content_type='application/json')

            assert response.status_code == status.HTTP_400_BAD_REQUEST
            assert response.data == {field: ['This field is required.']}
开发者ID:Athenolabs,项目名称:silver,代码行数:29,代码来源:test_subscription.py


示例8: test_already_billed_sub_wa_cb

    def test_already_billed_sub_wa_cb(self):
        plan = PlanFactory.create(generate_after=100)
        subscription = SubscriptionFactory.create(
            plan=plan,
            state=Subscription.STATES.ACTIVE,
            start_date=datetime.date(2015, 1, 1)
        )
        correct_billing_date = datetime.date(2015, 10, 1)
        incorrect_billing_date_1 = datetime.date(2015, 9, 3)
        incorrect_billing_date_2 = datetime.date(2015, 9, 12)
        incorrect_billing_date_3 = datetime.date(2015, 9, 30)

        false_property = PropertyMock(return_value=False)
        mocked_on_trial = MagicMock(return_value=True)
        mocked_last_billing_date = PropertyMock(
            return_value=datetime.date(2015, 9, 2)
        )
        mocked_bucket_end_date = MagicMock(
            return_value=datetime.date(2015, 9, 30)
        )
        with patch.multiple(
            Subscription,
            is_billed_first_time=false_property,
            on_trial=mocked_on_trial,
            last_billing_date=mocked_last_billing_date,
            _has_existing_customer_with_consolidated_billing=false_property,
            bucket_end_date=mocked_bucket_end_date
        ):
            assert subscription.should_be_billed(correct_billing_date) is True
            assert subscription.should_be_billed(incorrect_billing_date_1) is False
            assert subscription.should_be_billed(incorrect_billing_date_2) is False
            assert subscription.should_be_billed(incorrect_billing_date_3) is False
开发者ID:Athenolabs,项目名称:silver,代码行数:32,代码来源:test_subscription.py


示例9: test_new_active_sub_with_smaller_billing_date_than_start_date

    def test_new_active_sub_with_smaller_billing_date_than_start_date(self):
        plan = PlanFactory.create(generate_after=120)
        subscription = SubscriptionFactory.create(
            plan=plan,
            state=Subscription.STATES.ACTIVE,
            start_date=datetime.date(2015, 8, 22)
        )
        billing_date = datetime.date(2015, 8, 10)

        assert subscription.should_be_billed(billing_date) is False
开发者ID:Athenolabs,项目名称:silver,代码行数:10,代码来源:test_subscription.py


示例10: test_activate_subscription

    def test_activate_subscription(self):
        subscription = SubscriptionFactory.create()
        url = reverse('sub-activate',
                      kwargs={'subscription_pk': subscription.pk,
                              'customer_pk': subscription.customer.pk})

        response = self.client.post(url, content_type='application/json')

        assert response.status_code == status.HTTP_200_OK
        assert response.data == {'state': 'active'}
开发者ID:Athenolabs,项目名称:silver,代码行数:10,代码来源:test_subscription.py


示例11: setUp

    def setUp(self):
        # Setup simple subscription
        self.plan = PlanFactory.create(interval=Plan.INTERVALS.MONTH,
                                       interval_count=1, generate_after=120,
                                       enabled=True, amount=Decimal('200.00'),
                                       trial_period_days=0)

        self.subscription = SubscriptionFactory.create(plan=self.plan,
                                                       start_date=self.date)
        self.subscription.activate()
        self.subscription.save()
开发者ID:yashodhank,项目名称:silver,代码行数:11,代码来源:test_generate_docs_args.py


示例12: test_get_subscription_detail

    def test_get_subscription_detail(self):
        subscription = SubscriptionFactory.create()

        url = reverse('subscription-detail',
                      kwargs={'subscription_pk': subscription.pk,
                              'customer_pk': subscription.customer.pk})

        response = self.client.get(url)

        assert response.status_code == status.HTTP_200_OK
        assert response.data != []
开发者ID:Athenolabs,项目名称:silver,代码行数:11,代码来源:test_subscription.py


示例13: test_canceled_sub_w_date_before_cancel_date

    def test_canceled_sub_w_date_before_cancel_date(self):
        plan = PlanFactory.create(generate_after=120)
        subscription = SubscriptionFactory.create(
            plan=plan,
            state=Subscription.STATES.CANCELED,
            cancel_date=datetime.date(2015, 8, 22),
            start_date=datetime.date(2015, 8, 1)
        )
        incorrect_billing_date = datetime.date(2015, 8, 10)

        assert subscription.should_be_billed(incorrect_billing_date) is False
开发者ID:Athenolabs,项目名称:silver,代码行数:11,代码来源:test_subscription.py


示例14: test_post_proforma_without_proforma_entries

    def test_post_proforma_without_proforma_entries(self):
        customer = CustomerFactory.create()
        provider = ProviderFactory.create()
        SubscriptionFactory.create()

        url = reverse('proforma-list')
        data = {
            'provider': 'http://testserver/providers/%s/' % provider.pk,
            'customer': 'http://testserver/customers/%s/' % customer.pk,
            'series': "",
            'number': "",
            'currency': 'RON',
            'proforma_entries': []
        }

        response = self.client.post(url, data=data)

        assert response.status_code == status.HTTP_201_CREATED
        assert response.data == {
            "id": response.data["id"],
            "series": "ProformaSeries",
            "number": None,
            "provider": "http://testserver/providers/%s/" % provider.pk,
            "customer": "http://testserver/customers/%s/" % customer.pk,
            "archived_provider": {},
            "archived_customer": {},
            "due_date": None,
            "issue_date": None,
            "paid_date": None,
            "cancel_date": None,
            "sales_tax_name": "VAT",
            "sales_tax_percent": '1.00',
            "currency": "RON",
            'pdf_url': None,
            "state": "draft",
            "invoice": None,
            "proforma_entries": [],
            "total": Decimal('0.00'),
        }
开发者ID:oucsaw,项目名称:silver,代码行数:39,代码来源:test_proforma.py


示例15: test_post_invoice_with_invoice_entries

    def test_post_invoice_with_invoice_entries(self):
        CustomerFactory.create()
        ProviderFactory.create()
        SubscriptionFactory.create()

        url = reverse('invoice-list')
        data = {
            'provider': 'http://testserver/providers/1/',
            'customer': 'http://testserver/customers/1/',
            'series': None,
            'number': None,
            'currency': 'RON',
            'invoice_entries': [{
                "description": "Page views",
                "unit_price": 10.0,
                "quantity": 20}]
        }

        response = self.client.post(url, data=json.dumps(data),
                                    content_type='application/json')

        assert response.status_code == status.HTTP_201_CREATED
开发者ID:MaxMorais,项目名称:silver,代码行数:22,代码来源:test_invoice.py


示例16: test_end_subscription_from_terminal_state

    def test_end_subscription_from_terminal_state(self):
        subscription = SubscriptionFactory.create()

        url = reverse('sub-cancel',
                      kwargs={'subscription_pk': subscription.pk,
                              'customer_pk': subscription.customer.pk})

        response = self.client.post(url, json.dumps({
            "when": "now"}), content_type='application/json')

        assert response.status_code == status.HTTP_400_BAD_REQUEST
        assert response.data == {
            'error': u'Cannot cancel subscription from inactive state.'
        }
开发者ID:Athenolabs,项目名称:silver,代码行数:14,代码来源:test_subscription.py


示例17: test_reactivate_subscription

    def test_reactivate_subscription(self):
        subscription = SubscriptionFactory.create()
        subscription.activate()
        subscription.cancel(when=Subscription.CANCEL_OPTIONS.NOW)
        subscription.save()

        url = reverse('sub-reactivate',
                      kwargs={'subscription_pk': subscription.pk,
                              'customer_pk': subscription.customer.pk})

        response = self.client.post(url, content_type='application/json')

        assert response.status_code == status.HTTP_200_OK
        assert response.data == {'state': Subscription.STATES.ACTIVE}
开发者ID:Athenolabs,项目名称:silver,代码行数:14,代码来源:test_subscription.py


示例18: test_create_subscription_mf_units_log_with_unactivated_sub

    def test_create_subscription_mf_units_log_with_unactivated_sub(self):
        subscription = SubscriptionFactory.create()
        metered_feature = MeteredFeatureFactory.create()
        subscription.plan.metered_features.add(metered_feature)

        url = reverse('mf-log-units',
                      kwargs={'subscription_pk': subscription.pk,
                              'customer_pk': subscription.customer.pk,
                              'mf_product_code': metered_feature.product_code})

        response = self.client.patch(url)

        assert response.status_code == status.HTTP_403_FORBIDDEN
        assert response.data == {'detail': 'Subscription is not active.'}
开发者ID:Athenolabs,项目名称:silver,代码行数:14,代码来源:test_subscription.py


示例19: test_cancel_subscription

    def test_cancel_subscription(self):
        subscription = SubscriptionFactory.create()
        subscription.activate()
        subscription.save()

        url = reverse('sub-cancel',
                      kwargs={'subscription_pk': subscription.pk,
                              'customer_pk': subscription.customer.pk})

        response = self.client.post(url, json.dumps({
            "when": "end_of_billing_cycle"}), content_type='application/json')

        assert response.status_code == status.HTTP_200_OK
        assert response.data == {'state': Subscription.STATES.CANCELED}
开发者ID:Athenolabs,项目名称:silver,代码行数:14,代码来源:test_subscription.py


示例20: test_create_subscription_mf_units_log_with_unexisting_mf

    def test_create_subscription_mf_units_log_with_unexisting_mf(self):
        subscription = SubscriptionFactory.create()

        subscription.activate()
        subscription.save()

        url = reverse('mf-log-units',
                      kwargs={'subscription_pk': subscription.pk,
                              'customer_pk': subscription.customer.pk,
                              'mf_product_code': '1234'})

        response = self.client.patch(url)

        assert response.status_code == status.HTTP_404_NOT_FOUND
        assert response.data == {'detail': 'Metered Feature Not found.'}
开发者ID:Athenolabs,项目名称:silver,代码行数:15,代码来源:test_subscription.py



注:本文中的silver.tests.factories.SubscriptionFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python client.CQLClient类代码示例发布时间:2022-05-27
下一篇:
Python factories.ProviderFactory类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap