-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from duplocloud/integration-tests
Integration tests
- Loading branch information
Showing
5 changed files
with
135 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,75 @@ | ||
import math | ||
import pytest | ||
import time | ||
import random | ||
|
||
from duplocloud.errors import DuploError | ||
from duplocloud.errors import DuploError, DuploFailedResource | ||
from duplocloud.client import DuploClient | ||
|
||
duplo, _ = DuploClient.from_env() | ||
|
||
@pytest.mark.integration | ||
def test_listing_infrastructures(): | ||
r = duplo.load("infrastructure") | ||
try: | ||
lot = r("list") | ||
except DuploError as e: | ||
pytest.fail(f"Failed to list infrastructures: {e}") | ||
@pytest.fixture(scope="module") | ||
def infra_name(): | ||
inc = random.randint(1, 100) | ||
return f"duploctl{inc}" | ||
|
||
@pytest.mark.integration | ||
def test_finding_infra(): | ||
r = duplo.load("tenant") | ||
try: | ||
t = r("find", "default") | ||
except DuploError as e: | ||
pytest.fail(f"Failed to find default infra: {e}") | ||
assert t["AccountName"] == "default" | ||
class TestInfra: | ||
|
||
@pytest.mark.integration | ||
def test_creating_infrastructures(): | ||
r = duplo.load("infrastructure") | ||
inc = random.randint(1, 100) | ||
vnum = math.ceil(random.randint(1, 9)) | ||
name = f"duploctl{inc}" | ||
try: | ||
r.create({ | ||
"Name": name, | ||
"Accountid": "", | ||
"EnableK8Cluster": False, | ||
"AzCount": 2, | ||
"Vnet": { | ||
"SubnetCidr": 22, | ||
"AddressPrefix": f"11.2{vnum}0.0.0/16" | ||
}, | ||
"Cloud": 0, | ||
"OnPremConfig": None, | ||
"Region": "us-west-2", | ||
"CustomData": [], | ||
}, wait=True) | ||
except DuploError as e: | ||
pytest.fail(f"Failed to create tenant: {e}") | ||
try: | ||
i = r.find(name) | ||
assert i["Name"] == name | ||
except DuploError as e: | ||
pytest.fail(f"Failed to find infrastructure {name}: {e}") | ||
try: | ||
r("delete", name) | ||
except DuploError as e: | ||
pytest.fail(f"Failed to delete infrastructure: {e}") | ||
@pytest.mark.integration | ||
def test_listing_infrastructures(self): | ||
r = duplo.load("infrastructure") | ||
try: | ||
lot = r("list") | ||
except DuploError as e: | ||
pytest.fail(f"Failed to list infrastructures: {e}") | ||
|
||
@pytest.mark.integration | ||
def test_finding_infra(self): | ||
r = duplo.load("tenant") | ||
try: | ||
t = r("find", "default") | ||
except DuploError as e: | ||
pytest.fail(f"Failed to find default infra: {e}") | ||
assert t["AccountName"] == "default" | ||
|
||
@pytest.mark.integration | ||
@pytest.mark.dependency(name = "create_infra") | ||
def test_creating_infrastructures(self, infra_name): | ||
r = duplo.load("infrastructure") | ||
vnum = math.ceil(random.randint(1, 9)) | ||
name = infra_name | ||
print(f"Creating infra '{name}'") | ||
try: | ||
r.create({ | ||
"Name": name, | ||
"Accountid": "", | ||
"EnableK8Cluster": False, | ||
"AzCount": 2, | ||
"Vnet": { | ||
"SubnetCidr": 22, | ||
"AddressPrefix": f"11.1{vnum}0.0.0/16" | ||
}, | ||
"Cloud": 0, | ||
"OnPremConfig": None, | ||
"Region": "us-east-1", | ||
"CustomData": [], | ||
}, wait=True) | ||
except DuploFailedResource as e: | ||
pytest.fail(f"Infrastructure is in a failed state: {e}") | ||
except DuploError as e: | ||
pytest.fail(f"Failed to create tenant: {e}") | ||
|
||
@pytest.mark.integration | ||
@pytest.mark.dependency(depends=["create_infra"]) | ||
def test_find_delete_infra(self, infra_name): | ||
r = duplo.load("infrastructure") | ||
name = infra_name | ||
print(f"Deleting infra '{name}'") | ||
try: | ||
i = r.find(name) | ||
assert i["Name"] == name | ||
except DuploError as e: | ||
pytest.fail(f"Failed to find infrastructure {name}: {e}") | ||
try: | ||
r("delete", name) | ||
except DuploError as e: | ||
pytest.fail(f"Failed to delete infrastructure: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters