Skip to content

Commit

Permalink
Updated test cases for connection module to increase the coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sijeesh committed Dec 13, 2019
1 parent 727f79c commit f34a432
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/unit/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ def test_download_to_stream_when_status_ok(self, mock_get_conn, mock_sleep):

mock_stream = Mock()

result = self.connection.download_to_stream(mock_stream, '/rest/download.zip')
result = self.connection.download_to_stream(mock_stream, '/rest/download.zip',
custom_headers={'custom': 'custom'})

self.assertTrue(result)
mock_stream.write.assert_has_calls([call('111'), call('222'), call('333')])
Expand Down Expand Up @@ -878,6 +879,16 @@ def test_do_http_with_timeout_error(self, mock_get_connection):

self.assertTrue('timed out' in context.exception.msg)

@patch.object(connection, 'get')
def test_get_by_uri(self, mock_get):
uri = "/rest/uri"
self.connection.get_by_uri(uri)
mock_get.assert_called_once_with(uri)

def test_make_url(self):
url = self.connection.make_url('/test/path')
self.assertEqual(url, url)

@patch.object(connection, 'get')
@patch.object(connection, 'post')
def test_login(self, mock_post, mock_get):
Expand Down Expand Up @@ -939,8 +950,8 @@ def test_login_with_exception_in_put(self, mock_put, mock_get):
def test_login_with_exception_in_put_username_password_sessionID(self, mock_put, mock_get):
mock_get.side_effect = [{'minimumVersion': 300, 'currentVersion': 400}]
mock_put.side_effect = HPOneViewException("Failed")

self.assertRaises(HPOneViewException, self.connection.login, {"userName": "administrator", "password": "", "sessionID": "123"})
self.assertRaises(HPOneViewException, self.connection.login, {"userName": "administrator",
"password": "", "sessionID": "123"})

@patch.object(connection, 'get')
def test_validate_version_exceeding_minimum(self, mock_get):
Expand Down

0 comments on commit f34a432

Please sign in to comment.