def test_len(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) self.assertEqual(3, len(sut))
def test_getitem_by_indices(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) self.assertSequenceEqual([entity1, entity3], sut[0::2])
def test_iter(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) self.assertSequenceEqual([entity1, entity2, entity3], list(sut))
def __init__(self, citation_id: Optional[str], source: Source): Entity.__init__(self, citation_id) Dated.__init__(self) HasFiles.__init__(self) HasPrivacy.__init__(self) self.location = None self.source = source
def test_clear(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) sut.clear() self.assertSequenceEqual([], sut)
def test_contains(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() sut.append(entity1) self.assertIn(entity1, sut) self.assertNotIn(entity2, sut)
def __init__(self, source_id: Optional[str], name: Optional[str] = None): Entity.__init__(self, source_id) Dated.__init__(self) HasFiles.__init__(self) HasLinks.__init__(self) HasPrivacy.__init__(self) self.name = name self.author = None self.publisher = None
def test_remove(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() entity4 = Entity() sut.append(entity1, entity2, entity3, entity4) sut.remove(entity4, entity2) self.assertSequenceEqual([entity1, entity3], sut)
def test_list(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) self.assertIs(entity1, sut[0]) self.assertIs(entity2, sut[1]) self.assertIs(entity3, sut[2])
def test_delitem_by_entity_id(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity('1') entity2 = Entity('2') entity3 = Entity('3') sut.append(entity1, entity2, entity3) del sut['2'] self.assertSequenceEqual([entity1, entity3], sut)
def test_add(self) -> None: sut1 = SingleTypeEntityCollection() sut2 = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() sut1.append(entity1) sut2.append(entity2) sut_added = sut1 + sut2 self.assertIsInstance(sut_added, SingleTypeEntityCollection) self.assertSequenceEqual([entity1, entity2], sut_added)
def test_delitem_by_index(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) del sut[1] self.assertSequenceEqual([entity1, entity3], sut)
def test_getitem_by_entity_id(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity('1') entity2 = Entity('2') entity3 = Entity('3') sut.append(entity1, entity2, entity3) self.assertIs(entity1, sut['1']) self.assertIs(entity2, sut['2']) self.assertIs(entity3, sut['3']) with self.assertRaises(KeyError): sut['4']
def test_getitem_by_index(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) self.assertIs(entity1, sut[0]) self.assertIs(entity2, sut[1]) self.assertIs(entity3, sut[2]) with self.assertRaises(IndexError): sut[3]
def test_append(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity3) sut.append(entity2) sut.append(entity1) # Append an already appended value again, and assert that it was ignored. sut.append(entity1) self.assertSequenceEqual([entity3, entity2, entity1], sut)
def __init__(self, event_id: Optional[str], event_type: EventType, date: Optional[Datey] = None): Entity.__init__(self, event_id) Dated.__init__(self) HasFiles.__init__(self) HasCitations.__init__(self) Described.__init__(self) HasPrivacy.__init__(self) self.date = date self._type = event_type
def __init__(self, person: Person, individual: Optional[str] = None, affiliation: Optional[str] = None): Entity.__init__(self) Localized.__init__(self) HasCitations.__init__(self) self._individual = individual self._affiliation = affiliation # Set the person association last, because the association requires comparisons, and self.__eq__() uses the # individual and affiliation names. self.person = person
def __init__(self, file_id: Optional[str], path: PathLike, media_type: Optional[MediaType] = None): Entity.__init__(self, file_id) Described.__init__(self) HasPrivacy.__init__(self) HasMediaType.__init__(self) HasNotes.__init__(self) HasCitations.__init__(self) self._path = Path(path) self.media_type = media_type
def test_prepend(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity('1') entity2 = Entity('2') entity3 = Entity('3') sut.prepend(entity3) sut.prepend(entity2) sut.prepend(entity1) # Prepend an already prepended value again, and assert that it was ignored. sut.prepend(entity1) self.assertIs(entity1, sut['1']) self.assertIs(entity2, sut['2']) self.assertIs(entity3, sut['3'])
def _encode_entity(self, encoded: Dict, entity: Entity) -> None: self._encode_schema( encoded, upper_camel_case_to_lower_camel_case( get_entity_type_name(entity.entity_type()))) if 'links' not in encoded: encoded['links'] = [] if not isinstance(entity.id, GeneratedEntityId): encoded['id'] = entity.id canonical = Link(self._generate_url(entity)) canonical.relationship = 'canonical' canonical.media_type = 'application/json' encoded['links'].append(canonical) for locale_configuration in self._app.configuration.locales: if locale_configuration.locale == self._locale: continue translation = Link( self._generate_url(entity, locale=locale_configuration.locale)) translation.relationship = 'alternate' translation.locale = locale_configuration.locale encoded['links'].append(translation) html = Link(self._generate_url(entity, media_type='text/html')) html.relationship = 'alternate' html.media_type = 'text/html' encoded['links'].append(html)
def test_set_like_functionality(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() entity4 = Entity() entity5 = Entity() entity6 = Entity() entity7 = Entity() entity8 = Entity() entity9 = Entity() # Ensure duplicates are skipped. sut.append(entity1, entity2, entity3, entity1, entity2, entity3, entity1, entity2, entity3) # Ensure skipped duplicates do not affect further new values. sut.append(entity1, entity2, entity3, entity4, entity5, entity6, entity7, entity8, entity9) self.assertSequenceEqual([ entity1, entity2, entity3, entity4, entity5, entity6, entity7, entity8, entity9 ], sut)
def test_replace(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() entity4 = Entity() entity5 = Entity() entity6 = Entity() sut.append(entity1, entity2, entity3) sut.replace(entity4, entity5, entity6) self.assertSequenceEqual([entity4, entity5, entity6], sut)
def _load_objref(loader: _Loader, owner: Entity, element: ElementTree.Element): file_handles = _load_handles('objref', element) for file_handle in file_handles: loader.add_association(owner.entity_type(), owner.id, 'files', File, file_handle)
def _load_citationref(loader: _Loader, owner: Entity, element: ElementTree.Element): for citation_handle in _load_handles('citationref', element): loader.add_association(owner.entity_type(), owner.id, 'citations', Citation, citation_handle)
def add_entity(self, entity: Entity) -> None: self._flattened_entities.add_entity(entity) self._added_entity_counts[entity.entity_type()] += 1
def __init__(self, note_id: str, text: str): Entity.__init__(self, note_id) self._text = text
def __init__(self, person_id: Optional[str]): Entity.__init__(self, person_id) HasFiles.__init__(self) HasCitations.__init__(self) HasLinks.__init__(self) HasPrivacy.__init__(self)
def test_id(self) -> None: entity_id = '000000001' sut = Entity(entity_id) self.assertEqual(entity_id, sut.id)
def test_entity_type_with_class(self) -> None: self.assertEqual(Entity, Entity.entity_type())
def test_entity_type_with_instance(self) -> None: self.assertEqual(Entity, Entity().entity_type())