Example #1
0
    def test_osd_no_article_subject(self):
        osd_plugin = OSDPlugin()
        test_article_00 = Article()
        test_article_00.subject = None
        test_article_00.body = "A very small body"
        test_article_00.topic = "First topic"
        test_articles = [test_article_00]

        mock = MagicMock(return_value="")
        with patch("builtins.print", mock):
            osd_plugin.store("Test", test_articles)

        assert mock.called
Example #2
0
File: pydesk.py Project: QFAPP/QF
    def convert_to_kbmodel(self, item_type, item_entries):
        """Converts the Desk.com items to KbExtractor items.

        :param item_type: The type of the item to convert.
        :param item_entries: All the entries to convert.
        """
        # Prepare the result list containing the converted entries
        converted_item_list = []

        # We need to have items to convert to perform some work
        if not item_entries:
            return converted_item_list

        # We need an item type to be able to convert the items
        if not item_type:
            return converted_item_list

        # If the item type contains a "/" (i.e.:
        # /api/v2/topics/633385/articles)
        # it means we have to retrieve the last part to determine the item type
        if item_type.__contains__("/"):
            item_type = item_type.split("/")[-1]

        # Go through all the entries and convert them to the appropriate type
        if item_type == "topics":
            for topic_entry in item_entries:
                # Skip entries that are not in the support center
                if not topic_entry.get("in_support_center"):
                    continue

                # Add the topic to the result list
                topic = Topic()
                topic.name = topic_entry.get("name", "")
                topic.meta = topic_entry.get("_links", {})
                converted_item_list.append(topic)

        if item_type == "articles":
            for article_entry in item_entries:
                article = Article()
                article.topic = self.topic
                article.subject = article_entry.get("subject", "")
                article.body = article_entry.get("body", "")
                converted_item_list.append(article)

        # Return the result. It will be an emtpy list if the item type is
        # invalid.
        return converted_item_list