Example #1
0
    def test_new_client(self):
        client = invoiced.Client('api_key')

        self.assertEqual('api_key', client.api_key)
        self.assertEqual('https://api.invoiced.com', client.api_url)
        self.assertIsInstance(client.Customer, invoiced.Customer)
        self.assertIsInstance(client.Invoice, invoiced.Invoice)
        self.assertIsInstance(client.Subscription, invoiced.Subscription)
Example #2
0
    def test_read_timeout(self):
        responses.add(responses.GET,
                      'https://api.invoiced.com/invoices',
                      body=ReadTimeout('Something went wrong'))

        client = invoiced.Client('test')

        with self.assertRaises(invoiced.errors.ApiConnectionError):
            client.request("GET", "/invoices")
Example #3
0
    def test_api_error(self):
        responses.add(responses.POST,
                      'https://api.invoiced.com/invoices',
                      json={'message': 'error'},
                      status=500)

        client = invoiced.Client('test')

        with self.assertRaises(invoiced.errors.ApiError):
            client.request("POST", "/invoices")
Example #4
0
    def test_api_error_invalid_json(self):
        responses.add(responses.POST,
                      'https://api.invoiced.com/invoices',
                      body='not valid json',
                      content_type='application/json',
                      status=400)

        client = invoiced.Client('test')

        with self.assertRaises(invoiced.errors.ApiError):
            client.request("POST", "/invoices")
Example #5
0
    def test_post_request(self):
        responses.add(responses.POST,
                      'https://api.invoiced.com/invoices',
                      status=204,
                      adding_headers={'Header': 'test'})

        client = invoiced.Client('test')

        params = {"test": "property"}
        response = client.request("POST", "/invoices", params)

        expectedResponse = {
            'code': 204,
            'headers': {
                'Header': 'test',
                'Content-Type': 'text/plain'
            },
            'body': None
        }
        self.assertEqual(response, expectedResponse)
Example #6
0
def sync_streams(config, state, catalog):

    # Build the Invoiced client
    # config values are _always_ strings.
    is_sandbox = config.get('sandbox') == 'true'
    client = invoiced.Client(config['api_key'], is_sandbox)

    # Find the user-selected streams
    selected_stream_ids = get_selected_streams(catalog)

    # Loop over streams in catalog
    for stream in catalog.streams:
        stream_id = stream.tap_stream_id
        if stream_id in selected_stream_ids:
            # Write out the schemas
            schema_dict = stream.schema.to_dict()
            stream_metadata = metadata.to_map(stream.metadata)
            singer.write_schema(stream_id, schema_dict, stream.key_properties)

            # Then write out the records
            sync(client, config, state, stream_id, schema_dict,
                 stream_metadata)
Example #7
0
def index(request):
    clients = Client.objects.all()
    orders = Order.objects.all()
    for order in orders:
        # print(order.client.name)
        # print(order.client.email)
        # print(order.client.payment_type)
        # print(order.order_number)
        if order.invoice_checkbox is True:
            my_client = invoiced.Client("g7faIDdCVW7yByH09PR9oq18pBQNMgiL",
                                        True)
            # try:
            #     customer = my_client.Customer.retrieve(number=str(order.order_number))
            # except:
            customer = my_client.Customer.create(
                name=order.client.name,
                email=order.client.email,
                payment_terms=order.client.payment_type,
                number=str(order.order_number))
            my_items = [{
                'name': "HEYY",
                'quantity': 1,
                'unit_cost': 20
            }, {
                'catalog_item': "delivery",
                'quantity': 1
            }]
            my_taxes = [{'amount': 3}]
            invoice = my_client.Invoice.create(
                customer=customer.id,
                payment_terms=order.client.payment_type,
                items=my_items,
                taxes=my_taxes)
            emails = invoice.send()
            order.status = INVOICE_SENT
        else:
            continue
    return HttpResponse("<h1>The invoices have been sent successfully!!</h1> ")
Example #8
0
    def test_get_request(self):
        def request_callback(request):
            # verify headers
            self.assertEqual(request.headers['authorization'],
                             "Basic dGVzdDo=")  # noqa
            self.assertEqual(request.headers['content-type'],
                             "application/json")  # noqa
            self.assertEqual(request.headers['user-agent'],
                             "Invoiced Python/" + invoiced.VERSION)  # noqa

            headers = {'Header': 'test', 'Content-Type': 'application/json'}
            body = {'test': True}
            return (200, headers, json.dumps(body))

        responses.add_callback(
            responses.GET,
            'https://api.invoiced.com/invoices?filter[levels]=work&test=property',  # noqa
            match_querystring=True,
            callback=request_callback)

        client = invoiced.Client('test')

        params = {'test': 'property', 'filter': {'levels': 'work'}}
        response = client.request('GET', '/invoices', params)

        expectedResponse = {
            'code': 200,
            'headers': {
                'Header': 'test',
                'Content-Type': 'application/json'
            },
            'body': {
                'test': True
            }
        }
        self.assertEqual(response, expectedResponse)
Example #9
0
 def setUp(self):
     self.client = invoiced.Client('api_key')