本文整理汇总了Python中silver.tests.factories.SubscriptionFactory类的典型用法代码示例。如果您正苦于以下问题:Python SubscriptionFactory类的具体用法?Python SubscriptionFactory怎么用?Python SubscriptionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SubscriptionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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">')
示例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
示例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": []
})
示例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
示例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}
示例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
示例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.']}
示例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
示例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
示例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'}
示例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()
示例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 != []
示例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
示例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'),
}
示例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