# Testing the APIs inside library unit tests

**URL:** <https://community.hubspot.com/t/testing-the-apis-inside-library-unit-tests/14965>\
**Category:** APIs & Integrations\
**Tags:** developer-tools\
**Created:** [June 25, 2019, 3:40pm UTC](https://community.hubspot.com/t/testing-the-apis-inside-library-unit-tests/14965 "2019-06-25T15:40:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacobi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jacobi/32/64485_2.png) [@jacobi](https://community.hubspot.com/u/jacobi)\
**Post date:** [June 25, 2019, 3:40pm UTC](https://community.hubspot.com/t/testing-the-apis-inside-library-unit-tests/14965/1 "2019-06-25T15:40:48Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Derek\_Gervais](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/derek_gervais/32/17429_2.png) [@Derek\_Gervais](https://community.hubspot.com/u/Derek_Gervais)\
**Post date:** [June 26, 2019, 9:30pm UTC](https://community.hubspot.com/t/testing-the-apis-inside-library-unit-tests/14965/2 "2019-06-26T21:30:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jacobi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jacobi/32/64485_2.png) [@jacobi](https://community.hubspot.com/u/jacobi)\
**Post date:** [June 27, 2019, 1:49pm UTC](https://community.hubspot.com/t/testing-the-apis-inside-library-unit-tests/14965/3 "2019-06-27T13:49:52Z")

</div>

Hey Derek, thanks for the reply!

Where can I create a test account for this? I saw [this link,](https://developers.hubspot.com/docs/faq/how-do-i-create-a-test-account) 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?

---

<div class="post-metadata">

**Author:** ![Derek\_Gervais](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/derek_gervais/32/17429_2.png) [@Derek\_Gervais](https://community.hubspot.com/u/Derek_Gervais)\
**Post date:** [June 27, 2019, 3:17pm UTC](https://community.hubspot.com/t/testing-the-apis-inside-library-unit-tests/14965/4 "2019-06-27T15:17:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jacobi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jacobi/32/64485_2.png) [@jacobi](https://community.hubspot.com/u/jacobi)\
**Post date:** [June 27, 2019, 3:40pm UTC](https://community.hubspot.com/t/testing-the-apis-inside-library-unit-tests/14965/5 "2019-06-27T15:40:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Derek\_Gervais](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/derek_gervais/32/17429_2.png) [@Derek\_Gervais](https://community.hubspot.com/u/Derek_Gervais)\
**Post date:** [June 27, 2019, 5:57pm UTC](https://community.hubspot.com/t/testing-the-apis-inside-library-unit-tests/14965/6 "2019-06-27T17:57:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jacobi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jacobi/32/64485_2.png) [@jacobi](https://community.hubspot.com/u/jacobi)\
**Post date:** [June 28, 2019, 12:25pm UTC](https://community.hubspot.com/t/testing-the-apis-inside-library-unit-tests/14965/7 "2019-06-28T12:25:30Z")

</div>

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