def testFetchSystematicEntriesForDocument(self):

        # Setup
        document = Document(25)
        signature = systematic_string_to_identifier("1.2.IV-3")
        identifier1 = SystematicIdentifier("2.3", 5, 6)
        identifier2 = SystematicIdentifier("3.4", 7, 8)
        self.references_dao.fetch_systematik_ids_for_document_id = MagicMock(
            return_value=[identifier1, identifier2])
        self.references_dao.fetch_signature_for_document_id = MagicMock(
            return_value=signature)

        values = {
            signature: SystematicPoint(signature, "signature"),
            identifier1: SystematicPoint(identifier1, "identifier1"),
            identifier2: SystematicPoint(identifier2, "identifier2")
        }

        def side_effect(arg):
            return values[arg]

        self.systematic_dao.get_by_id = MagicMock(side_effect=side_effect)

        # Execution
        result = self.service.fetch_systematic_entries_for_document(document)

        # Assertion
        self.assertEqual(len(result), 3)

        self.assertIn(QualifiedSystematicPoint(values[signature], True),
                      result)
        self.assertIn(QualifiedSystematicPoint(values[identifier1], False),
                      result)
        self.assertIn(QualifiedSystematicPoint(values[identifier2], False),
                      result)
コード例 #2
0
 def create_test_data(self):
     self.entity_list = []
     self.entity_list.append(
         SystematicPoint(SystematicIdentifier("1"), "root node"))
     self.entity_list.append(
         SystematicPoint(SystematicIdentifier("1.1"), "child 1 node"))
     self.entity_list.append(
         SystematicPoint(SystematicIdentifier("1.2"), "child 2 node"))
     self.systematic_tree = Tree(self.entity_list)
 def test_potential_new_children_6(self):
     node = Node(
         SystematicPoint(SystematicIdentifier("1.2", 3), "Description"))
     self.systematic_dao.get_children.return_value = [
         SystematicPoint(SystematicIdentifier("1.2", 3, 1), "Description")
     ]
     new_child_identifiers = self.service.get_potential_new_child_identifier(
         node)
     self.assertEqual(1, len(new_child_identifiers))
     self.assertEqual(SystematicIdentifier("1.2", 3, 2),
                      new_child_identifiers[0])
 def test_comparison_lt(self):
     one = SystematicPoint(SystematicIdentifier("1.2"), "Description")
     other = SystematicPoint(SystematicIdentifier("1.2.3"), "Description")
     third = SystematicPoint(SystematicIdentifier("1.2"), "Description")
     fourth = None
     self.assertTrue(one < other)
     self.assertFalse(one > other)
     self.assertTrue(one >= third)
     self.assertTrue(one <= third)
     self.assertTrue(one == third)
     self.assertTrue(other >= third)
     self.assertFalse(other == third)
     self.assertFalse(one == fourth)
    def test_three_node_tree(self):

        node_list = []
        node_list.append(SystematicPoint(SystematicIdentifier("1.2"), "1.2"))
        node_list.append(SystematicPoint(SystematicIdentifier("1.1"), "1.1"))
        node_list.append(SystematicPoint(SystematicIdentifier("1"), "1"))
        node_list.append(SystematicPoint(SystematicIdentifier(None), "root"))

        tree = Tree(node_list)
        self.assertEqual(len(tree.root_node.children), 1)
        self.assertEqual(len(tree.root_node.children[0].children), 2)
        self.assertEqual("%s" % tree.root_node.children[0].children[0],
                         "1.1: 1.1")
コード例 #6
0
def export_info_object_hook(obj):
    '''
    This function is used for deserializing ExportInfo json objects
    '''

    if 'cd_name' in obj:
        export_info = ExportInfo()
        export_info.start_date = obj['start_date']
        export_info.end_date = obj['end_date']
        export_info.signature = obj['signature']
        export_info.cd_name = obj['cd_name']
        export_info.pagecontent = obj['pagecontent']
        export_info.start_image = obj['start_image']
        return export_info

    if '_year' in obj:
        return AlexDate(obj['_year'], obj['_month'], obj['_day'])

    if 'description' in obj:
        return SystematicPoint(obj['id'], obj['description'])

    if 'node_id' in obj:
        return SystematicIdentifier(obj['node_id'], obj['roman'],
                                    obj['subfolder'])

    return obj
    def test_next_sibling_exists(self):

        identifier = SystematicIdentifier("1.2.3")
        sibling = SystematicIdentifier("1.2.4")
        self.systematic_dao.get_node.return_value = SystematicPoint(
            sibling, "Description")
        self.assertTrue(self.service.next_sibling_exists(identifier))
        self.systematic_dao.get_node.assert_called_once_with(sibling)
 def test_potential_new_children_2(self):
     node = Node(
         SystematicPoint(SystematicIdentifier("1.2", 1), "Description"))
     new_child_identifiers = self.service.get_potential_new_child_identifier(
         node)
     self.assertEqual(1, len(new_child_identifiers))
     self.assertEqual(SystematicIdentifier("1.2", 1, 1),
                      new_child_identifiers[0])
    def test_fetch_systematic_entry_for_id_string(self):

        identifier = SystematicIdentifier("1.2", 3, 4)
        self.systematic_dao.get_node = MagicMock(
            return_value=SystematicPoint(identifier, "description"))
        entry = self.service.fetch_systematic_entry_for_id_string("1.2.III-4")
        self.systematic_dao.get_node.assert_called_once_with(identifier)
        self.assertEqual(entry.id, identifier)
        self.assertEqual(entry.description, "description")
コード例 #10
0
 def test_insert(self):
     parent_id = SystematicIdentifier('1.1', 2)
     parent_node = self.dao.get_node(parent_id)
     self.assertEqual(len(parent_node.children), 3)
     identifier = SystematicIdentifier('1.1', 2, 4)
     node = SystematicPoint(identifier, "Completely new node")
     self.dao.save(node)
     parent_node = self.dao.get_node(parent_id)
     self.assertEqual(len(parent_node.children), 4)
     self.assertEqual(identifier, parent_node.children[-1].id)
コード例 #11
0
    def test_for_wrong_entry(self):

        document = self.document_dao.get_by_id(1)
        systematic_point = SystematicPoint(SystematicIdentifier("35.4.6"),
                                           "Not existing")
        self.systematic_service.add_systematic_entry_to_document(
            document, systematic_point)
        self.presenter.view.current_document = document
        self.presenter._load_systematic_items()
        self.assertMessage(ERROR_MESSAGE)
コード例 #12
0
    def test_new_entry(self):
        self.view.working_entry = SystematicPoint(SystematicIdentifier("2.1"),
                                                  "New entry")

        with pytest.raises(NoSuchNodeException):
            self.tree.get_by_id(SystematicIdentifier("2.1"))

        self.presenter.save_working_entry_action()

        new_tree = self.service.get_systematic_tree()
        new_entry = new_tree.get_by_id(SystematicIdentifier("2.1"))
        self.assertFalse(new_entry is None)
    def testRemoveSystematicEntryFromDocumentLocation(self):
        document = Document(56)
        document.standort = "1.2.III-4"
        systematic_identifier = SystematicIdentifier("1.2", 3, 4)
        systematic_point = QualifiedSystematicPoint(
            SystematicPoint(systematic_identifier, "Description"), True)

        self.service.remove_systematic_entry_from_document(
            document, systematic_point)

        self.assertEqual(document.standort, None)
        self.references_dao.set_signature_for_document_id.assert_called_with(
            56, None)
    def testRemoveSystematicEntryFromDocumentRelations(self):
        document = Document(56)
        document.standort = "1.2.III-4"
        systematic_identifier = SystematicIdentifier("1.2", 3, 4)
        systematic_point = SystematicPoint(systematic_identifier,
                                           "Description")
        qualified_systematic_node = QualifiedSystematicPoint(
            systematic_point, False)

        self.service.remove_systematic_entry_from_document(
            document, qualified_systematic_node)

        self.references_dao.remove_systematik_document_relation(
            56, systematic_identifier)
    def test_set_signature_for_document_id_I(self):
        '''
        Tests for existing signature
        '''
        systematic_node = SystematicPoint(SystematicIdentifier("1.2"), "desc")
        self.dao.set_signature_for_document_id(1, systematic_node)

        table = DOCUMENT_TABLE
        query = select([table.c.standort]).where(table.c.laufnr == 1)
        row = self.dao._get_exactly_one_row(query)
        self.assertEqual('1.2', row[table.c.standort])

        signature = self.dao.fetch_signature_for_document_id(1)
        self.assertEqual(signature, systematic_string_to_identifier('1.2'))
