當前位置: 首頁>>代碼示例>>Python>>正文


Python SubscriptionFactory.create_batch方法代碼示例

本文整理匯總了Python中silver.tests.factories.SubscriptionFactory.create_batch方法的典型用法代碼示例。如果您正苦於以下問題:Python SubscriptionFactory.create_batch方法的具體用法?Python SubscriptionFactory.create_batch怎麽用?Python SubscriptionFactory.create_batch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在silver.tests.factories.SubscriptionFactory的用法示例。


在下文中一共展示了SubscriptionFactory.create_batch方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_get_subscription_list

# 需要導入模塊: from silver.tests.factories import SubscriptionFactory [as 別名]
# 或者: from silver.tests.factories.SubscriptionFactory import create_batch [as 別名]
    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,代碼行數:33,代碼來源:test_subscription.py

示例2: test_get_subscription_list_reference_filter

# 需要導入模塊: from silver.tests.factories import SubscriptionFactory [as 別名]
# 或者: from silver.tests.factories.SubscriptionFactory import create_batch [as 別名]
    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,代碼行數:27,代碼來源:test_subscription.py


注:本文中的silver.tests.factories.SubscriptionFactory.create_batch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。