Skip to content
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

4 unit tests are network dependent. #1618

Closed
karlcow opened this issue Jun 27, 2017 · 4 comments
Closed

4 unit tests are network dependent. #1618

karlcow opened this issue Jun 27, 2017 · 4 comments

Comments

@karlcow
Copy link
Member

karlcow commented Jun 27, 2017

When working with @brizental for an issue she had with tests, we also found out that 4 unit tests are failing if the network is off.

ERROR: API access to comments greater than 30 returns pagination in Link
Traceback (most recent call last):
  File "/Users/karl/code/webcompat.com/tests/test_api_urls.py", line 81, in test_api_comments_link_header_auth
    query_string=query_string, environ_base=headers)

ERROR: API issue for a non existent number returns JSON 404.
Traceback (most recent call last):
  File "/Users/karl/code/webcompat.com/tests/test_api_urls.py", line 45, in test_api_issues_out_of_range
    rv = self.app.get('/api/issues/1000000', environ_base=headers)

ERROR: API access to labels without auth returns JSON 200.
Traceback (most recent call last):
  File "/Users/karl/code/webcompat.com/tests/test_api_urls.py", line 69, in test_api_labels_without_auth
    rv = self.app.get('/api/issues/labels', environ_base=headers)

ERROR: Checks 500 is not accepted for /issues/new POST.
Traceback (most recent call last):
  File "/Users/karl/code/webcompat.com/tests/test_urls.py", line 129, in test_new_issue_should_not_crash
    rv = self.app.post('/issues/new', data=data)

These need to work even if the network is off.

@wisniewskit
Copy link
Member

I am just commenting upon request, please ignore this comment!

@brizental
Copy link
Contributor

brizental commented Jul 26, 2017

I was looking at this issue and the reason why some tests from test_api_urls.py fail is that we don't start the server is test mode for this suite. We even have a comment saying that we don't want fixture data for this suite in particular (https://github.com/webcompat/webcompat.com/blob/master/tests/test_api_urls.py#L28-L29). Maybe we could put these three tests that do require fixture data in another test file. What do you think, @karlcow?

@karlcow
Copy link
Member Author

karlcow commented Jul 26, 2017

That's one possibility. Another one is to mock the data (if we can). I tried a couple of times, was close to manage it, but there was still a small things missing. Mocking is less complicated than I thought at the beginning.
see

def test_build_query_string(self):
testdt = datetime.datetime(2006, 1, 1, 0, 0, 0, 0)
with patch('datetime.datetime') as dt_mock:
dt_mock.utcnow.return_value = testdt
self.assertEqual(topsites.build_query_string('CN', 1),
TEST_QUERY_STRING)

@karlcow
Copy link
Member Author

karlcow commented Aug 7, 2017

Oh and this PR is probably one of the nails into finishing #396

brizental added a commit that referenced this issue Aug 11, 2017
brizental added a commit that referenced this issue Aug 11, 2017
Fixes #1618 - Get all unittests to be network independent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants