Esempio n. 1
0
    def test_unsubscribe_all_online(self):
        """
        """
        core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': 6379,
                'db': 6
            },
            additional_controller_classes=[FakeController])
        controller = core_controller.additional_controller(identifier='the.id')

        def handler(data):
            self.assertEquals(data, 'hello')

        controller.start_listening_to_events()
        controller.subscribe('test-channel1', handler)
        controller.subscribe('test-channel2', handler)

        self.assertTrue('test-channel1' in controller.subscriptions)
        self.assertTrue('test-channel2' in controller.subscriptions)

        controller.unsubscribe_all()
        controller.stop_listening_to_events()

        self.assertFalse('test-channel1' in controller.subscriptions)
        self.assertFalse('test-channel2' in controller.subscriptions)
Esempio n. 2
0
    def test_execute_event_request_with_invalid_session(self):
        """
        """
        GASDKLibrary().register_sdk('default', tstdk)
        core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': 6379,
                'db': 6
            },
            additional_controller_classes=[AdditionalController],
            authentication_plugins=[FakeAuthPlugin()])

        request = GARequest(action=GARequest.ACTION_CREATE)
        request.resources = [GAResource(name='enterprise', value=None)]

        with patch.object(core_controller.sessions_controller,
                          'get_session',
                          return_value=None):
            result = core_controller.execute_events_request(request)
            self.assertEquals(result[0], None)
            self.assertEquals(result[1].__class__, GAResponseFailure)
            self.assertEquals(len(result[1].content), 1)
            self.assertEquals(result[1].content[0].type,
                              GAError.TYPE_UNAUTHORIZED)
Esempio n. 3
0
    def test_execute_event_request_with_valid_session(self):
        """
        """
        GASDKLibrary().register_sdk('default', tstdk)
        core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': 6379,
                'db': 6
            },
            additional_controller_classes=[AdditionalController],
            authentication_plugins=[FakeAuthPlugin()])

        request = GARequest(action=GARequest.ACTION_CREATE)
        request.resources = [GAResource(name='enterprise', value=None)]

        session = GASession(garuda_uuid='test-garuda')
        session.root_object = NURESTRootObject()
        session.root_object.id = 'toto'

        with patch.object(core_controller.sessions_controller,
                          'get_session',
                          return_value=session):
            result = core_controller.execute_events_request(request)
            self.assertEquals(result[0].__class__, GASession)
            self.assertEquals(result[1], None)
Esempio n. 4
0
    def test_execute_model_request_with_valid_session(self):
        """
        """
        GASDKLibrary().register_sdk('default', tstdk)
        core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': 6379,
                'db': 6
            },
            additional_controller_classes=[AdditionalController],
            authentication_plugins=[FakeAuthPlugin()])

        request = GARequest(action=GARequest.ACTION_CREATE)
        request.resources = [GAResource(name='enterprise', value=None)]
        request.token = 'toto'

        with patch.object(core_controller.sessions_controller,
                          'get_session',
                          return_value=GASession(garuda_uuid='test-garuda',
                                                 root_object=tstdk.GARoot())):
            result = core_controller.execute_model_request(request)
            self.assertEquals(result.__class__,
                              GAResponseFailure)  # nothing exists that's fine
Esempio n. 5
0
    def test_offline_subscriptions(self):
        """
        """
        core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': 6379,
                'db': 6
            },
            additional_controller_classes=[FakeController])
        controller = core_controller.additional_controller(identifier='the.id')

        def handler(data):
            pass

        controller.subscribe('test-channel1', handler)
        controller.subscribe('test-channel2', handler)

        self.assertEquals(controller.subscriptions['test-channel1'], handler)
        self.assertEquals(controller.subscriptions['test-channel2'], handler)

        self.assertTrue('test-channel1' in controller.subscriptions)
        self.assertTrue('test-channel2' in controller.subscriptions)

        controller.unsubscribe('test-channel1')
        controller.unsubscribe('test-channel2')

        self.assertEquals(len(controller.subscriptions), 0)
        self.assertFalse('test-channel1' in controller.subscriptions)
        self.assertFalse('test-channel2' in controller.subscriptions)
Esempio n. 6
0
    def test_additonal_controllers(self):
        """
        """
        core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, authentication_plugins=[FakeAuthPlugin()])

        with self.assertRaises(KeyError):
            core_controller.additional_controller(identifier='nope')

        core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6},
                                           additional_controller_classes=[AdditionalController], authentication_plugins=[FakeAuthPlugin()])

        self.assertIsNotNone(core_controller.additional_controller(identifier='test.controller.additional'))
