コード例 #1
0
    def test_put_provider_without_required_field(self):
        """
         .. note::

             The test does not verify each required field, because the test
         test_create_provider_without_required_fields does this and since the
         creation will fail the update will fail too. This is more of a
         sanity test, to check if the correct view is called and if it does
         what's supposed to do for at least one field.
         """

        ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': 1})
        new_data = {
            'id': 1,
            'url': 'http://testserver/providers/1/',
            'email': '*****@*****.**',
            'address_1': 'address',
            'city': 'City',
            'zip_code': '1',
            'country': 'RO',
            'flow': 'invoice',
            'invoice_series': 'NSeries',
            'invoice_starting_number': 2,
        }

        response = self.client.put(url, data=new_data)

        assert response.status_code == status.HTTP_400_BAD_REQUEST
        assert response.data == {'name': ['This field is required.']}
コード例 #2
0
ファイル: test_invoice.py プロジェクト: infomagnum-net/tcoapp
    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
コード例 #3
0
    def test_delete_provider(self):
        ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': 1})
        response = self.client.delete(url)

        assert response.status_code == status.HTTP_204_NO_CONTENT
コード例 #4
0
ファイル: test_provider.py プロジェクト: Athenolabs/silver
    def test_get_provider(self):
        ProviderFactory.reset_sequence(1)
        ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': 1})

        response = self.client.get(url)

        assert response.status_code == 200
        assert response.data == {
            'id': 1,
            'url': 'http://testserver/providers/1/',
            'name': 'Name1',
            'company': 'Company1',
            'flow': 'proforma',
            'invoice_series': 'InvoiceSeries',
            'invoice_starting_number': 1,
            'proforma_series': 'ProformaSeries',
            'proforma_starting_number': 1,
            'email': '*****@*****.**',
            'address_1': 'Address11',
            'address_2': 'Address21',
            'city': 'City1',
            'state': 'State1',
            'zip_code': '1',
            'country': u'AL',
            'extra': 'Extra1',
            'meta': {u'something': [1, 2]}
        }
コード例 #5
0
ファイル: test_provider.py プロジェクト: Athenolabs/silver
    def test_get_providers(self):
        batch_size = 40
        ProviderFactory.create_batch(batch_size)
        url = reverse('provider-list')
        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">')
コード例 #6
0
ファイル: test_provider.py プロジェクト: Athenolabs/silver
    def test_put_provider_without_required_field(self):
        """
         .. note::

             The test does not verify each required field, because the test
         test_create_provider_without_required_fields does this and since the
         creation will fail the update will fail too. This is more of a
         sanity test, to check if the correct view is called and if it does
         what's supposed to do for at least one field.
         """

        ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': 1})
        new_data = {
            'id': 1,
            'url': 'http://testserver/providers/1/',
            'email': '*****@*****.**',
            'address_1': 'address',
            'city': 'City',
            'zip_code': '1',
            'country': 'RO',
            'flow': 'invoice',
            'invoice_series': 'NSeries',
            'invoice_starting_number': 2,
        }

        response = self.client.put(url, data=new_data)

        assert response.status_code == status.HTTP_400_BAD_REQUEST
        assert response.data == {'name': ['This field is required.']}
コード例 #7
0
ファイル: test_provider.py プロジェクト: Athenolabs/silver
    def test_delete_provider(self):
        ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': 1})
        response = self.client.delete(url)

        assert response.status_code == status.HTTP_204_NO_CONTENT
コード例 #8
0
    def test_get_provider(self):
        ProviderFactory.reset_sequence(1)
        ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': 1})

        response = self.client.get(url)

        assert response.status_code == 200
        assert response.data == {
            'id': 1,
            'url': 'http://testserver/providers/1/',
            'name': 'Name1',
            'company': 'Company1',
            'flow': 'proforma',
            'invoice_series': 'InvoiceSeries',
            'invoice_starting_number': 1,
            'proforma_series': 'ProformaSeries',
            'proforma_starting_number': 1,
            'email': '*****@*****.**',
            'address_1': 'Address11',
            'address_2': 'Address21',
            'city': 'City1',
            'state': 'State1',
            'zip_code': '1',
            'country': u'AL',
            'extra': 'Extra1',
            'meta': {
                u'something': [1, 2]
            }
        }
コード例 #9
0
ファイル: test_provider.py プロジェクト: Alex-CodeLab/silver
    def test_get_providers(self):
        batch_size = 40
        ProviderFactory.create_batch(batch_size)
        url = reverse('provider-list')
        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">')
コード例 #10
0
ファイル: test_provider.py プロジェクト: Alex-CodeLab/silver
    def test_get_provider(self):
        ProviderFactory.reset_sequence(1)
        provider = ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': provider.pk})

        response = self.client.get(url)

        assert response.status_code == 200
        expected = {
            'id': provider.pk,
            'url': 'http://testserver/providers/%s/' % provider.pk,
            'name': provider.name,
            'company': provider.company,
            'flow': provider.flow,
            'invoice_series': provider.invoice_series,
            'invoice_starting_number': provider.invoice_starting_number,
            'proforma_series': provider.proforma_series,
            'proforma_starting_number': provider.proforma_starting_number,
            'email': provider.email,
            'address_1': provider.address_1,
            'address_2': provider.address_2,
            'city': provider.city,
            'state': provider.state,
            'zip_code': provider.zip_code,
            'country': provider.country,
            'extra': provider.extra,
            'meta': {
                u'something': [1, 2]
            },
        }
        assert response.data == expected
コード例 #11
0
ファイル: test_provider.py プロジェクト: MaxMorais/silver
    def test_get_provider(self):
        ProviderFactory.reset_sequence(1)
        provider = ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': 1})

        response = self.client.get(url)

        assert response.status_code == 200
        expected = {
            'id': 1,
            'url': 'http://testserver/providers/1/',
            'name': provider.name,
            'company': provider.company,
            'flow': provider.flow,
            'invoice_series': provider.invoice_series,
            'invoice_starting_number': provider.invoice_starting_number,
            'proforma_series': provider.proforma_series,
            'proforma_starting_number': provider.proforma_starting_number,
            'email': provider.email,
            'address_1': provider.address_1,
            'address_2': provider.address_2,
            'city': provider.city,
            'state': provider.state,
            'zip_code': provider.zip_code,
            'country': provider.country,
            'extra': provider.extra,
            'meta': {u'something': [1, 2]}
        }
        assert response.data == expected
コード例 #12
0
ファイル: test_provider.py プロジェクト: oucsaw/silver
    def test_put_provider_correctly(self):
        ProviderFactory.reset_sequence(1)
        provider = ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': provider.pk})
        new_data = {
            'id': provider.pk,
            'url': 'http://testserver/providers/%s/' % provider.pk,
            'name': 'TestProvider',
            'company': 'TheNewCompany',
            'display_email': '*****@*****.**',
            'notification_email': '*****@*****.**',
            'address_1': 'address',
            'city': 'City',
            'zip_code': '1',
            'country': 'RO',
            'flow': 'proforma',
            'invoice_series': 'NewSeries',
            'invoice_starting_number': 1,
            'proforma_series': 'ProformaSeries',
            'proforma_starting_number': 1
            # TODO: add new meta JSON value
        }

        response = self.client.put(url, data=new_data)

        assert response.status_code == status.HTTP_200_OK
        assert response.data == {
            'id': provider.pk,
            'url': 'http://testserver/providers/%s/' % provider.pk,
            'name': 'TestProvider',
            'company': 'TheNewCompany',
            'flow': 'proforma',
            'display_email': '*****@*****.**',
            'notification_email': '*****@*****.**',
            'address_1': 'address',
            'address_2': u'Addåress21',
            'city': 'City',
            'state': 'State1',
            'zip_code': '1',
            'country': 'RO',
            'extra': 'Extra1',
            'flow': 'proforma',
            'invoice_series': 'NewSeries',
            'invoice_starting_number': 1,
            'proforma_series': 'ProformaSeries',
            'proforma_starting_number': 1,
            'meta': {u'something': [1, 2]},
            'payment_processors': 'http://testserver/providers/%s/payment_processors/' % provider.pk
        }
コード例 #13
0
    def test_put_provider_correctly(self):
        ProviderFactory.reset_sequence(1)
        provider = ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': provider.pk})
        new_data = {
            'id': provider.pk,
            'name': 'TestProvider',
            'company': 'TheNewCompany',
            'email': '*****@*****.**',
            'address_1': 'address',
            'city': 'City',
            'zip_code': '1',
            'country': 'RO',
            'flow': 'proforma',
            'invoice_series': 'NewSeries',
            'invoice_starting_number': 1,
            'proforma_series': 'ProformaSeries',
            'proforma_starting_number': 1
            # TODO: add new meta JSON value
        }

        response = self.client.put(url, data=new_data)

        assert response.status_code == status.HTTP_200_OK

        self_url = build_absolute_test_url(url)
        assert response.data == {
            'id': provider.pk,
            'url': self_url,
            'name': new_data['name'],
            'company': new_data['company'],
            'flow': provider.flow,
            'email': new_data['email'],
            'address_1': new_data['address_1'],
            'address_2': provider.address_2,
            'city': new_data['city'],
            'state': provider.state,
            'zip_code': new_data['zip_code'],
            'country': new_data['country'],
            'extra': provider.extra,
            'flow': new_data['flow'],
            'invoice_series': new_data['invoice_series'],
            'invoice_starting_number': new_data['invoice_starting_number'],
            'proforma_series': new_data['proforma_series'],
            'proforma_starting_number': new_data['proforma_starting_number'],
            'meta': provider.meta,
        }
コード例 #14
0
ファイル: test_provider.py プロジェクト: PressLabs/silver
    def test_put_provider_correctly(self):
        ProviderFactory.reset_sequence(1)
        provider = ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': provider.pk})
        new_data = {
            'id': provider.pk,
            'name': 'TestProvider',
            'company': 'TheNewCompany',
            'email': '*****@*****.**',
            'address_1': 'address',
            'city': 'City',
            'zip_code': '1',
            'country': 'RO',
            'flow': 'proforma',
            'invoice_series': 'NewSeries',
            'invoice_starting_number': 1,
            'proforma_series': 'ProformaSeries',
            'proforma_starting_number': 1
            # TODO: add new meta JSON value
        }

        response = self.client.put(url, data=new_data)

        assert response.status_code == status.HTTP_200_OK

        self_url = build_absolute_test_url(url)
        assert response.data == {
            'id': provider.pk,
            'url': self_url,
            'name': new_data['name'],
            'company': new_data['company'],
            'flow': provider.flow,
            'email': new_data['email'],
            'address_1': new_data['address_1'],
            'address_2': provider.address_2,
            'city': new_data['city'],
            'state': provider.state,
            'zip_code': new_data['zip_code'],
            'country': new_data['country'],
            'extra': provider.extra,
            'flow': new_data['flow'],
            'invoice_series': new_data['invoice_series'],
            'invoice_starting_number': new_data['invoice_starting_number'],
            'proforma_series': new_data['proforma_series'],
            'proforma_starting_number': new_data['proforma_starting_number'],
            'meta': provider.meta,
        }
コード例 #15
0
    def test_pay_invoice_with_provided_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        invoice = InvoiceFactory.create(provider=provider, customer=customer)
        invoice.issue()
        invoice.save()

        url = reverse('invoice-state', kwargs={'pk': invoice.pk})
        data = {
            'state': 'paid',
            'paid_date': '2014-05-05'
        }
        response = self.client.put(url, data=json.dumps(data),
                                   content_type='application/json')

        assert response.status_code == status.HTTP_200_OK
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)
        mandatory_content = {
            'issue_date': timezone.now().date().strftime('%Y-%m-%d'),
            'due_date': due_date.strftime('%Y-%m-%d'),
            'paid_date': '2014-05-05',
            'state': 'paid'
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in response.data.items()
                   for item in mandatory_content.iteritems())