コード例 #16
0
 def __init__(self):
     self.nodes = [
         SystematicPoint(SystematicIdentifier(None), "Root"),
         SystematicPoint(SystematicIdentifier("0"), "Node 0"),
         SystematicPoint(SystematicIdentifier("0.1"), "Node 0.1"),
         SystematicPoint(SystematicIdentifier("0.2"), "Node 0.2"),
         SystematicPoint(SystematicIdentifier("1"), "Node 1"),
         SystematicPoint(SystematicIdentifier("1.1"), "Node 1.1"),
         SystematicPoint(SystematicIdentifier("1.2"), "Node 1.2"),
     ]
     self.tree = Tree(self.nodes)
     self.doc_nodes = [[], [self.nodes[2], self.nodes[3]],
                       [self.nodes[4], self.nodes[5]]]
    def testAddSystematicEntryToDocumentWithoutLocation(self):
        # Setup
        document = Document(56)
        systematic_node = SystematicPoint(SystematicIdentifier("1.2", 3, 4),
                                          "Description")
        self.references_dao.fetch_signature_for_document_id = MagicMock(
            return_value=None)

        # Execution
        self.service.add_systematic_entry_to_document(document,
                                                      systematic_node)

        # Assertion
        self.references_dao.set_signature_for_document_id.assert_called_once_with(
            document.id, systematic_node)
    def testAddSystematicEntryToDocumentWithLocation(self):
        # Setup
        document = Document(56)
        document.standort = "1.2.III-4"
        systematic_identifier = SystematicIdentifier("5.6", 7, 8)
        systematic_node = SystematicPoint(systematic_identifier, "Description")

        # Execution
        self.service.add_systematic_entry_to_document(document,
                                                      systematic_node)

        # Assertion
        self.assertEqual(document.standort, "1.2.III-4")
        self.references_dao.add_systematik_document_relation.assert_called_with(
            systematic_identifier, 56)
コード例 #19
0
    def setUp(self):

        self.export_info = ExportInfo()
        self.export_info = ExportInfo()
        self.export_info.cd_name = "TEST_CD"
        self.export_info.start_date = AlexDate(1973, 5, 1)
        self.export_info.end_date = AlexDate(1974, 5, 1)
        self.export_info.location_id = SystematicPoint(
            SystematicIdentifier("1.2.3", 4, 5), "dummy description")

        self.export_info_json = '{%s, %s, %s, %s}' % (
            '"cd_name": "TEST_CD"',
            '"end_date": {"_day": 1, "_month": 5, "_year": 1974}',
            '"location_id": {%s, %s}' %
            ('"description": "dummy description"',
             '"id": {"node_id": "1.2.3", "roman": 4, "subfolder": 5}'),
            '"start_date": {"_day": 1, "_month": 5, "_year": 1973}')

        self.message_broker = MessageBroker()
        self.generation_engine = MagicMock(spec=GenerationEngine)
        self.presenter = ChronoCDExporterMenuAdditionsPresenter(
            self.message_broker, self.generation_engine)

        self.presenter.view = MagicMock()
    def test_delete(self):

        identifier = SystematicIdentifier("1.2.3")
        node = SystematicPoint(identifier, "Description")
        self.service.delete(node)
        self.systematic_dao.delete.assert_called_once_with(identifier)
 def test_to_string_1(self):
     node = SystematicPoint(SystematicIdentifier("1.2"), "Description")
     self.assertEqual("%s" % node, "1.2: Description")
 def test_to_string_2(self):
     # Root node
     node = SystematicPoint(SystematicIdentifier(None), "Description")
     self.assertEqual("%s" % node, "Description")
コード例 #23
0
    def create_new_entry_action(self):

        self.view.working_entry = SystematicPoint(self.view.new_child_id,
                                                  _('No description'))
コード例 #24
0
 def test_update(self):
     identifier = SystematicIdentifier('1.1', 2, 3)
     node = SystematicPoint(identifier, "Completely new description")
     self.dao.save(node)
     node = self.dao.get_node(identifier)
     self.assertEqual("%s" % node, "1.1.II-3: Completely new description")
 def test_hash(self):
     dictionary = {}
     identifier = SystematicIdentifier("1.2", 3, 4)
     node = SystematicPoint(identifier, "Description")
     qualified_node = QualifiedSystematicPoint(node, False)
     dictionary[qualified_node] = None
 def test_string_for_relation_node(self):
     identifier = SystematicIdentifier("1.2", 3, 4)
     node = SystematicPoint(identifier, "Description")
     qualified_node = QualifiedSystematicPoint(node, False)
     node_as_string = "%s" % qualified_node
     self.assertEqual(node_as_string, "1.2.III-4: Description")
 def test_potential_new_children_1(self):
     node = Node(
         SystematicPoint(SystematicIdentifier("1.2", 1, 2), "Description"))
     self.assertEqual(
         0, len(self.service.get_potential_new_child_identifier(node)))