Esempio n. 7
0
 def test_stop_listening_to_events_when_not_listening(self):
     """
     """
     core_controller = GACoreController(
         garuda_uuid='test-garuda',
         redis_info={
             'host': '127.0.0.1',
             'port': 6379,
             'db': 6
         },
         additional_controller_classes=[FakeController])
     controller = core_controller.additional_controller(identifier='the.id')
     controller.stop_listening_to_events()
Esempio n. 8
0
    def test_execute_model_request_with_valid_session(self):
        """
        """
        GASDKLibrary().register_sdk('default', tstdk)
        core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6},
                                           additional_controller_classes=[AdditionalController], authentication_plugins=[FakeAuthPlugin()])

        request = GARequest(action=GARequest.ACTION_CREATE)
        request.resources = [GAResource(name='enterprise', value=None)]
        request.token = 'toto'

        with patch.object(core_controller.sessions_controller, 'get_session', return_value=GASession(garuda_uuid='test-garuda', root_object=tstdk.GARoot())):
            result = core_controller.execute_model_request(request)
            self.assertEquals(result.__class__, GAResponseFailure)  # nothing exists that's fine
Esempio n. 9
0
    def test_start_stop_twice(self):
        """
        """
        core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[FakeController])
        controller = core_controller.additional_controller(identifier='the.id')

        controller.start_listening_to_events()
        thread = controller._pubsub_thread
        controller.start_listening_to_events()
        self.assertEquals(controller._pubsub_thread, thread)

        controller.stop_listening_to_events()
        controller.stop_listening_to_events()

        self.assertIsNone(controller._pubsub_thread)
Esempio n. 10
0
    def start(self):
        """
        """
        logger.info("Forking communication channels...")

        for channel in self._channels:

            pid = os.fork()
            if not pid:  # pragma: no cover
                break
            else:
                self._channel_pids.append(pid)
                logger.info('Channel %s forked with pid: %s' %
                            (channel.manifest().identifier, pid))

        if not pid:  # pragma: no cover
            core = GACoreController(
                garuda_uuid=self._garuda_uuid,
                redis_info=self._redis_info,
                logic_plugins=self._logic_plugins,
                additional_controller_classes=self.
                _additional_controller_classes,
                authentication_plugins=self._authentication_plugins,
                storage_plugins=self._storage_plugins,
                permission_plugins=self._permission_plugins)

            channel.core_controller = core
            channel.did_fork()
            channel.run()
            logger.info("Channels subprocess %s exited gracefuly." %
                        os.getpid())
            channel.did_exit()
            sys.exit(0)
        else:
            logger.info("All channels successfully forked")
Esempio n. 11
0
    def test_perform_delegate(self):
        """
        """
        plugin1 = LogicPlugin1()
        plugin2 = LogicPlugin2()

        core_controller = GACoreController(garuda_uuid='test-garuda',
                                           redis_info={
                                               'host': '127.0.0.1',
                                               'port': '6379',
                                               'db': 6
                                           },
                                           authentication_plugins=[])
        logic_controller = GALogicController(plugins=[plugin1, plugin2],
                                             core_controller=core_controller)
        logic_controller.ready()

        request = GARequest(action=GARequest.ACTION_CREATE)
        request.resources = [GAResource(name='fakeobject1', value=None)]

        context = GAContext(request=request, session='fake')
        context.object = 'original'

        logic_controller.perform_delegate(delegate='delegate', context=context)

        self.assertEquals(context.object, 'modified by LogicPlugin1')

        logic_controller.perform_delegate(delegate='nope',
                                          context=context)  # should not crash
Esempio n. 12
0
    def test_execute_event_request_with_invalid_session(self):
        """
        """
        GASDKLibrary().register_sdk('default', tstdk)
        core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6},
                                           additional_controller_classes=[AdditionalController], authentication_plugins=[FakeAuthPlugin()])

        request = GARequest(action=GARequest.ACTION_CREATE)
        request.resources = [GAResource(name='enterprise', value=None)]

        with patch.object(core_controller.sessions_controller, 'get_session', return_value=None):
            result = core_controller.execute_events_request(request)
            self.assertEquals(result[0], None)
            self.assertEquals(result[1].__class__, GAResponseFailure)
            self.assertEquals(len(result[1].content), 1)
            self.assertEquals(result[1].content[0].type, GAError.TYPE_UNAUTHORIZED)
Esempio n. 13
0
    def test_additonal_controllers(self):
        """
        """
        core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': 6379,
                'db': 6
            },
            authentication_plugins=[FakeAuthPlugin()])

        with self.assertRaises(KeyError):
            core_controller.additional_controller(identifier='nope')

        core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': 6379,
                'db': 6
            },
            additional_controller_classes=[AdditionalController],
            authentication_plugins=[FakeAuthPlugin()])

        self.assertIsNotNone(
            core_controller.additional_controller(
                identifier='test.controller.additional'))
Esempio n. 14
0
    def test_execute_event_request_with_valid_session(self):
        """
        """
        GASDKLibrary().register_sdk('default', tstdk)
        core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6},
                                           additional_controller_classes=[AdditionalController], authentication_plugins=[FakeAuthPlugin()])

        request = GARequest(action=GARequest.ACTION_CREATE)
        request.resources = [GAResource(name='enterprise', value=None)]

        session = GASession(garuda_uuid='test-garuda')
        session.root_object = NURESTRootObject()
        session.root_object.id = 'toto'

        with patch.object(core_controller.sessions_controller, 'get_session', return_value=session):
            result = core_controller.execute_events_request(request)
            self.assertEquals(result[0].__class__, GASession)
            self.assertEquals(result[1], None)
Esempio n. 15
0
 def test_start(self):
     """
     """
     controller = GAController(
         core_controller=GACoreController(garuda_uuid='test-garuda',
                                          redis_info={
                                              'host': '127.0.0.1',
                                              'port': 6379,
                                              'db': 6
                                          }))
     controller.start()
Esempio n. 16
0
    def test_unsubscribe_all_online(self):
        """
        """
        core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[FakeController])
        controller = core_controller.additional_controller(identifier='the.id')

        def handler(data):
            self.assertEquals(data, 'hello')

        controller.start_listening_to_events()
        controller.subscribe('test-channel1', handler)
        controller.subscribe('test-channel2', handler)

        self.assertTrue('test-channel1' in controller.subscriptions)
        self.assertTrue('test-channel2' in controller.subscriptions)

        controller.unsubscribe_all()
        controller.stop_listening_to_events()

        self.assertFalse('test-channel1' in controller.subscriptions)
        self.assertFalse('test-channel2' in controller.subscriptions)
Esempio n. 17
0
    def test_uuid(self):
        """
        """
        controller = GAController(
            core_controller=GACoreController(garuda_uuid='test-garuda',
                                             redis_info={
                                                 'host': '127.0.0.1',
                                                 'port': 6379,
                                                 'db': 6
                                             }))

        self.assertIsNotNone(controller.uuid)
Esempio n. 18
0
 def test_identifiers(self):
     """
     """
     core_controller = GACoreController(
         garuda_uuid='test-garuda',
         redis_info={
             'host': '127.0.0.1',
             'port': 6379,
             'db': 6
         },
         authentication_plugins=[FakeAuthPlugin()])
     self.assertIsNotNone(core_controller.uuid)
     self.assertEquals(core_controller.garuda_uuid, 'test-garuda')
Esempio n. 19
0
 def setUpClass(cls):
     """
     """
     GASDKLibrary().register_sdk('default', tstdk)
     cls.plugin = FakeStoragePlugin()
     cls.core_controller = GACoreController(garuda_uuid='test-garuda',
                                            redis_info={
                                                'host': '127.0.0.1',
                                                'port': '6379',
                                                'db': 5
                                            },
                                            storage_plugins=[cls.plugin])
     cls.storage_controller = cls.core_controller.storage_controller
Esempio n. 20
0
    def test_start_stop_twice(self):
        """
        """
        core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': 6379,
                'db': 6
            },
            additional_controller_classes=[FakeController])
        controller = core_controller.additional_controller(identifier='the.id')

        controller.start_listening_to_events()
        thread = controller._pubsub_thread
        controller.start_listening_to_events()
        self.assertEquals(controller._pubsub_thread, thread)

        controller.stop_listening_to_events()
        controller.stop_listening_to_events()

        self.assertIsNone(controller._pubsub_thread)
Esempio n. 21
0
    def test_lifecycle(self):
        """
        """
        core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6},
                                           additional_controller_classes=[AdditionalController], authentication_plugins=[FakeAuthPlugin()])

        additional = core_controller.additional_controller('test.controller.additional')

        self.assertTrue(additional.is_ready)

        core_controller.start()
        self.assertTrue(core_controller.running)
        self.assertTrue(additional.is_started)

        with self.assertRaises(RuntimeError):
            core_controller.start()

        core_controller.stop()
        self.assertFalse(core_controller.running)
        self.assertFalse(additional.is_started)

        with self.assertRaises(RuntimeError):
            core_controller.stop()
Esempio n. 22
0
    def test_identifier_must_be_implemented(self):
        """
        """
        controller = GAController(
            core_controller=GACoreController(garuda_uuid='test-garuda',
                                             redis_info={
                                                 'host': '127.0.0.1',
                                                 'port': 6379,
                                                 'db': 6
                                             }))
        with self.assertRaises(NotImplementedError):
            controller.identifier()

        with self.assertRaises(NotImplementedError):
            controller.__class__.identifier()
Esempio n. 23
0
    def test_redis_informations(self):
        """
        """
        controller = GAController(
            core_controller=GACoreController(garuda_uuid='test-garuda',
                                             redis_info={
                                                 'host': '127.0.0.1',
                                                 'port': 6379,
                                                 'db': 6
                                             }))

        self.assertEquals(controller.subscriptions, {})
        self.assertEquals(controller.redis_host, '127.0.0.1')
        self.assertEquals(controller.redis_port, 6379)
        self.assertEquals(controller.redis_db, 6)
Esempio n. 24
0
 def test_redis_information(self):
     """
     """
     core_controller = GACoreController(
         garuda_uuid='test-garuda',
         redis_info={
             'host': '127.0.0.1',
             'port': 6379,
             'db': 6
         },
         authentication_plugins=[FakeAuthPlugin()])
     self.assertIsNotNone(core_controller.redis)
     self.assertEquals(core_controller.redis_host, '127.0.0.1')
     self.assertEquals(core_controller.redis_port, 6379)
     self.assertEquals(core_controller.redis_db, 6)
Esempio n. 25
0
    def test_offline_subscriptions(self):
        """
        """
        core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[FakeController])
        controller = core_controller.additional_controller(identifier='the.id')

        def handler(data):
            pass

        controller.subscribe('test-channel1', handler)
        controller.subscribe('test-channel2', handler)

        self.assertEquals(controller.subscriptions['test-channel1'], handler)
        self.assertEquals(controller.subscriptions['test-channel2'], handler)

        self.assertTrue('test-channel1' in controller.subscriptions)
        self.assertTrue('test-channel2' in controller.subscriptions)

        controller.unsubscribe('test-channel1')
        controller.unsubscribe('test-channel2')

        self.assertEquals(len(controller.subscriptions), 0)
        self.assertFalse('test-channel1' in controller.subscriptions)
        self.assertFalse('test-channel2' in controller.subscriptions)
Esempio n. 26
0
 def test_managed_plugin_type(self):
     """
     """
     core_controller = GACoreController(garuda_uuid='test-garuda',
                                        redis_info={
                                            'host': '127.0.0.1',
                                            'port': '6379',
                                            'db': 6
                                        },
                                        authentication_plugins=[])
     logic_controller = GALogicController(plugins=[],
                                          core_controller=core_controller)
     self.assertEquals(logic_controller.managed_plugin_type(),
                       GALogicPlugin)
     self.assertEquals(logic_controller.__class__.managed_plugin_type(),
                       GALogicPlugin)
Esempio n. 27
0
 def test_controllers(self):
     """
     """
     core_controller = GACoreController(
         garuda_uuid='test-garuda',
         redis_info={
             'host': '127.0.0.1',
             'port': 6379,
             'db': 6
         },
         authentication_plugins=[FakeAuthPlugin()])
     self.assertIsNotNone(core_controller.storage_controller)
     self.assertIsNotNone(core_controller.logic_controller)
     self.assertIsNotNone(core_controller.push_controller)
     self.assertIsNotNone(core_controller.permissions_controller)
     self.assertIsNotNone(core_controller.sessions_controller)
