Пример #1
0
 def test_tool_filter_gets_added_to_filter_model(self):
     url = "sqlite:///" + os.path.join(self._temp_dir.name, "db.sqlite")
     db_map = DiffDatabaseMapping(url, create=True)
     import_tools(db_map, ("tool", ))
     db_map.commit_session("Add test data.")
     db_map.connection.close()
     self._link.handle_dag_changed(
         [ProjectItemResource(MetaObject("provider", ""), "database", url)])
     self._link.refresh_resource_filter_model()
     self.assertTrue(self._link.connection.has_filters())
     filter_model = self._link.resource_filter_model
     self.assertEqual(filter_model.rowCount(), 1)
     self.assertEqual(filter_model.columnCount(), 1)
     index = filter_model.index(0, 0)
     self.assertEqual(index.data(), url)
     root_item = filter_model.itemFromIndex(index)
     self.assertEqual(root_item.rowCount(), 2)
     self.assertEqual(root_item.columnCount(), 1)
     tool_title_item = root_item.child(1, 0)
     self.assertEqual(tool_title_item.index().data(), "Tool filter")
     self.assertEqual(tool_title_item.rowCount(), 2)
     self.assertEqual(tool_title_item.columnCount(), 1)
     tool_item = tool_title_item.child(0, 0)
     self.assertEqual(tool_item.index().data(), "Select all")
     tool_item = tool_title_item.child(1, 0)
     self.assertEqual(tool_item.index().data(), "tool")
Пример #2
0
 def test_fetch_tools(self):
     connection = Connection("source", "bottom", "destination", "top")
     url = "sqlite:///" + os.path.join(self._temp_dir.name, "db.sqlite")
     db_map = DiffDatabaseMapping(url, create=True)
     import_tools(db_map, ("tool",))
     db_map.commit_session("Add test data.")
     db_map.connection.close()
     resources = [database_resource("source", url)]
     connection.receive_resources_from_source(resources)
     self.assertFalse(connection.has_filters())
     connection.fetch_database_items()
     self.assertTrue(connection.has_filters())
     self.assertEqual(connection.resource_filters, {resources[0].label: {"tool_filter": {1: False}}})
Пример #3
0
 def test_toggle_tool_filter(self):
     url = "sqlite:///" + os.path.join(self._temp_dir.name, "db.sqlite")
     db_map = DiffDatabaseMapping(url, create=True)
     import_tools(db_map, ("tool", ))
     db_map.commit_session("Add test data.")
     db_map.connection.close()
     self._link.handle_dag_changed(
         [ProjectItemResource(MetaObject("provider", ""), "database", url)])
     self._link.refresh_resource_filter_model()
     filter_model = self._link.resource_filter_model
     filter_model.set_online(url, "tool_filter", {1: True})
     self.assertEqual(self._link.connection.resource_filters,
                      {url: {
                          "tool_filter": {
                              1: True
                          }
                      }})
Пример #4
0
 def test_filter_stacks(self):
     """Tests filter stacks are properly applied."""
     with TemporaryDirectory() as temp_dir:
         url = "sqlite:///" + os.path.join(temp_dir, "db.sqlite")
         db_map = DiffDatabaseMapping(url, create=True)
         import_scenarios(db_map, (("scen1", True), ("scen2", True)))
         import_tools(db_map, ("toolA", ))
         db_map.commit_session("Add test data.")
         db_map.connection.close()
         url_a_fw = _make_resource(url)
         url_b_fw = _make_resource("db:///url_b_fw")
         url_c_bw = _make_resource("db:///url_c_bw")
         mock_item_a = self._mock_item("item_a",
                                       resources_forward=[url_a_fw],
                                       resources_backward=[])
         mock_item_b = self._mock_item("item_b",
                                       resources_forward=[url_b_fw],
                                       resources_backward=[])
         mock_item_c = self._mock_item("item_c",
                                       resources_forward=[],
                                       resources_backward=[url_c_bw])
         items = {
             "item_a": mock_item_a,
             "item_b": mock_item_b,
             "item_c": mock_item_c
         }
         connections = [
             {
                 "from": ("item_a", "right"),
                 "to": ("item_b", "left"),
                 "resource_filters": {
                     url_a_fw.label: {
                         "scenario_filter": [1, 2],
                         "tool_filter": [1]
                     }
                 },
             },
             {
                 "from": ("item_b", "bottom"),
                 "to": ("item_c", "left")
             },
         ]
         successors = {"item_a": ["item_b"], "item_b": ["item_c"]}
         execution_permits = {
             "item_a": True,
             "item_b": True,
             "item_c": True
         }
         engine = SpineEngine(items=items,
                              connections=connections,
                              node_successors=successors,
                              execution_permits=execution_permits)
         engine._make_item = lambda name, direction: engine._items[name]
         with patch("spine_engine.spine_engine.create_timestamp"
                    ) as mock_create_timestamp:
             mock_create_timestamp.return_value = "timestamp"
             engine.run()
         # Check that item_b has been executed two times, with the right filters
         self.assertEqual(len(mock_item_b.fwd_flt_stacks), 2)
         self.assertEqual(len(mock_item_b.bwd_flt_stacks), 2)
         self.assertIn(
             (scenario_filter_config("scen1"), tool_filter_config("toolA")),
             mock_item_b.fwd_flt_stacks)
         self.assertIn(
             (scenario_filter_config("scen2"), tool_filter_config("toolA")),
             mock_item_b.fwd_flt_stacks)
         self.assertIn(
             (execution_filter_config({
                 "execution_item": "item_b",
                 "scenarios": ["scen1"],
                 "timestamp": "timestamp"
             }), ),
             mock_item_b.bwd_flt_stacks,
         )
         self.assertIn(
             (execution_filter_config({
                 "execution_item": "item_b",
                 "scenarios": ["scen2"],
                 "timestamp": "timestamp"
             }), ),
             mock_item_b.bwd_flt_stacks,
         )
         # Check that item_c has also been executed two times
         self.assertEqual(len(mock_item_c.fwd_flt_stacks), 2)