# Path: mollie/api/error.py
# class IdentifierError(RequestSetupError):
#     """Errors related to invalid resource identifiers that will be requested from the API."""
# 
#     pass
# 
# Path: mollie/api/objects/permission.py
# class Permission(ObjectBase):
#     @classmethod
#     def get_resource_class(cls, client):
#         from ..resources.permissions import Permissions
# 
#         return Permissions(client)
# 
#     @property
#     def id(self):
#         return self._get_property("id")
# 
#     @property
#     def resource(self):
#         return self._get_property("resource")
# 
#     @property
#     def description(self):
#         return self._get_property("description")
# 
#     @property
#     def granted(self):
#         return self._get_property("granted")
# 
# Path: mollie/api/resources/permissions.py
# class Permissions(ResourceBase):
#     def get_resource_object(self, result):
#         return Permission(result, self.client)
# 
#     @staticmethod
#     def validate_permission_id(permission_id):
#         if not permission_id or not bool(re.match(r"^[a-z]+\.[a-z]+$", permission_id)):
#             raise IdentifierError(f"Invalid permission ID: '{permission_id}'. Does not match ^[a-z]+.[a-z]+$")
# 
#     def get(self, permission_id, **params):
#         self.validate_permission_id(permission_id)
#         return super().get(permission_id, **params)
# 
# Path: tests/utils.py
# def assert_list_object(obj, object_type, count=None):
#     """Assert that a List object is correctly working, and has sane contents."""
#     assert isinstance(obj, ObjectList), f"Object {obj} is not a ObjectList instance."
#     assert isinstance(obj.count, int), "ObjectList count is not an integer."
#     if count is not None:
#         assert obj.count == count, "ObjectList does not contain the expected number of items."
#     else:
#         assert obj.count > 0, "ObjectList has no items."
# 
#     # verify items in list
#     items = []
#     for item in obj:
#         assert isinstance(item, object_type)
#         assert item.id is not None
#         items.append(item.id)
# 
#     assert len(items) == obj.count, "Items in ObjectList don't match list count."
#     assert len(set(items)) == obj.count, "Not all object ids in the ObjectList are unique."


import pytest
from mollie.api.error import IdentifierError
from mollie.api.objects.permission import Permission
from mollie.api.resources.permissions import Permissions
from .utils import assert_list_object



PERMISSION_ID = "payments.read"


def test_list_permissions(oauth_client, response):
    """Retrieve a list of existing permissions."""
    response.get("https://api.mollie.com/v2/permissions", "permissions_list")

    permissions = oauth_client.permissions.list()
    assert_list_object(permissions, Permission)


def test_get_permission(oauth_client, response):
    """Retrieve a single permission."""
    response.get(f"https://api.mollie.com/v2/permissions/{PERMISSION_ID}", "permission_single")

    permission = oauth_client.permissions.get(PERMISSION_ID)

# Path: mollie/api/error.py
# class IdentifierError(RequestSetupError):
#     """Errors related to invalid resource identifiers that will be requested from the API."""
# 
#     pass
# 
# Path: mollie/api/objects/permission.py
# class Permission(ObjectBase):
#     @classmethod
#     def get_resource_class(cls, client):
#         from ..resources.permissions import Permissions
# 
#         return Permissions(client)
# 
#     @property
#     def id(self):
#         return self._get_property("id")
# 
#     @property
#     def resource(self):
#         return self._get_property("resource")
# 
#     @property
#     def description(self):
#         return self._get_property("description")
# 
#     @property
#     def granted(self):
#         return self._get_property("granted")
# 
# Path: mollie/api/resources/permissions.py
# class Permissions(ResourceBase):
#     def get_resource_object(self, result):
#         return Permission(result, self.client)
# 
#     @staticmethod
#     def validate_permission_id(permission_id):
#         if not permission_id or not bool(re.match(r"^[a-z]+\.[a-z]+$", permission_id)):
#             raise IdentifierError(f"Invalid permission ID: '{permission_id}'. Does not match ^[a-z]+.[a-z]+$")
# 
#     def get(self, permission_id, **params):
#         self.validate_permission_id(permission_id)
#         return super().get(permission_id, **params)
# 
# Path: tests/utils.py
# def assert_list_object(obj, object_type, count=None):
#     """Assert that a List object is correctly working, and has sane contents."""
#     assert isinstance(obj, ObjectList), f"Object {obj} is not a ObjectList instance."
#     assert isinstance(obj.count, int), "ObjectList count is not an integer."
#     if count is not None:
#         assert obj.count == count, "ObjectList does not contain the expected number of items."
#     else:
#         assert obj.count > 0, "ObjectList has no items."
# 
#     # verify items in list
#     items = []
#     for item in obj:
#         assert isinstance(item, object_type)
#         assert item.id is not None
#         items.append(item.id)
# 
#     assert len(items) == obj.count, "Items in ObjectList don't match list count."
#     assert len(set(items)) == obj.count, "Not all object ids in the ObjectList are unique."


# Path: tests/test_permissions.py
import pytest
from mollie.api.error import IdentifierError
from mollie.api.objects.permission import Permission
from mollie.api.resources.permissions import Permissions
from .utils import assert_list_object




PERMISSION_ID = "payments.read"


def test_list_permissions(oauth_client, response):
    """Retrieve a list of existing permissions."""
    response.get("https://api.mollie.com/v2/permissions", "permissions_list")

    permissions = oauth_client.permissions.list()
    assert_list_object(permissions, Permission)


def test_get_permission(oauth_client, response):
    """Retrieve a single permission."""
    response.get(f"https://api.mollie.com/v2/permissions/{PERMISSION_ID}", "permission_single")

    permission = oauth_client.permissions.get(PERMISSION_ID)

    assert isinstance(permission, Permission)