Skip to content
This repository has been archived by the owner on Aug 28, 2020. It is now read-only.

Mock network requests for faster unit testing #13 #84

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hydrosquall
Copy link
Contributor

@hydrosquall hydrosquall commented Oct 23, 2017

Description of the change:

  • Addresses the HTTP Requests part of Create unit tests #13. I wasn't sure how to mock the DB requests, so I left those alone.
  • Uses VCR.py to record the HTTP interactions once, and stores the results in a tests/fixtures folder. I redacted the API key that was used to get this data, and used unittest.patch to path the HTTP requests so that the cassettes could be reused later.

Reason for the change:

  • Tests run more slowly when they need to make live network requests
  • Testing can't happen if the developer doesn't have internet connection
  • Adding mocked fixtures fixes this.

Checklist

Make sure all of these items are complete, or else the PR will be ineligible for a code review.

  • Code passes all existing tests
  • Any new functionality added includes new unit tests in tests/test.py
  • Create or update example code to show the new functionality in action.
  • All code, branch, and git naming and style conventions are followed (see CONTRIBUTING.md)
  • Feature branch has been rebased off of the latest master branch. ( see CONTRIBUTING.md ).

@thinkingserious
Copy link
Contributor

Hi @hydrosquall,

This is awesome! I think we will create a new issue to deal with the DB mocks. I'm not sure the best way to do that either. Perhaps if we query a few people in this repos, we might find a great solution.

With regards to the failing tests, it seems we need to update the requirements files to include the missing dependencies. Could you please update those?

With Best Regards,

Elmer

@hydrosquall
Copy link
Contributor Author

hydrosquall commented Nov 3, 2017

Hey @thinkingserious : How would you feel about dropping support for Python 3.2?

Otherwise, I'll need to figure out a way to install the library below only for the build that happens on version 3.2, since mock has been in the standard library since 3.3.

https://pypi.python.org/pypi/mock/

@thinkingserious
Copy link
Contributor

HI @hydrosquall,

I'm not opposed to requiring that dependency for 3.2 development.

@hydrosquall hydrosquall force-pushed the feature/ISSUE-13_mock-network-requests branch from 57aee5c to 58e9d25 Compare November 3, 2017 21:35
@hydrosquall hydrosquall force-pushed the feature/ISSUE-13_mock-network-requests branch from 16d33f1 to 113b5a0 Compare November 3, 2017 21:42
@hydrosquall
Copy link
Contributor Author

@thinkingserious : I think my latest changes should fix the build. In the future, we may want to write some separate tests that are able to test just the HTTP requests, without having the dependency on the DB mocks. As it stands, I think all of the tests might depend on the database with the exception of the "send email" test.

@thinkingserious
Copy link
Contributor

Thanks @hydrosquall!

@hydrosquall
Copy link
Contributor Author

Hey @thinkingserious , it looks like VCR.py fails to install on just the python 3.2 build :(.

@thinkingserious
Copy link
Contributor

Hi @hydrosquall,

Thanks for the further detail! Once this issue pops up on our backlog, I'll dig deeper.

With Best Regards,

Elmer

number_of_watchers=0,
number_of_stargazers=0,
number_of_forks=0
)
res = self.db.add_data(github_data_import)
self.assertTrue(isinstance(res, GitHubData))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@42B thanks for catching these items - with that said, these lines fall outside the scope of the topics for this active PR, if you're interested, maybe those changes could go into a separate PR

php_downloads=0,
python_downloads=0,
ruby_downloads=0
)
res = self.db.add_data(packagedata)
self.assertTrue(isinstance(res, PackageManagerData))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.config.github_repos[0])
config = MOCK_DATA['github_config']
res = self.github.update_library_data(config['user'],
config['repositories'][0])
self.assertTrue(isinstance(res, GitHubData))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def test_update_package_manager_data(self):
if os.environ.get('TRAVIS') == None:
res = self.pm.update_package_manager_data(
self.config.package_manager_urls)
MOCK_DATA['package_urls'])
self.assertTrue(isinstance(res, PackageManagerData))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants