Skip to content

Commit

Permalink
fix WCS unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBogdan committed Mar 26, 2021
1 parent dc49e20 commit 91ee755
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions test/tools/test_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ def test_create(self, mock_get_cluster_config, mock_set_bearer, mock_requests):

wcs = WCS(AuthClientPassword('test_user', 'test_pass'), dev=True)
wcs.auth_bearer = 'test_auth'
mock_get_cluster_config.side_effect = lambda name: {
progress = lambda name, prog = 99: {
'meta': {'PublicURL': f'{name}.semi.network'},
'status': {
'state': {'percentage': 99}
'state': {'percentage': prog}
}
}

mock_get_cluster_config.side_effect = progress
config = {
'id': 'Test_name',
'email': '[email protected]',
Expand Down Expand Up @@ -188,22 +190,24 @@ def test_create(self, mock_get_cluster_config, mock_set_bearer, mock_requests):
)
self.assertEqual(result, 'https://test_id.semi.network')

with patch('weaviate.tools.wcs.WCS.is_ready') as mock_obj:
mock_obj.side_effect = lambda x: True if mock_obj.call_count == 2 else False
mock_requests.post.return_value = Mock(status_code=202)
result = wcs.create(cluster_name='weaviate', wait_for_completion=True)
mock_requests.post.assert_called_with(
url='https://dev.wcs.api.semi.technology/v1/clusters',
data=json.dumps({'id': 'weaviate', 'configuration': {'tier': 'sandbox', 'modules': []}}).encode("utf-8"),
headers={"content-type": "application/json", 'Authorization': 'Bearer test_auth'},
timeout=(2, 20)
)
self.assertEqual(result, 'https://weaviate.semi.network')
mock_get_cluster_config.reset_mock()
mock_get_cluster_config.side_effect = lambda x: progress('weaviate', 100) if mock_get_cluster_config.call_count == 2 else progress('weaviate')
mock_requests.post.return_value = Mock(status_code=202)
result = wcs.create(cluster_name='weaviate', wait_for_completion=True)
mock_requests.post.assert_called_with(
url='https://dev.wcs.api.semi.technology/v1/clusters',
data=json.dumps({'id': 'weaviate', 'configuration': {'tier': 'sandbox', 'modules': []}}).encode("utf-8"),
headers={"content-type": "application/json", 'Authorization': 'Bearer test_auth'},
timeout=(2, 20)
)
self.assertEqual(result, 'https://weaviate.semi.network')

# for PROD
wcs = WCS(AuthClientPassword('test_user', 'test_pass'), dev=False)
wcs.auth_bearer = 'test_auth'

mock_get_cluster_config.side_effect = progress

mock_requests.post.return_value = Mock(status_code=400, text='Cluster already exists!')
result = wcs.create(cluster_name='my-url')
mock_requests.post.assert_called_with(
Expand Down

0 comments on commit 91ee755

Please sign in to comment.