コード例 #16
0
ファイル: test_proforma.py プロジェクト: Athenolabs/silver
    def test_issue_proforma_with_custom_issue_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        ProformaFactory.create(provider=provider, customer=customer)

        url = reverse('proforma-state', kwargs={'pk': 1})
        data = {'state': 'issued', 'issue_date': '2014-01-01'}
        response = self.client.put(url, data=json.dumps(data),
                                     content_type='application/json')

        assert response.status_code == status.HTTP_200_OK
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)
        mandatory_content = {
            'issue_date': '2014-01-01',
            'due_date': due_date.strftime('%Y-%m-%d'),
            'state': 'issued'
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in response.data.items()
                   for item in mandatory_content.iteritems())
        assert response.data.get('archived_provider', {}) != {}
        assert response.data.get('archived_customer', {}) != {}
        assert Invoice.objects.count() == 0

        proforma = get_object_or_None(Proforma, pk=1)
コード例 #17
0
ファイル: test_proforma.py プロジェクト: oucsaw/silver
    def test_pay_proforma_with_provided_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        proforma = ProformaFactory.create(provider=provider, customer=customer)
        proforma.issue()
        proforma.save()

        url = reverse('proforma-state', kwargs={'pk': proforma.pk})
        data = {
            'state': 'paid',
            'paid_date': '2014-05-05'
        }
        response = self.client.put(url, data=json.dumps(data), content_type='application/json')

        proforma.refresh_from_db()
        assert response.status_code == status.HTTP_200_OK
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)
        mandatory_content = {
            'issue_date': timezone.now().date().strftime('%Y-%m-%d'),
            'due_date': due_date.strftime('%Y-%m-%d'),
            'paid_date': '2014-05-05',
            'state': 'paid',
            'invoice': 'http://testserver/invoices/%s/' % proforma.invoice.pk
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in response.data.items()
                   for item in mandatory_content.iteritems())

        invoice = Invoice.objects.all()[0]
        assert proforma.invoice == invoice
        assert invoice.proforma == proforma

        invoice = get_object_or_None(Invoice, proforma=proforma)
コード例 #18
0
ファイル: test_invoice.py プロジェクト: MaxMorais/silver
    def test_cancel_invoice_with_provided_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        invoice = InvoiceFactory.create(provider=provider, customer=customer)
        invoice.issue()
        invoice.save()

        url = reverse('invoice-state', kwargs={'pk': 1})
        data = {
            'state': 'canceled',
            'cancel_date': '2014-10-10'
        }

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

        assert response.status_code == status.HTTP_200_OK
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)
        mandatory_content = {
            'issue_date': timezone.now().date().strftime('%Y-%m-%d'),
            'due_date': due_date.strftime('%Y-%m-%d'),
            'cancel_date': '2014-10-10',
            'state': 'canceled'
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in response.data.items()
                   for item in mandatory_content.iteritems())
コード例 #19
0
    def test_pay_proforma_with_provided_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        proforma = ProformaFactory.create(provider=provider, customer=customer)
        proforma.issue()

        url = reverse('proforma-state', kwargs={'pk': proforma.pk})
        data = {'state': 'paid', 'paid_date': '2014-05-05'}
        response = self.client.put(url,
                                   data=json.dumps(data),
                                   content_type='application/json')

        proforma.refresh_from_db()
        assert response.status_code == status.HTTP_200_OK
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)

        invoice_url = build_absolute_test_url(
            reverse('invoice-detail', [proforma.related_document.pk]))
        mandatory_content = {
            'issue_date': timezone.now().date().strftime('%Y-%m-%d'),
            'due_date': due_date.strftime('%Y-%m-%d'),
            'paid_date': '2014-05-05',
            'state': 'paid',
            'invoice': invoice_url
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in response.data.items()
                   for item in mandatory_content.iteritems())

        invoice = Invoice.objects.all()[0]
        assert proforma.related_document == invoice
        assert invoice.related_document == proforma
コード例 #20
0
ファイル: test_proforma.py プロジェクト: Alex-CodeLab/silver
    def test_issue_proforma_with_custom_issue_date_and_due_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        proforma = ProformaFactory.create(provider=provider, customer=customer)

        url = reverse('proforma-state', kwargs={'pk': proforma.pk})
        data = {
            'state': 'issued',
            'issue_date': '2014-01-01',
            'due_date': '2014-01-20'
        }

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

        assert response.status_code == status.HTTP_200_OK
        mandatory_content = {
            'issue_date': '2014-01-01',
            'due_date': '2014-01-20',
            'state': 'issued'
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in response.data.items()
                   for item in mandatory_content.iteritems())
        assert response.data.get('archived_provider', {}) != {}
        assert response.data.get('archived_customer', {}) != {}
        assert Invoice.objects.count() == 0

        proforma = get_object_or_None(Proforma, pk=1)
コード例 #21
0
ファイル: test_proforma.py プロジェクト: PressLabs/silver
    def test_pay_proforma_with_provided_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        proforma = ProformaFactory.create(provider=provider, customer=customer)
        proforma.issue()

        url = reverse('proforma-state', kwargs={'pk': proforma.pk})
        data = {
            'state': 'paid',
            'paid_date': '2014-05-05'
        }
        response = self.client.put(url, data=json.dumps(data), content_type='application/json')

        proforma.refresh_from_db()
        assert response.status_code == status.HTTP_200_OK
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)

        invoice_url = build_absolute_test_url(reverse('invoice-detail',
                                                      [proforma.related_document.pk]))
        mandatory_content = {
            'issue_date': timezone.now().date().strftime('%Y-%m-%d'),
            'due_date': due_date.strftime('%Y-%m-%d'),
            'paid_date': '2014-05-05',
            'state': 'paid',
            'invoice': invoice_url
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in list(response.data.items())
                   for item in mandatory_content.items())

        invoice = Invoice.objects.all()[0]
        assert proforma.related_document == invoice
        assert invoice.related_document == proforma
コード例 #22
0
ファイル: test_invoice.py プロジェクト: Dynamicic/silver
    def test_issue_invoice_with_custom_issue_date_and_due_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        invoice = InvoiceFactory.create(provider=provider, customer=customer)

        url = reverse('invoice-state', kwargs={'pk': invoice.pk})
        data = {
            'state': 'issued',
            'issue_date': '2014-01-01',
            'due_date': '2014-01-20'
        }

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

        assert response.status_code == status.HTTP_200_OK
        mandatory_content = {
            'issue_date': '2014-01-01',
            'due_date': '2014-01-20',
            'state': 'issued'
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in list(response.data.items())
                   for item in mandatory_content.items())
        assert response.data.get('archived_provider', {}) != {}
        assert response.data.get('archived_customer', {}) != {}
コード例 #23
0
ファイル: test_proforma.py プロジェクト: PressLabs/silver
    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
コード例 #24
0
ファイル: test_proforma.py プロジェクト: Alex-CodeLab/silver
    def test_pay_proforma_with_provided_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        proforma = ProformaFactory.create(provider=provider, customer=customer)
        proforma.issue()
        proforma.save()

        url = reverse('proforma-state', kwargs={'pk': proforma.pk})
        data = {
            'state': 'paid',
            'paid_date': '2014-05-05'
        }
        response = self.client.put(url, data=json.dumps(data), content_type='application/json')

        proforma.refresh_from_db()
        assert response.status_code == status.HTTP_200_OK
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)
        mandatory_content = {
            'issue_date': timezone.now().date().strftime('%Y-%m-%d'),
            'due_date': due_date.strftime('%Y-%m-%d'),
            'paid_date': '2014-05-05',
            'state': 'paid',
            'invoice': 'http://testserver/invoices/%s/' % proforma.invoice.pk
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in response.data.items()
                   for item in mandatory_content.iteritems())

        invoice = Invoice.objects.all()[0]
        assert proforma.invoice == invoice
        assert invoice.proforma == proforma

        invoice = get_object_or_None(Invoice, proforma=proforma)
コード例 #25
0
ファイル: test_proforma.py プロジェクト: SpotDraft/silver
    def test_issue_proforma_with_custom_issue_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        proforma = ProformaFactory.create(provider=provider, customer=customer)

        url = reverse('proforma-state', kwargs={'pk': proforma.pk})
        data = {'state': 'issued', 'issue_date': '2014-01-01'}
        response = self.client.put(url,
                                   data=json.dumps(data),
                                   content_type='application/json')

        assert response.status_code == status.HTTP_200_OK
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)
        mandatory_content = {
            'issue_date': '2014-01-01',
            'due_date': due_date.strftime('%Y-%m-%d'),
            'state': 'issued'
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in list(response.data.items())
                   for item in mandatory_content.items())
        assert response.data.get('archived_provider', {}) != {}
        assert response.data.get('archived_customer', {}) != {}
        assert Invoice.objects.count() == 0

        proforma = get_object_or_None(Proforma, pk=1)
コード例 #26
0
    def create_basic_plan(self,
                          start_date,
                          end_date,
                          interval=Plan.INTERVALS.YEAR):
        self.provider = ProviderFactory.create(flow=Provider.FLOWS.INVOICE)

        self.customer = CustomerFactory.create(
            consolidated_billing=False, sales_tax_percent=Decimal('0.00'))
        self.currency = 'USD'

        self.plan = PlanFactory.create(
            interval=interval,
            interval_count=1,
            generate_after=0,
            enabled=True,
            provider=self.provider,
            product_code=ProductCodeFactory(value="yearly-seat-plan"),
            amount=Decimal('10.00'),
            prebill_plan=False,
            currency=self.currency,
            trial_period_days=None,
            cycle_billing_duration=dt.timedelta(days=1),
        )
        self.plan.save()

        # Create the prorated subscription
        self.subscription = SubscriptionFactory.create(plan=self.plan,
                                                       start_date=start_date,
                                                       customer=self.customer)
        self.subscription.activate()
        self.subscription.save()
コード例 #27
0
ファイル: test_invoice.py プロジェクト: infomagnum-net/tcoapp
    def test_issue_invoice_with_default_dates(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        InvoiceFactory.create(provider=provider, customer=customer)

        url = reverse('invoice-state', kwargs={'pk': 1})
        data = {'state': 'issued'}
        response = self.client.put(url,
                                   data=json.dumps(data),
                                   content_type='application/json')

        assert response.status_code == status.HTTP_200_OK
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)
        mandatory_content = {
            'issue_date': timezone.now().date().strftime('%Y-%m-%d'),
            'due_date': due_date.strftime('%Y-%m-%d'),
            'state': 'issued'
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in response.data.items()
                   for item in mandatory_content.iteritems())
        assert response.data.get('archived_provider', {}) != {}
        assert response.data.get('archived_customer', {}) != {}

        invoice = get_object_or_None(Invoice, pk=1)
コード例 #28
0
ファイル: test_invoice.py プロジェクト: MaxMorais/silver
    def test_issue_invoice_with_custom_issue_date_and_due_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        InvoiceFactory.create(provider=provider, customer=customer)

        url = reverse('invoice-state', kwargs={'pk': 1})
        data = {
            'state': 'issued',
            'issue_date': '2014-01-01',
            'due_date': '2014-01-20'
        }

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

        assert response.status_code == status.HTTP_200_OK
        mandatory_content = {
            'issue_date': '2014-01-01',
            'due_date': '2014-01-20',
            'state': 'issued'
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in response.data.items()
                   for item in mandatory_content.iteritems())
        assert response.data.get('archived_provider', {}) != {}
        assert response.data.get('archived_customer', {}) != {}

        invoice = get_object_or_None(Invoice, pk=1)