Esempio n. 28
0
    def test_identifiers(self):
        """
        """
        core_controller = GACoreController(garuda_uuid='test-garuda',
                                           redis_info={
                                               'host': '127.0.0.1',
                                               'port': '6379',
                                               'db': 6
                                           },
                                           authentication_plugins=[])
        logic_controller = GALogicController(plugins=[],
                                             core_controller=core_controller)

        self.assertEquals(logic_controller.identifier(),
                          'garuda.controller.logic')
        self.assertEquals(logic_controller.__class__.identifier(),
                          'garuda.controller.logic')
    def setUpClass(cls):
        """
        """

        cls.maxDiff = None
        cls.fake_auth_plugin = FakeAuthPlugin()
        cls.core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': '6379',
                'db': 6
            },
            authentication_plugins=[cls.fake_auth_plugin])

        cls.sessions_controller = cls.core_controller.sessions_controller
        cls.sessions_controller._default_session_ttl = 3
Esempio n. 30
0
    def test_publish(self):
        """
        """
        core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[FakeController])
        controller = core_controller.additional_controller(identifier='the.id')

        def handler(data):
            self.assertEquals(data, 'hello')

        core_controller.start()
        controller.subscribe('test-channel', handler)
        controller.start_listening_to_events()
        controller.publish('test-channel', 'hello')
        controller.stop_listening_to_events()
        core_controller.stop()
Esempio n. 31
0
    def test_should_manage(self):
        """
        """
        plugin1 = LogicPlugin1()
        plugin2 = LogicPlugin2()

        core_controller = GACoreController(garuda_uuid='test-garuda',
                                           redis_info={
                                               'host': '127.0.0.1',
                                               'port': '6379',
                                               'db': 6
                                           },
                                           authentication_plugins=[])
        logic_controller = GALogicController(plugins=[plugin1, plugin2],
                                             core_controller=core_controller)
        logic_controller.ready()

        managing_plugins = logic_controller._managing_plugins(
            resource_name='fakeobject1', action=GARequest.ACTION_CREATE)
        self.assertEquals(sorted(managing_plugins), sorted([plugin1]))

        managing_plugins = logic_controller._managing_plugins(
            resource_name='fakeobject1', action=GARequest.ACTION_CREATE)
        self.assertEquals(sorted(managing_plugins),
                          sorted([plugin1]))  # do it twice to check the cache

        managing_plugins = logic_controller._managing_plugins(
            resource_name='fakeobject2', action=GARequest.ACTION_CREATE)
        self.assertEquals(sorted(managing_plugins), sorted([plugin2]))

        managing_plugins = logic_controller._managing_plugins(
            resource_name='shared', action=GARequest.ACTION_CREATE)
        self.assertEquals(sorted(managing_plugins), sorted([plugin1, plugin2]))

        managing_plugins = logic_controller._managing_plugins(
            resource_name='shared', action=GARequest.ACTION_DELETE)
        self.assertEquals(sorted(managing_plugins), sorted([plugin1]))

        managing_plugins = logic_controller._managing_plugins(
            resource_name='shared', action=GARequest.ACTION_ASSIGN)
        self.assertEquals(sorted(managing_plugins), sorted([plugin2]))
Esempio n. 32
0
    def test_perform_delegate_with_no_plugin(self):
        """
        """
        core_controller = GACoreController(garuda_uuid='test-garuda',
                                           redis_info={
                                               'host': '127.0.0.1',
                                               'port': '6379',
                                               'db': 6
                                           },
                                           authentication_plugins=[])
        logic_controller = GALogicController(plugins=[],
                                             core_controller=core_controller)
        logic_controller.ready()

        request = GARequest(action=GARequest.ACTION_CREATE)
        request.resources = [GAResource(name='fakeobject1', value=None)]

        context = GAContext(request=request, session='fake')
        context.object = 'original'

        logic_controller.perform_delegate(delegate='delegate', context=context)
Esempio n. 33
0
    def test_lifecycle(self):
        """
        """
        core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[FakeController])
        controller = core_controller.additional_controller(identifier='the.id')

        self.assertIsNotNone(controller)
        self.assertFalse(controller.is_started)
        self.assertTrue(controller.is_ready)

        core_controller.start()
        self.assertTrue(controller.is_started)
        self.assertTrue(controller.is_ready)

        core_controller.stop()
        self.assertFalse(controller.is_started)
        self.assertTrue(controller.is_ready)
