Beispiel #1
0
    def test_serializers(self):
        """its possible to register and get annotators"""
        providers = PermissionProviders()

        def mock_serializer(*args):
            pass

        providers.acl_serializer(TestType, mock_serializer)
        serializers_list = providers.get_type_serializers(TestType())
        self.assertEqual(serializers_list[0], mock_serializer)
Beispiel #2
0
    def test_annotators(self):
        """its possible to register and get annotators"""
        providers = PermissionProviders()

        def test_annotator(*args):
            pass

        providers.acl_annotator(TestType, test_annotator)
        annotators_list = providers.get_type_annotators(TestType())
        self.assertEqual(annotators_list[0], test_annotator)
Beispiel #3
0
    def test_dict(self):
        """providers manager dict() returns dict"""
        providers = PermissionProviders()
        providers_dict = providers.dict()

        providers_setting = settings.MISAGO_ACL_EXTENSIONS
        self.assertEqual(len(providers_dict), len(providers_setting))

        for extension, module in providers_dict.items():
            self.assertTrue(isinstance(extension, six.string_types))
            self.assertEqual(type(module), ModuleType)
Beispiel #4
0
    def test_list(self):
        """providers manager list() returns iterable of tuples"""
        providers = PermissionProviders()
        providers_list = providers.list()

        providers_setting = settings.MISAGO_ACL_EXTENSIONS
        self.assertEqual(len(providers_list), len(providers_setting))

        for extension, module in providers_list:
            self.assertTrue(isinstance(extension, six.string_types))
            self.assertEqual(type(module), ModuleType)
Beispiel #5
0
    def test_serializers(self):
        """its possible to register and get annotators"""
        def mock_serializer(*args):
            pass

        providers = PermissionProviders()
        providers.acl_serializer(TestType, mock_serializer)
        providers.load()

        # providers.acl_serializer() throws after loading providers
        with self.assertRaises(AssertionError):
            providers.acl_serializer(TestType, mock_serializer)

        serializers_list = providers.get_obj_type_serializers(TestType())
        self.assertEqual(serializers_list[0], mock_serializer)
Beispiel #6
0
    def test_dict(self):
        """providers manager dict() returns dict"""
        providers = PermissionProviders()

        # providers.dict() throws before loading providers
        with self.assertRaises(AssertionError):
            providers.dict()

        providers.load()

        providers_dict = providers.dict()

        providers_setting = settings.MISAGO_ACL_EXTENSIONS
        self.assertEqual(len(providers_dict), len(providers_setting))

        for extension, module in providers_dict.items():
            self.assertTrue(isinstance(extension, str))
            self.assertEqual(type(module), ModuleType)
Beispiel #7
0
    def test_initialization(self):
        """providers manager is lazily initialized"""
        providers = PermissionProviders()

        self.assertTrue(providers._initialized is False)
        self.assertTrue(not providers._providers)
        self.assertTrue(not providers._providers_dict)

        # list call initializes providers
        providers_list = providers.list()

        self.assertTrue(providers_list)
        self.assertTrue(providers._initialized)
        self.assertTrue(providers._providers)
        self.assertTrue(providers._providers_dict)

        # dict call initializes providers
        providers = PermissionProviders()
        providers_dict = providers.dict()

        self.assertTrue(providers_dict)
        self.assertTrue(providers._initialized)
        self.assertTrue(providers._providers)
        self.assertTrue(providers._providers_dict)
Beispiel #8
0
    def test_initialization(self):
        """providers manager is lazily initialized"""
        providers = PermissionProviders()

        self.assertTrue(providers._initialized is False)
        self.assertTrue(not providers._providers)
        self.assertTrue(not providers._providers_dict)

        # public api errors on non-loaded object
        with self.assertRaises(AssertionError):
            providers.get_obj_type_annotators(TestType())

        with self.assertRaises(AssertionError):
            providers.get_obj_type_serializers(TestType())

        with self.assertRaises(AssertionError):
            providers.list()

        self.assertTrue(providers._initialized is False)
        self.assertTrue(not providers._providers)
        self.assertTrue(not providers._providers_dict)

        # load initializes providers
        providers = PermissionProviders()
        providers.load()

        self.assertTrue(providers._initialized)
        self.assertTrue(providers._providers)
        self.assertTrue(providers._providers_dict)