コード例 #29
0
ファイル: test_proforma.py プロジェクト: Alex-CodeLab/silver
    def test_cancel_proforma_with_provided_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        proforma = ProformaFactory.create(provider=provider, customer=customer)
        proforma.issue()
        proforma.save()

        url = reverse('proforma-state', kwargs={'pk': proforma.pk})
        data = {
            'state': 'canceled',
            'cancel_date': '2014-10-10'
        }

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

        assert response.status_code == status.HTTP_200_OK
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)
        mandatory_content = {
            'issue_date': timezone.now().date().strftime('%Y-%m-%d'),
            'due_date': due_date.strftime('%Y-%m-%d'),
            'cancel_date': '2014-10-10',
            'state': 'canceled'
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in response.data.items()
                   for item in mandatory_content.iteritems())
        assert Invoice.objects.count() == 0
コード例 #30
0
ファイル: test_plan.py プロジェクト: infomagnum-net/tcoapp
    def test_create_plan(self):
        url = reverse('plan-list')

        ProductCodeFactory.create_batch(2)
        feature1_pc = ProductCode.objects.get(id=1).value
        plan_pc = ProductCode.objects.get(id=2).value
        provider = ProviderFactory.create()
        provider_url = reverse('provider-detail', kwargs={'pk': provider.pk})
        response = self.client.post(url,
                                    json.dumps({
                                        "name":
                                        "Hydrogen",
                                        "interval":
                                        "month",
                                        "interval_count":
                                        1,
                                        "amount":
                                        149.99,
                                        "currency":
                                        "USD",
                                        "trial_period_days":
                                        15,
                                        "generate_after":
                                        86400,
                                        "enabled":
                                        True,
                                        "private":
                                        False,
                                        "product_code":
                                        plan_pc,
                                        'metered_features': [{
                                            'name':
                                            'Page Views',
                                            'unit':
                                            '100k',
                                            'price_per_unit':
                                            0.01,
                                            'included_units':
                                            0,
                                            'product_code':
                                            feature1_pc
                                        }, {
                                            'name':
                                            'VIP Support',
                                            'price_per_unit':
                                            49.99,
                                            'unit':
                                            1,
                                            'included_units':
                                            1,
                                            'product_code':
                                            "1234"
                                        }],
                                        'provider':
                                        provider_url
                                    }),
                                    content_type='application/json')

        assert response.status_code == status.HTTP_201_CREATED
コード例 #31
0
ファイル: test_provider.py プロジェクト: oucsaw/silver
    def test_patch_provider(self):
        ProviderFactory.reset_sequence(1)
        provider = ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': provider.pk})

        new_data = {
            'company': 'TheNewCompany',  # The changed field
            'address_1': 'Address11',
            'flow': 'proforma',
            'invoice_series': 'InvoiceSeries',
            'invoice_starting_number': 1,
            'proforma_series': 'ProformaSeries',
            'proforma_starting_number': 1,
            'city': 'City1',
            'zip_code': '1',
            'country': u'AL',
        }

        response = self.client.patch(url, data=new_data)

        assert response.status_code == 200
        assert response.data == {
            'id': provider.pk,
            'url': 'http://testserver/providers/%s/' % provider.pk,
            'name': u'Náme1',
            'company': u'TheNewCompany',
            'flow': 'proforma',
            'invoice_series': 'InvoiceSeries',
            'invoice_starting_number': 1,
            'proforma_series': 'ProformaSeries',
            'proforma_starting_number': 1,
            'display_email': '*****@*****.**',
            'notification_email': '*****@*****.**',
            'address_1': 'Address11',
            'address_2': u'Addåress21',
            'city': 'City1',
            'state': 'State1',
            'zip_code': '1',
            'country': u'AL',
            'extra': 'Extra1',
            'meta': {u'something': [1, 2]},
            'payment_processors': 'http://testserver/providers/%s/payment_processors/' % provider.pk
        }
コード例 #32
0
ファイル: test_provider.py プロジェクト: Alex-CodeLab/silver
    def test_patch_provider(self):
        ProviderFactory.reset_sequence(1)
        provider = ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': provider.pk})

        new_data = {
            'company': 'TheNewCompany',  # The changed field
            'address_1': 'Address11',
            'flow': 'proforma',
            'invoice_series': 'InvoiceSeries',
            'invoice_starting_number': 1,
            'proforma_series': 'ProformaSeries',
            'proforma_starting_number': 1,
            'city': 'City1',
            'zip_code': '1',
            'country': u'AL',
        }

        response = self.client.patch(url, data=new_data)

        assert response.status_code == 200
        assert response.data == {
            'id': provider.pk,
            'url': 'http://testserver/providers/%s/' % provider.pk,
            'name': u'Náme1',
            'company': u'TheNewCompany',
            'flow': 'proforma',
            'invoice_series': 'InvoiceSeries',
            'invoice_starting_number': 1,
            'proforma_series': 'ProformaSeries',
            'proforma_starting_number': 1,
            'email': '*****@*****.**',
            'address_1': 'Address11',
            'address_2': u'Addåress21',
            'city': 'City1',
            'state': 'State1',
            'zip_code': '1',
            'country': u'AL',
            'extra': 'Extra1',
            'meta': {
                u'something': [1, 2]
            },
        }
