Skip to content

Commit

Permalink
Improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Nov 20, 2018
1 parent 575127c commit 9c040dd
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions test/unit/connectors/OCCI.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def test_10_concrete(self):
self.assertEqual(len(concrete), 1)
self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())

def test_15_concrete_appdb(self):
@patch('requests.request')
def test_15_concrete_appdb(self, requests):
radl_data = """
network net ()
system test (
Expand All @@ -133,11 +134,12 @@ def test_15_concrete_appdb(self):
occi_cloud = self.get_occi_cloud()
occi_cloud.cloud.server = "carach5.ics.muni.cz"

requests.side_effect = self.get_response
concrete = occi_cloud.concreteSystem(radl_system, auth)
self.assertEqual(len(concrete), 1)
self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())

def get_response(self, method, url, verify, cert, headers, data):
def get_response(self, method, url, verify, cert=None, headers=None, data=None):
resp = MagicMock()
parts = uriparse(url)
url = parts[2]
Expand Down Expand Up @@ -173,6 +175,31 @@ def get_response(self, method, url, verify, cert, headers, data):
resp.headers = {'X-Subject-Token': 'token1'}
elif url.endswith("/link/storagelink/compute_10_disk_1"):
resp.status_code = 404
elif url == "/rest/1.0/va_providers":
resp.status_code = 200
resp.text = """<appdb:appdb>
<virtualization:provider id="4454G0" in_production="true">
<provider:name>CESNET-MetaCloud</provider:name>
</virtualization:provider>
<virtualization:provider id="id" in_production="true">
<provider:name>some</provider:name>
</virtualization:provider>
</appdb:appdb>"""
elif url == "/rest/1.0/va_providers/4454G0":
resp.status_code = 200
resp.text = """<appdb:appdb>
<virtualization:provider id="4454G0" in_production="true">
<provider:endpoint_url>https://carach5.ics.muni.cz:11443</provider:endpoint_url>
<provider:image
va_provider_image_id="http://url/os_tpl#image_id"
appcname="egi.docker.ubuntu.16.04"
voname="fedcloud.egi.eu"/>
<provider:image
va_provider_image_id="http://url/os_tpl#image_id2"
appcname="egi.ubuntu.16.04"
voname="fedcloud.egi.eu"/>
</virtualization:provider>
</appdb:appdb>"""
elif method == "POST":
if url == "/compute/":
if self.return_error:
Expand Down

0 comments on commit 9c040dd

Please sign in to comment.