Пример #1
0
    def test_query(self):
        manager = get_manager(self.plugin_info['1']['plugin'], db.session, user=self.plugin_info['1']['user'])
        obj = TestModel()
        manager.add(obj)

        # We have created the object, so querying for it should give us the first instance.
        data = manager.query_first(obj.plugin_proxy, obj.metric_proxy)
        self.assertTrue(isinstance(data, TestModel))
Пример #2
0
    def test_wrong_permissions(self):
        manager = get_manager(self.plugin_info['1']['plugin'], db.session, user=self.plugin_info['1']['user'])
        bad_plugin = PluginFactory()

        obj = TestLoosePermissions()
        manager.add(obj)

        # This is 1 because of the object we made, and another because the setUp function makes an instance, which is 2.
        self.run_query_assert(obj, bad_plugin, 2)
Пример #3
0
    def test_query(self):
        manager = get_manager(self.plugin_info['1']['plugin'],
                              db.session,
                              user=self.plugin_info['1']['user'])
        obj = TestModel()
        manager.add(obj)

        # We have created the object, so querying for it should give us the first instance.
        data = manager.query_first(obj.plugin_proxy, obj.metric_proxy)
        self.assertTrue(isinstance(data, TestModel))
Пример #4
0
    def test_wrong_permissions(self):
        manager = get_manager(self.plugin_info['1']['plugin'],
                              db.session,
                              user=self.plugin_info['1']['user'])
        bad_plugin = PluginFactory()

        obj = TestLoosePermissions()
        manager.add(obj)

        # This is 1 because of the object we made, and another because the setUp function makes an instance, which is 2.
        self.run_query_assert(obj, bad_plugin, 2)
Пример #5
0
    def test_manager(self):
        manager = get_manager(self.plugin_info['1']['plugin'], db.session, user=self.plugin_info['1']['user'])
        bad_user = UserFactory()
        bad_plugin = PluginFactory()

        t_obj = TestModel()
        manager.add(t_obj)

        # We are the wrong user and plugin, so we don't have permissions for this yet.
        self.run_query_assert(t_obj, bad_plugin, 0, bad_user)

        # Right user, wrong plugin.  Should give us nothing.
        self.run_query_assert(t_obj, self.plugin_info['1']['plugin'], 0, bad_user)

        # Wrong user, right plugin.  Should give us nothing.
        self.run_query_assert(t_obj, bad_plugin, 0, self.plugin_info['1']['user'])

        # We are now the correct user and plugin, so we should have permission.
        self.run_query_assert(t_obj, self.plugin_info['1']['plugin'], 1, self.plugin_info['1']['user'])
Пример #6
0
    def test_manager(self):
        manager = get_manager(self.plugin_info['1']['plugin'],
                              db.session,
                              user=self.plugin_info['1']['user'])
        bad_user = UserFactory()
        bad_plugin = PluginFactory()

        t_obj = TestModel()
        manager.add(t_obj)

        # We are the wrong user and plugin, so we don't have permissions for this yet.
        self.run_query_assert(t_obj, bad_plugin, 0, bad_user)

        # Right user, wrong plugin.  Should give us nothing.
        self.run_query_assert(t_obj, self.plugin_info['1']['plugin'], 0,
                              bad_user)

        # Wrong user, right plugin.  Should give us nothing.
        self.run_query_assert(t_obj, bad_plugin, 0,
                              self.plugin_info['1']['user'])

        # We are now the correct user and plugin, so we should have permission.
        self.run_query_assert(t_obj, self.plugin_info['1']['plugin'], 1,
                              self.plugin_info['1']['user'])
Пример #7
0
 def run_query_assert(self, obj, plugin, times_len, user=None):
     manager = get_manager(plugin, db.session, user=user)
     times = manager.query_filter(obj.plugin_proxy, obj.metric_proxy)
     self.assertEqual(len(times), times_len)
Пример #8
0
 def run_query_assert(self, obj, plugin, times_len, user=None):
     manager = get_manager(plugin, db.session, user=user)
     times = manager.query_filter(obj.plugin_proxy, obj.metric_proxy)
     self.assertEqual(len(times), times_len)