Skip to content

Commit a7be9a0

Browse files
committed
Add tests and fixtures for the Licenses API wrapper
1 parent 2b0e130 commit a7be9a0

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

tests/api/test_licenses.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
1-
#!/usr/bin/env python
21
# -*- coding: utf-8 -*-
2+
3+
"""pytest Licenses API wrapper tests and fixtures."""
4+
5+
6+
import pytest
7+
8+
import ciscosparkapi
9+
10+
11+
# Helper Functions
12+
13+
def get_list_of_licenses(api, orgId=None, max=None):
14+
return api.licenses.list(orgId=orgId, max=max)
15+
16+
17+
def get_license_by_id(api, licenseId):
18+
return api.licenses.get(licenseId)
19+
20+
21+
def is_valid_license(obj):
22+
return isinstance(obj, ciscosparkapi.License) and obj.id is not None
23+
24+
25+
def are_valid_licenses(iterable):
26+
return all([is_valid_license(obj) for obj in iterable])
27+
28+
29+
# pytest Fixtures
30+
31+
@pytest.fixture(scope="session")
32+
def licenses_list(api):
33+
return list(get_list_of_licenses(api))
34+
35+
36+
@pytest.fixture(scope="session")
37+
def licenses_dict(licenses_list):
38+
return {lic.name: lic for lic in licenses_list}
39+
40+
41+
# Tests
42+
43+
class TestLicensesAPI(object):
44+
"""Test LicensesAPI methods."""
45+
46+
def test_list_licenses(self, licenses_list):
47+
assert are_valid_licenses(licenses_list)
48+
49+
def test_list_licenses_with_paging(self, api):
50+
paging_generator = get_list_of_licenses(api, max=1)
51+
licenses = list(paging_generator)
52+
assert licenses > 1
53+
assert are_valid_licenses(licenses)
54+
55+
def test_get_licenses_for_organization(self, api, me):
56+
licenses = list(get_list_of_licenses(api, orgId=me.orgId))
57+
assert are_valid_licenses(licenses)
58+
59+
def test_get_license_by_id(self, api, licenses_list):
60+
assert len(licenses_list) >= 1
61+
license_id = licenses_list[0].id
62+
license = get_license_by_id(api, licenseId=license_id)
63+
assert is_valid_license(license)

0 commit comments

Comments
 (0)