コード例 #33
0
ファイル: test_provider.py プロジェクト: PressLabs/silver
    def test_patch_provider(self):
        ProviderFactory.reset_sequence(1)
        provider = ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': provider.pk})

        new_data = {
            'company': 'TheNewCompany',  # The changed field
            'address_1': 'Address11',
            'flow': 'proforma',
            'invoice_series': 'InvoiceSeries',
            'invoice_starting_number': 1,
            'proforma_series': 'ProformaSeries',
            'proforma_starting_number': 1,
            'city': 'City1',
            'zip_code': '1',
            'country': u'AL',
        }

        response = self.client.patch(url, data=new_data)

        assert response.status_code == 200

        self_url = build_absolute_test_url(url)
        assert response.data == {
            'id': provider.pk,
            'url': self_url,
            'name': provider.name,
            'company': new_data['company'],
            'flow': new_data['flow'],
            'invoice_series': new_data['invoice_series'],
            'invoice_starting_number': new_data['invoice_starting_number'],
            'proforma_series': new_data['proforma_series'],
            'proforma_starting_number': new_data['proforma_starting_number'],
            'email': provider.email,
            'address_1': new_data['address_1'],
            'address_2': provider.address_2,
            'city': new_data['city'],
            'state': provider.state,
            'zip_code': new_data['zip_code'],
            'country': new_data['country'],
            'extra': provider.extra,
            'meta': provider.meta,
        }
コード例 #34
0
    def test_patch_provider(self):
        ProviderFactory.reset_sequence(1)
        provider = ProviderFactory.create()

        url = reverse('provider-detail', kwargs={'pk': provider.pk})

        new_data = {
            'company': 'TheNewCompany',  # The changed field
            'address_1': 'Address11',
            'flow': 'proforma',
            'invoice_series': 'InvoiceSeries',
            'invoice_starting_number': 1,
            'proforma_series': 'ProformaSeries',
            'proforma_starting_number': 1,
            'city': 'City1',
            'zip_code': '1',
            'country': 'AL',
        }

        response = self.client.patch(url, data=new_data)

        assert response.status_code == 200

        self_url = build_absolute_test_url(url)
        assert response.data == {
            'id': provider.pk,
            'url': self_url,
            'name': provider.name,
            'company': new_data['company'],
            'flow': new_data['flow'],
            'invoice_series': new_data['invoice_series'],
            'invoice_starting_number': new_data['invoice_starting_number'],
            'proforma_series': new_data['proforma_series'],
            'proforma_starting_number': new_data['proforma_starting_number'],
            'email': provider.email,
            'address_1': new_data['address_1'],
            'address_2': provider.address_2,
            'city': new_data['city'],
            'state': provider.state,
            'zip_code': new_data['zip_code'],
            'country': new_data['country'],
            'extra': provider.extra,
            'meta': provider.meta,
        }
