APIs & Integrations

jacobi
Member

Testing the APIs inside library unit tests

SOLVE

Hey everyone!

 

I maintain a python library for some of the HubSpot APIs, and was recently reworking some of my unit tests to make contributing a bit easier.

 

I had been using the demo hapi key for a few of the API calls (I know not great but just needed something to start with) to ensure that we got data similar to what HubSpot would actually return during real use - this worked fine with only a few tests, but after adding more (and having other contributors running the tests locally) we're hitting the daily limit for API calls on that key, which in turn causes all of our tests to fail.

 

Someone brought up the idea of just writing mocks for all of your APIs to test against (and we can do that if need be), but that also somewhat defeats the purpose, as we'd be maintaining an example of what each API returns, and if anything changed on HubSpot's end, we'd no longer know as we're not hitting the real API endpoints.

 

So I'm wondering what the best course of action is here - we could definitely mock stuff, but it's not really optimal. If there were any way to get a new hapi key specific to testing the APIs (that perhaps had a slightly higher limit on API calls), that'd be awesome! I'd love to be able to actually hit the API during tests if possible.


Thanks for your time!

0 Upvotes
1 Accepted solution
Derek_Gervais
Solution
HubSpot Alumni
HubSpot Alumni

Testing the APIs inside library unit tests

SOLVE

Hey @jacobi ,

 

That's a good question. I'd actually recommend creating your own HubSpot Test Account and using that instead. That would allow you and other collaborators to continue to take advantage of the live responses, without needing to share an API limit with the broader HubSpot community. 

View solution in original post

0 Upvotes
6 Replies 6
Derek_Gervais
Solution
HubSpot Alumni
HubSpot Alumni

Testing the APIs inside library unit tests

SOLVE

Hey @jacobi ,

 

That's a good question. I'd actually recommend creating your own HubSpot Test Account and using that instead. That would allow you and other collaborators to continue to take advantage of the live responses, without needing to share an API limit with the broader HubSpot community. 

0 Upvotes
jacobi
Member

Testing the APIs inside library unit tests

SOLVE

Hey Derek, thanks for the reply!

 

Where can I create a test account for this? I saw this link, but I don't see that view or any of those buttons inside my developer account.

 

Is that something that is tied to my company's HubSpot account, or is that something that could be entirely seperate?

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Testing the APIs inside library unit tests

SOLVE

Hey @jacobi ,

 

That's odd; the UI has been tweaked a little bit, but the 'Testing' button should still appear in the nav. Can you send me your Hub ID?

0 Upvotes
jacobi
Member

Testing the APIs inside library unit tests

SOLVE

Ah, I must've been looking in the wrong place! I've found the 'Testing' button, and I've created a test account.

 

Is the renewal every 90 days required? Is there an official way to automate renewals, or will this be something I'll need to keep an eye on?

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Testing the APIs inside library unit tests

SOLVE

Hey @jacobi ,

 

That's a great question; test portals are automatically renewed if there's any request traffic from one of the Developer Account's apps. So you could create an app to install in the test portal, and periodically make some request(s) to the test portal to keep it active indefinitely.

0 Upvotes
jacobi
Member

Testing the APIs inside library unit tests

SOLVE

Awesome! I'll give that a try - thanks for your help, Derek!