Esempio n. 34
0
    def test_publish(self):
        """
        """
        core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': 6379,
                'db': 6
            },
            additional_controller_classes=[FakeController])
        controller = core_controller.additional_controller(identifier='the.id')

        def handler(data):
            self.assertEquals(data, 'hello')

        core_controller.start()
        controller.subscribe('test-channel', handler)
        controller.start_listening_to_events()
        controller.publish('test-channel', 'hello')
        controller.stop_listening_to_events()
        core_controller.stop()
Esempio n. 35
0
    def test_lifecycle(self):
        """
        """
        core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': 6379,
                'db': 6
            },
            additional_controller_classes=[FakeController])
        controller = core_controller.additional_controller(identifier='the.id')

        self.assertIsNotNone(controller)
        self.assertFalse(controller.is_started)
        self.assertTrue(controller.is_ready)

        core_controller.start()
        self.assertTrue(controller.is_started)
        self.assertTrue(controller.is_ready)

        core_controller.stop()
        self.assertFalse(controller.is_started)
        self.assertTrue(controller.is_ready)
Esempio n. 36
0
    def test_lifecycle(self):
        """
        """
        core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': 6379,
                'db': 6
            },
            additional_controller_classes=[AdditionalController],
            authentication_plugins=[FakeAuthPlugin()])

        additional = core_controller.additional_controller(
            'test.controller.additional')

        self.assertTrue(additional.is_ready)

        core_controller.start()
        self.assertTrue(core_controller.running)
        self.assertTrue(additional.is_started)

        with self.assertRaises(RuntimeError):
            core_controller.start()

        core_controller.stop()
        self.assertFalse(core_controller.running)
        self.assertFalse(additional.is_started)

        with self.assertRaises(RuntimeError):
            core_controller.stop()
Esempio n. 37
0
 def test_stop_listening_to_events_when_not_listening(self):
     """
     """
     core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[FakeController])
     controller = core_controller.additional_controller(identifier='the.id')
     controller.stop_listening_to_events()
    def setUpClass(cls):
        """
        Model:

        e1  --- u1  --- a1
            +-- u2  --- a2
            +-- u3

        e2  --- u4  --- a3
            +-- u5  --- a4
                    --- a5

        will be testing diverse permissions on that model for self.e0
        """
        GASDKLibrary().register_sdk('default', tstdk)

        cls.mongo_plugin = GAMongoStoragePlugin(db_name='permissions_test',
                                                sdk_identifier='default')
        cls.redis_permissions_plugin = GARedisPermissionsPlugin()

        cls.core_controller = GACoreController(
            garuda_uuid='test-garuda',
            redis_info={
                'host': '127.0.0.1',
                'port': '6379',
                'db': 7
            },
            storage_plugins=[cls.mongo_plugin],
            permission_plugins=[cls.redis_permissions_plugin])

        cls.storage_controller = cls.core_controller.storage_controller

        cls.core_controller.redis.flushdb()

        cls.core_controller.start()
        cls.permissions_controller = cls.core_controller.permissions_controller

        cls.e0 = tstdk.GAEnterprise(username='******')
        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.e0,
                                      parent=None)

        cls.e1 = tstdk.GAEnterprise(name='e1')
        cls.e2 = tstdk.GAEnterprise(name='e2')

        cls.u1 = tstdk.GAUser(username='******')
        cls.u2 = tstdk.GAUser(username='******')
        cls.u3 = tstdk.GAUser(username='******')
        cls.u4 = tstdk.GAUser(username='******')
        cls.u5 = tstdk.GAUser(username='******')

        cls.a1 = tstdk.GAUser(street='a1')
        cls.a2 = tstdk.GAUser(street='a2')
        cls.a3 = tstdk.GAUser(street='a3')
        cls.a4 = tstdk.GAUser(street='a4')
        cls.a5 = tstdk.GAUser(street='a5')

        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.e1,
                                      parent=None)
        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.u1,
                                      parent=cls.e1)
        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.u2,
                                      parent=cls.e1)
        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.u3,
                                      parent=cls.e1)
        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.a1,
                                      parent=cls.u1)
        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.a2,
                                      parent=cls.u2)

        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.e2,
                                      parent=None)
        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.u4,
                                      parent=cls.e2)
        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.u5,
                                      parent=cls.e2)
        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.a3,
                                      parent=cls.u4)
        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.a4,
                                      parent=cls.u5)
        cls.storage_controller.create(user_identifier='fake',
                                      resource=cls.a5,
                                      parent=cls.u5)