Beispiel #1
0
 def test_add_plugin_views_to_compare_view_missing_key(self):
     cr = CompareRoutes(AppMock(), None)
     plugin_views = [('plugin_1', b'<plugin view 1>'),
                     ('plugin_2', b'<plugin view 2>')]
     compare_view = 'xxxxxyyyyy'
     result = cr._add_plugin_views_to_compare_view(compare_view,
                                                   plugin_views)
     assert result == compare_view
Beispiel #2
0
    def test_add_to_compare_basket(self):
        with self.frontend.app.test_request_context():
            assert 'uids_for_comparison' not in session

            CompareRoutes.add_to_compare_basket(self.frontend, 'test')
            assert 'uids_for_comparison' in session
            assert isinstance(session['uids_for_comparison'], dict)
            assert 'test' in session['uids_for_comparison']
Beispiel #3
0
    def test_insert_plugin_into_view_at_index():
        view = '------><------'
        plugin = 'o'
        index = view.find('<')

        assert CompareRoutes._insert_plugin_into_view_at_index(plugin, view, 0) == 'o------><------'
        assert CompareRoutes._insert_plugin_into_view_at_index(plugin, view, index) == '------>o<------'
        assert CompareRoutes._insert_plugin_into_view_at_index(plugin, view, len(view) + 10) == '------><------o'
        assert CompareRoutes._insert_plugin_into_view_at_index(plugin, view, -10) == view
Beispiel #4
0
    def test_get_compare_plugin_views():
        cr = CompareRoutes(AppMock(), None)
        compare_result = {'plugins': {}}
        result = cr._get_compare_plugin_views(compare_result)
        assert result == ([], [])

        compare_result = {'plugins': {'plugin_1': None, 'plugin_2': None}}
        plugin_views, plugins_without_view = cr._get_compare_plugin_views(compare_result)
        assert plugin_views == [('plugin_1', b'<plugin 1 view>')]
        assert plugins_without_view == ['plugin_2']
Beispiel #5
0
    def test_remove_all_from_compare_basket(self):
        with self.frontend.app.test_request_context():
            session['uids_for_comparison'] = [TEST_FW.uid, TEST_FW_2.uid]
            session.modified = True
            assert 'uids_for_comparison' in session
            assert TEST_FW.uid in session['uids_for_comparison']
            assert TEST_FW_2.uid in session['uids_for_comparison']

            CompareRoutes.remove_all_from_compare_basket(self.frontend, 'some_uid')
            assert TEST_FW.uid not in session['uids_for_comparison']
            assert TEST_FW_2.uid not in session['uids_for_comparison']
Beispiel #6
0
    def test_remove_from_compare_basket(self):
        with self.frontend.app.test_request_context():
            session['uids_for_comparison'] = [
                TEST_FW.get_uid(), TEST_FW_2.get_uid()
            ]
            session.modified = True
            assert 'uids_for_comparison' in session
            assert TEST_FW.get_uid() in session['uids_for_comparison']
            assert TEST_FW_2.get_uid() in session['uids_for_comparison']

            CompareRoutes._remove_from_compare_basket('some_uid',
                                                      TEST_FW.get_uid())
            assert TEST_FW.get_uid() not in session['uids_for_comparison']
            assert TEST_FW_2.get_uid() in session['uids_for_comparison']
Beispiel #7
0
    def test_add_plugin_views_to_compare_view():
        cr = CompareRoutes(AppMock(), None)
        plugin_views = [
            ('plugin_1', b'<plugin view 1>'),
            ('plugin_2', b'<plugin view 2>')
        ]
        key = '{# individual plugin views #}'
        compare_view = 'xxxxx{}yyyyy'.format(key)
        key_index = compare_view.find(key)
        result = cr._add_plugin_views_to_compare_view(compare_view, plugin_views)

        for plugin, view in plugin_views:
            assert 'elif plugin == \'{}\''.format(plugin) in result
            assert view.decode() in result
            assert key_index + len(key) <= result.find(view.decode()) < result.find('yyyyy')
Beispiel #8
0
    def test_remove_from_compare_basket(self):
        with self.frontend.app.test_request_context():
            CompareRoutes.add_to_compare_basket(self.frontend, TEST_FW.uid)
            CompareRoutes.add_to_compare_basket(self.frontend, TEST_FW_2.uid)
            assert 'uids_for_comparison' in session
            assert TEST_FW.uid in session['uids_for_comparison']
            assert TEST_FW_2.uid in session['uids_for_comparison']

            CompareRoutes.remove_from_compare_basket(self.frontend, 'some_uid', TEST_FW.uid)
            assert TEST_FW.uid not in session['uids_for_comparison']
            assert TEST_FW_2.uid in session['uids_for_comparison']
    def _setup_app(self):
        self.app = Flask(__name__)
        self.app.config.from_object(__name__)

        Flask.secret_key = os.urandom(24)

        RestBase(app=self.app, config=self.config)

        AjaxRoutes(self.app, self.config)
        AnalysisRoutes(self.app, self.config)
        CompareRoutes(self.app, self.config)
        DatabaseRoutes(self.app, self.config)
        IORoutes(self.app, self.config)
        MiscellaneousRoutes(self.app, self.config)
        StatisticRoutes(self.app, self.config)

        FilterClass(self.app, self.program_version, self.config)
Beispiel #10
0
    def _setup_app(self):
        self.app = Flask(__name__)
        self.app.config.from_object(__name__)

        self.app.config['SECRET_KEY'] = os.urandom(24)
        add_config_from_configparser_to_app(self.app, self.config)
        self.user_db, self.user_datastore = add_flask_security_to_app(self.app)

        AjaxRoutes(self.app, self.config)
        AnalysisRoutes(self.app, self.config)
        CompareRoutes(self.app, self.config)
        DatabaseRoutes(self.app, self.config)
        IORoutes(self.app, self.config)
        MiscellaneousRoutes(self.app, self.config)
        StatisticRoutes(self.app, self.config)
        UserManagementRoutes(self.app,
                             self.config,
                             user_db=self.user_db,
                             user_db_interface=self.user_datastore)

        rest_base = RestBase(app=self.app, config=self.config)
        PluginRoutes(self.app, self.config, api=rest_base.api)
        FilterClass(self.app, self.program_version, self.config)
Beispiel #11
0
 def test_get_compare_view():
     cr = CompareRoutes(AppMock(), None)
     result = cr._get_compare_view([])
     assert '>General information<' in result
     assert '--- plugin results ---' in result