Skip to content

Commit

Permalink
update testing for #205
Browse files Browse the repository at this point in the history
* move resource group fixture to session (needs change https://gitlab.com/saltstack/pop/pytest-pop/-/merge_requests/4)
* make resource_group fixture allocate the resource group instead of just creating a string
* update resource group test since it is now a fixture
* on shutdown of the test session, remove the resource group which should cascade to remove all resources in the group
* move duplicated password fixture up to the common fixture config

Signed-off-by: Tom Scanlan <tscanlan@vmware.com>
  • Loading branch information
tompscanlan committed Apr 21, 2021
1 parent 7922ea1 commit 144e7b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
17 changes: 15 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ def tags():


@pytest.fixture(scope="session")
def resource_group():
yield "rg-idem-inttest-" + "".join(
async def resource_group(hub, ctx, location):
name = "rg-idem-inttest-" + "".join(
random.choice(string.ascii_lowercase + string.digits) for _ in range(20)
)

await hub.states.azurerm.resource.group.present(ctx, name, location)
yield name

# Clean up
await hub.states.azurerm.resource.group.absent(ctx, name, location)


@pytest.fixture(scope="session")
def vm():
Expand Down Expand Up @@ -190,3 +196,10 @@ def acr():
yield "acrideminttest" + "".join(
random.choice(string.ascii_lowercase + string.digits) for _ in range(8)
)


@pytest.fixture(scope="session")
def password():
yield "#PASS" + "".join(
random.choice(string.ascii_lowercase + string.digits) for _ in range(16)
) + "!"
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
import string


@pytest.fixture(scope="session")
def password():
yield "#PASS" + "".join(
random.choice(string.ascii_lowercase + string.digits) for _ in range(16)
) + "!"


@pytest.mark.run(order=5)
@pytest.mark.asyncio
async def test_present(hub, ctx, vm, resource_group, vnet, subnet, password):
Expand Down
7 changes: 0 additions & 7 deletions tests/integration/states/azurerm/postgresql/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
import string


@pytest.fixture(scope="session")
def password():
yield "#" + "".join(
random.choice(string.ascii_lowercase + string.digits) for _ in range(16)
) + "!"


@pytest.mark.run(order=3)
@pytest.mark.asyncio
async def test_present(hub, ctx, postgresql_server, resource_group, location, password):
Expand Down
14 changes: 3 additions & 11 deletions tests/integration/states/azurerm/resource/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@
@pytest.mark.asyncio
async def test_present(hub, ctx, resource_group, location):
expected = {
"changes": {
"new": {
"location": location,
"name": resource_group,
"type": "Microsoft.Resources/resourceGroups",
"properties": {"provisioning_state": "Succeeded"},
},
"old": {},
},
"comment": f"Resource group {resource_group} has been created.",
"name": resource_group,
"result": True,
"comment": f"Resource group {resource_group} is already present.",
"changes": {},
}

ret = await hub.states.azurerm.resource.group.present(ctx, resource_group, location)
ret["changes"]["new"].pop("id")
assert ret == expected


Expand Down

0 comments on commit 144e7b2

Please sign in to comment.