|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +"""pytest Roles 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_roles(api, max=None): |
| 14 | + return api.roles.list(max=max) |
| 15 | + |
| 16 | + |
| 17 | +def get_role_by_id(api, roleId): |
| 18 | + return api.roles.get(roleId) |
| 19 | + |
| 20 | + |
| 21 | +def is_valid_role(obj): |
| 22 | + return isinstance(obj, ciscosparkapi.Role) and obj.id is not None |
| 23 | + |
| 24 | + |
| 25 | +def are_valid_roles(iterable): |
| 26 | + return all([is_valid_role(obj) for obj in iterable]) |
| 27 | + |
| 28 | + |
| 29 | +# pytest Fixtures |
| 30 | + |
| 31 | +@pytest.fixture(scope="session") |
| 32 | +def roles_list(api): |
| 33 | + return list(get_list_of_roles(api)) |
| 34 | + |
| 35 | + |
| 36 | +@pytest.fixture(scope="session") |
| 37 | +def roles_dict(roles_list): |
| 38 | + return {role.name: role for role in roles_list} |
| 39 | + |
| 40 | + |
| 41 | +# Tests |
| 42 | + |
| 43 | +class TestRolesAPI(object): |
| 44 | + """Test RolesAPI methods.""" |
| 45 | + |
| 46 | + def test_list_roles(self, roles_list): |
| 47 | + assert are_valid_roles(roles_list) |
| 48 | + |
| 49 | + def test_list_roles_with_paging(self, api): |
| 50 | + paging_generator = get_list_of_roles(api, max=1) |
| 51 | + roles = list(paging_generator) |
| 52 | + assert roles > 1 |
| 53 | + assert are_valid_roles(roles) |
| 54 | + |
| 55 | + def test_get_role_by_id(self, api, roles_list): |
| 56 | + assert len(roles_list) >= 1 |
| 57 | + role_id = roles_list[0].id |
| 58 | + role = get_role_by_id(api, roleId=role_id) |
| 59 | + assert is_valid_role(role) |
0 commit comments