-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RSDK-4907 - Add billing client #471
Conversation
async def GetBillingSummary(self, stream: Stream[GetBillingSummaryRequest, GetBillingSummaryResponse]) -> None: | ||
raise NotImplementedError() | ||
|
||
async def GetCurrentMonthUsageSummary( | ||
self, | ||
stream: Stream[GetCurrentMonthUsageSummaryRequest, GetCurrentMonthUsageSummaryResponse], | ||
) -> None: | ||
raise NotImplementedError() | ||
|
||
async def GetInvoiceHistory(self, stream: Stream[GetInvoiceHistoryRequest, GetInvoiceHistoryResponse]) -> None: | ||
raise NotImplementedError() | ||
|
||
async def GetItemizedInvoice(self, stream: Stream[GetItemizedInvoiceRequest, GetItemizedInvoiceResponse]) -> None: | ||
raise NotImplementedError() | ||
|
||
async def GetUnpaidBalance(self, stream: Stream[GetUnpaidBalanceRequest, GetUnpaidBalanceResponse]) -> None: | ||
raise NotImplementedError() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods are slated to be deprecated and so are not being implemented.
assert service.org_id == org_id | ||
|
||
@pytest.mark.asyncio | ||
async def test_get_invoice_pdf(self, service: MockBilling): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to reviewers: the client code for get_invoice_pdf
saves the pdf to a file. I didn't really want to mess around with having a test in CI that creates and modifies files, and the only other alternative I could think of (make the filepath optional, return the pdf's byte array instead of nothing, and then compare to that return value) I think would be a bad API change to the get_invoice_pdf
method (the byte array is not particularly human parse-able or useful outside of being saved to a pdf). In local testing I was able to download and save invoice PDFs successfully so I figured that was good enough. If there's any disagreement with the above, let me know!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable to me
src/viam/app/billing_client.py
Outdated
response: GetInvoicePdfResponse = await self._billing_client.GetInvoicePdf(request, metadata=self._metadata, timeout=timeout) | ||
data: bytes = response[0].chunk | ||
file = open(dest, "wb") | ||
file.write(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be followed with a file.flush()
.
And probably an os.fsync(file)
, but that's less likely to prevent a surprising behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh good callout, thanks! Also adding file.flush()
to other app client methods that write to file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Post-approve realization mentioned in person: We should be file.close()
ing here, or with open(...) as file:
. Which omits the need for a flush
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just switched to with open
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still lgtm
Major changes
Adds billing client to python SDK.