コード例 #35
0
ファイル: test_proforma.py プロジェクト: Alex-CodeLab/silver
    def test_pay_proforma_when_in_draft_state(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        proforma = ProformaFactory.create(provider=provider, customer=customer)

        url = reverse('proforma-state', kwargs={'pk': proforma.pk})
        data = {'state': 'paid'}
        response = self.client.put(url, data=json.dumps(data), content_type='application/json')
        assert response.status_code == status.HTTP_403_FORBIDDEN
        assert response.data == {'detail': 'A proforma can be paid only if it is in issued state.'}
        assert Invoice.objects.count() == 0
コード例 #36
0
ファイル: test_invoice.py プロジェクト: MaxMorais/silver
    def test_pay_invoice_when_in_draft_state(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        InvoiceFactory.create(provider=provider, customer=customer)

        url = reverse('invoice-state', kwargs={'pk': 1})
        data = {'state': 'paid'}
        response = self.client.put(url, data=json.dumps(data),
                                     content_type='application/json')
        assert response.status_code == status.HTTP_403_FORBIDDEN
        assert response.data == {'detail': 'An invoice can be paid only if it is in issued state.'}
コード例 #37
0
ファイル: test_invoice.py プロジェクト: Dynamicic/silver
    def test_post_invoice_without_invoice_entries(self):
        customer = CustomerFactory.create()
        provider = ProviderFactory.create()
        SubscriptionFactory.create()

        url = reverse('invoice-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',
            'invoice_entries': []
        }

        response = self.client.post(url, data=data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        invoice = get_object_or_None(Invoice, id=response.data["id"])
        self.assertTrue(invoice)

        self.assertEqual(
            response.data, {
                "id": response.data["id"],
                "series": invoice.series,
                "number": invoice.number,
                "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": invoice.sales_tax_name,
                "sales_tax_percent": str(invoice.sales_tax_percent),
                "currency": "RON",
                "transaction_currency": invoice.transaction_currency,
                "transaction_xe_rate": None,
                "transaction_xe_date": invoice.transaction_xe_date,
                "state": invoice.state,
                "proforma": None,
                "invoice_entries": [],
                "pdf_url": None,
                "total": invoice.total,
                "total_in_transaction_currency": invoice.total,
                "transactions": []
            })
コード例 #38
0
ファイル: test_proforma.py プロジェクト: PressLabs/silver
    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": []
        })
コード例 #39
0
ファイル: test_invoice.py プロジェクト: MaxMorais/silver
    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
コード例 #40
0
ファイル: test_proforma.py プロジェクト: Athenolabs/silver
    def test_post_proforma_without_proforma_entries(self):
        CustomerFactory.create()
        ProviderFactory.create()
        SubscriptionFactory.create()

        url = reverse('proforma-list')
        data = {
            'provider': 'http://testserver/providers/1/',
            'customer': 'http://testserver/customers/1/',
            '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": 1,
            "series": "ProformaSeries",
            "number": 1,
            "provider": "http://testserver/providers/1/",
            "customer": "http://testserver/customers/1/",
            "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'),
        }
コード例 #41
0
ファイル: test_invoice.py プロジェクト: MaxMorais/silver
    def test_illegal_state_change_when_in_draft_state(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        InvoiceFactory.create(provider=provider, customer=customer)

        url = reverse('invoice-state', kwargs={'pk': 1})
        data = {'state': 'illegal-state'}

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

        assert response.status_code == status.HTTP_403_FORBIDDEN
        assert response.data == {'detail': 'Illegal state value.'}
コード例 #42
0
ファイル: test_proforma.py プロジェクト: Alex-CodeLab/silver
    def test_illegal_state_change_when_in_draft_state(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        proforma = ProformaFactory.create(provider=provider, customer=customer)

        url = reverse('proforma-state', kwargs={'pk': proforma.pk})
        data = {'state': 'illegal-state'}

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

        assert response.status_code == status.HTTP_403_FORBIDDEN
        assert response.data == {'detail': 'Illegal state value.'}
        assert Invoice.objects.count() == 0
コード例 #43
0
ファイル: test_proforma.py プロジェクト: oucsaw/silver
    def test_cancel_proforma_in_draft_state(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        proforma = ProformaFactory.create(provider=provider, customer=customer)

        url = reverse('proforma-state', kwargs={'pk': proforma.pk})
        data = {'state': 'canceled'}

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

        assert response.status_code == status.HTTP_403_FORBIDDEN
        assert response.data == {'detail': 'A proforma can be canceled only if it is in issued state.'}
        assert Invoice.objects.count() == 0
コード例 #44
0
ファイル: test_proforma.py プロジェクト: galaxydata/silver
    def test_post_proforma_without_proforma_entries(self):
        CustomerFactory.create()
        ProviderFactory.create()
        SubscriptionFactory.create()

        url = reverse('proforma-list')
        data = {
            'provider': 'http://testserver/providers/1/',
            'customer': 'http://testserver/customers/1/',
            '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": 1,
            "series": "ProformaSeries",
            "number": None,
            "provider": "http://testserver/providers/1/",
            "customer": "http://testserver/customers/1/",
            "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'),
        }
コード例 #45
0
ファイル: test_proforma.py プロジェクト: PressLabs/silver
    def test_illegal_state_change_when_in_issued_state(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        proforma = ProformaFactory.create(provider=provider, customer=customer)
        proforma.issue()

        url = reverse('proforma-state', kwargs={'pk': proforma.pk})
        data = {'state': 'illegal-state'}

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

        assert response.status_code == status.HTTP_403_FORBIDDEN
        assert response.data == {'detail': 'Illegal state value.'}
        assert Invoice.objects.count() == 0
コード例 #46
0
ファイル: test_proforma.py プロジェクト: Alex-CodeLab/silver
    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)

        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": "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",
            "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": Decimal("0.00"),
            "total_in_transaction_currency": Decimal("0.00"),
            "transactions": []
        })
コード例 #47
0
    def test_cancel_invoice_in_draft_state(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        invoice = InvoiceFactory.create(provider=provider, customer=customer)

        url = reverse('invoice-state', kwargs={'pk': invoice.pk})
        data = {'state': 'canceled'}

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

        assert response.status_code == status.HTTP_403_FORBIDDEN
        assert response.data == {
            'detail': 'An invoice can be canceled only if it is in issued state.'
        }
コード例 #48
0
ファイル: test_provider.py プロジェクト: oucsaw/silver
    def test_POST_bulk_providers(self):
        providers = ProviderFactory.create_batch(5)

        raw_providers = json.loads(serializers.serialize('json', providers))

        serialized_providers = []
        for item in raw_providers:
            serialized_providers.append(item['fields'])

        url = reverse('provider-list')
        response = self.client.post(url, data=json.dumps(serialized_providers, ensure_ascii=True).encode('utf8'),
                                    content_type='application/json')

        assert response.status_code == status.HTTP_201_CREATED
        assert len(response.data) == 5
コード例 #49
0
ファイル: test_provider.py プロジェクト: Athenolabs/silver
    def test_POST_bulk_providers(self):
        providers = ProviderFactory.create_batch(5)

        raw_providers = json.loads(serializers.serialize('json', providers))

        serialized_providers = []
        for item in raw_providers:
            serialized_providers.append(item['fields'])

        url = reverse('provider-list')
        response = self.client.post(url, data=json.dumps(serialized_providers),
                                    content_type='application/json')

        assert response.status_code == status.HTTP_201_CREATED
        assert len(response.data) == 5
コード例 #50
0
ファイル: test_invoice.py プロジェクト: Dynamicic/silver
    def test_illegal_state_change_when_in_issued_state(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        invoice = InvoiceFactory.create(provider=provider, customer=customer)
        invoice.issue()

        url = reverse('invoice-state', kwargs={'pk': invoice.pk})
        data = {'state': 'illegal-state'}

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

        assert response.status_code == status.HTTP_403_FORBIDDEN
        assert response.data == {'detail': 'Illegal state value.'}
コード例 #51
0
ファイル: test_invoice.py プロジェクト: PressLabs/silver
    def test_cancel_invoice_in_canceled_state(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        invoice = InvoiceFactory.create(provider=provider, customer=customer)
        invoice.issue()
        invoice.cancel()

        url = reverse('invoice-state', kwargs={'pk': invoice.pk})
        data = {'state': 'canceled'}

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

        assert response.status_code == status.HTTP_403_FORBIDDEN
        assert response.data == {
            'detail': 'An invoice can be canceled only if it is in issued state.'
        }
コード例 #52
0
ファイル: test_plan.py プロジェクト: intfrr/silver
    def test_create_plan(self):
        url = reverse("plan-list")

        ProductCodeFactory.create_batch(2)
        feature1_pc = ProductCode.objects.get(id=1).value
        plan_pc = ProductCode.objects.get(id=2).value
        provider = ProviderFactory.create()
        provider_url = reverse("provider-detail", kwargs={"pk": provider.pk})
        response = self.client.post(
            url,
            json.dumps(
                {
                    "name": "Hydrogen",
                    "interval": "month",
                    "interval_count": 1,
                    "amount": 149.99,
                    "currency": "USD",
                    "trial_period_days": 15,
                    "generate_after": 86400,
                    "enabled": True,
                    "private": False,
                    "product_code": plan_pc,
                    "metered_features": [
                        {
                            "name": "Page Views",
                            "unit": "100k",
                            "price_per_unit": 0.01,
                            "included_units": 0,
                            "product_code": feature1_pc,
                        },
                        {
                            "name": "VIP Support",
                            "price_per_unit": 49.99,
                            "unit": 1,
                            "included_units": 1,
                            "product_code": "1234",
                        },
                    ],
                    "provider": provider_url,
                }
            ),
            content_type="application/json",
        )

        assert response.status_code == status.HTTP_201_CREATED
コード例 #53
0
    def test_issue_invoice_with_custom_issue_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        invoice = InvoiceFactory.create(provider=provider, customer=customer)

        url = reverse('invoice-state', kwargs={'pk': invoice.pk})
        data = {'state': 'issued', 'issue_date': '2014-01-01'}
        response = self.client.put(url, data=json.dumps(data),
                                   content_type='application/json')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)
        mandatory_content = {
            'issue_date': '2014-01-01',
            'due_date': due_date.strftime('%Y-%m-%d'),
            'state': 'issued'
        }
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(all(item in response.data.items()
                        for item in mandatory_content.iteritems()))
        self.assertNotEqual(response.data.get('archived_provider', {}), {})
        self.assertNotEqual(response.data.get('archived_customer', {}), {})
コード例 #54
0
ファイル: test_proforma.py プロジェクト: PressLabs/silver
    def test_cancel_proforma_with_default_dates(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        proforma = ProformaFactory.create(provider=provider, customer=customer)
        proforma.issue()

        url = reverse('proforma-state', kwargs={'pk': proforma.pk})
        data = {'state': 'canceled'}
        response = self.client.put(url, data=json.dumps(data), content_type='application/json')

        assert response.status_code == status.HTTP_200_OK
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)
        mandatory_content = {
            'issue_date': timezone.now().date().strftime('%Y-%m-%d'),
            'due_date': due_date.strftime('%Y-%m-%d'),
            'cancel_date': timezone.now().date().strftime('%Y-%m-%d'),
            'state': 'canceled'
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in list(response.data.items())
                   for item in mandatory_content.items())
        assert Invoice.objects.count() == 0
コード例 #55
0
ファイル: test_invoice.py プロジェクト: PressLabs/silver
    def test_issue_invoice_with_custom_issue_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        invoice = InvoiceFactory.create(provider=provider, customer=customer)

        url = reverse('invoice-state', kwargs={'pk': invoice.pk})
        data = {'state': 'issued', 'issue_date': '2014-01-01'}
        response = self.client.put(url, data=json.dumps(data),
                                   content_type='application/json')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)
        mandatory_content = {
            'issue_date': '2014-01-01',
            'due_date': due_date.strftime('%Y-%m-%d'),
            'state': 'issued'
        }
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(all(item in list(response.data.items())
                        for item in mandatory_content.items()))
        self.assertNotEqual(response.data.get('archived_provider', {}), {})
        self.assertNotEqual(response.data.get('archived_customer', {}), {})
コード例 #56
0
    def test_payment_processors_list(self):
        provider = ProviderFactory.create()
        url = reverse('provider-payment-processor-list', kwargs={'pk': provider.pk})
        response = self.client.get(url, format='json')

        assert response.status_code == status.HTTP_200_OK
        assert response.data == [OrderedDict([
            ('name', u'Manual'),
            ('type', u'manual'),
            ('url', 'http://testserver/payment_processors/Manual/')
        ])]

        class SomeProcessor(GenericPaymentProcessor, TriggeredProcessorMixin):
            name = "SomeProcessor"

            @staticmethod
            def setup(data=None):
                pass

        PaymentProcessorManager.register(SomeProcessor)

        response = self.client.get(url, format='json')

        assert response.status_code == status.HTTP_200_OK
        assert response.data == [
            OrderedDict([
                ('name', u'SomeProcessor'),
                ('type', u'triggered'),
                ('url', 'http://testserver/payment_processors/SomeProcessor/')
            ]),
            OrderedDict([
                ('name', u'Manual'),
                ('type', u'manual'),
                ('url', 'http://testserver/payment_processors/Manual/')
            ])
        ]

        PaymentProcessorManager.unregister(SomeProcessor)
コード例 #57
0
ファイル: test_invoice.py プロジェクト: samlex20/silver
    def test_post_invoice_with_invoice_entries(self):
        customer = CustomerFactory.create()
        provider = ProviderFactory.create()
        SubscriptionFactory.create()

        url = reverse('invoice-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,
            'invoice_entries': [{
                "description": "Page views",
                "unit_price": 10.0,
                "quantity": 20
            }]
        }

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

        print(response.data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
コード例 #58
0
ファイル: test_plan.py プロジェクト: PressLabs/silver
    def test_create_plan(self):
        url = reverse('plan-list')

        ProductCodeFactory.create_batch(2)
        feature1_pc = ProductCode.objects.all()[0].value
        plan_pc = ProductCode.objects.all()[1].value
        provider = ProviderFactory.create()
        provider_url = reverse('provider-detail',
                               kwargs={'pk': provider.pk})
        response = self.client.post(url, json.dumps({
            "name": "Hydrogen",
            "interval": "month",
            "interval_count": 1,
            "amount": 149.99,
            "currency": "USD",
            "trial_period_days": 15,
            "generate_after": 86400,
            "enabled": True,
            "private": False,
            "product_code": plan_pc,
            'metered_features': [
                {'name': 'Page Views',
                 'unit': '100k',
                 'price_per_unit': 0.01,
                 'included_units': 0,
                 'product_code': feature1_pc},
                {'name': 'VIP Support',
                 'price_per_unit': 49.99,
                 'unit': 1,
                 'included_units': 1,
                 'product_code': "1234"}
            ],
            'provider': provider_url
        }), content_type='application/json')

        assert response.status_code == status.HTTP_201_CREATED