Exemplo n.º 1
0
    def test_event_relationship(self, item):
        db_add_objects(Event, all_events)
        word = dar(Word, item)

        event_start_from_db = Event.get_by_id(word.event_start_id)
        assert isinstance(event_start_from_db, Event)
        assert event_start_from_db == word.event_start

        if word.event_end_id:
            event_end_from_db = Event.get_by_id(word.event_end_id)
            assert isinstance(event_end_from_db, Event)
            assert event_end_from_db == word.event_start
        else:
            assert word.event_end is None
Exemplo n.º 2
0
    def test_relationship_appeared_words(self):
        db_add_objects(Word, changed_words)
        db_add_objects(Event, changed_events)
        event = Event.get_by_id(5)

        assert isinstance(event.deprecated_words, list)
        assert len(event.deprecated_words) == 4
Exemplo n.º 3
0
    def test_create_from_dict_with_data(self, item):
        """Get Word by ID."""

        event = dar(Event, item)
        event_from_db = Event.get_by_id(item["id"])

        assert event == event_from_db
        assert isinstance(event, Event)
        assert isinstance(event.id, int)
        assert isinstance(event.date, datetime.date)
        assert isinstance(event.name, str)
        assert isinstance(event.definition, str)
        assert isinstance(event.annotation, str)
        assert isinstance(event.suffix, str)
Exemplo n.º 4
0
    def by_event(cls,
                 event_id: Union[BaseEvent, int] = None,
                 add_to: BaseQuery = None) -> BaseQuery:
        """Query filtered by specified Event (latest by default)

        Args:
          event_id: Union[BaseEvent, int]: Event object or Event.id (int) (Default value = None)
          add_to:
        Returns:
          BaseQuery

        """
        if not event_id:
            event_id = BaseEvent.latest().id

        event_id = BaseEvent.id if isinstance(event_id,
                                              BaseEvent) else int(event_id)

        request = add_to if add_to else cls.query
        return cls._filter_event(event_id, request).order_by(cls.name)
Exemplo n.º 5
0
    def html_all_by_name(cls,
                         name: str,
                         style: str = DEFAULT_HTML_STYLE,
                         event_id: Union[BaseEvent, int, str] = None,
                         case_sensitive: bool = False) -> Optional[str]:
        """
        Convert all words found by name into one HTML string
        Args:
            name: Name of the search word
            style: HTML design style
            event_id:
            case_sensitive:
        Returns:

        """

        words_template = {
            "normal": '<div class="words">\n%s\n</div>\n',
            "ultra": '<ws>\n%s\n</ws>\n',
        }

        if not event_id:
            event_id = BaseEvent.latest().id

        event_id = int(event_id) if isinstance(event_id,
                                               (int, str)) else BaseEvent.id

        words = cls.by_name(name=name,
                            event_id=event_id,
                            case_sensitive=case_sensitive).all()

        if not words:
            return None

        items = cls._get_stylized_words(words, style)

        return words_template[style] % "\n".join(items)
Exemplo n.º 6
0
    def test_latest(self):
        db_add_objects(Event, all_events)
        latest = Event.latest()

        assert latest.id == 6
        assert latest.annotation == 'Torrua Repair'