Esempio n. 1
0
 def test_sorting_articles(self):
     article_dict = ArticleDict()
     for article_title in self.sorting_articles:
         article = Article(title=article_title)
         article_dict[article.uuid] = article
     article_titles = [
         a.title for a in article_dict.sort_by_title().values()
     ]
     self.sorting_articles.sort()
     self.assertEqual(article_titles, self.sorting_articles,
                      'Verify article dict is sorted')
Esempio n. 2
0
 def __init__(self,
              collection: ArticleDict,
              search_string: str,
              title_search: bool = True,
              tag_search: bool = True,
              description_search: bool = True):
     self._collection = collection
     self._title_search = title_search
     self._tag_search = tag_search
     self._description_search = description_search
     self._search_string = search_string
     self._search_results = ArticleDict()
Esempio n. 3
0
 def test_adding_articles(self):
     article_dict = ArticleDict()
     for article_data in self.articles_to_add.articles:
         article = Article(title=article_data.title,
                           description=article_data.description,
                           page=article_data.page,
                           binder=article_data.binder,
                           tags=article_data.tags)
         article_dict[article.uuid] = article
         self.assertEqual(article_dict[article.uuid], article,
                          'Verify article is added')
         self._save_needed_test(
             'Verify save is needed after adding article')
Esempio n. 4
0
 def test_add_article_with_the_same_uuid(self):
     article_dict = ArticleDict()
     article1 = Article(title='test1')
     article2 = Article(title='test2')
     article2._uuid = article1.uuid
     article_dict[article1.uuid] = article1
     SAVE_NEEDED.clear()
     with self.assertRaises(
             DuplicatedArticle,
             msg=
             f'Verify exception is raised when adding article with the same uuid as existing'
     ):
         article_dict[article2.uuid] = article2
     self.assertFalse(
         SAVE_NEEDED.is_set(),
         f'Verify save is not needed after exception of duplicated uuid')
     self.assertEqual(
         len(article_dict), 1,
         'Verify duplicated article was not added to ArticleDict')
Esempio n. 5
0
 def verify_articles_in_dictionary(self, dictionary: ArticleDict,
                                   test_data: ArticleDictTestData):
     self.assertEqual(len(dictionary), len(test_data.articles),
                      'Verify count of articles is correct')
     for test_data_article in test_data.articles:
         passed = False
         for article in dictionary.values():
             if test_data_article.title == article.title:
                 if test_data_article.page != article.page:
                     continue
                 if test_data_article.description != article.description:
                     continue
                 if test_data_article.binder != article.binder:
                     continue
                 if test_data_article.tags != article.tags:
                     continue
                 passed = True
         self.assertTrue(
             passed,
             f'Verify article is present: title: {test_data_article.title}, '
             f'\n\tdescription: {test_data_article.description}, \n\tpage: {test_data_article.page}, '
             f'\n\tbinder: {test_data_article.binder}, \n\ttags: {test_data_article.tags}'
         )
Esempio n. 6
0
class ArticleCollection:
    def __init__(self):
        self._article_list = ArticleDict()
        self.load_data()
        self._auto_save = AutoSave(self._article_list)
        self._auto_save.start()

    def __del__(self):
        self._auto_save.stop.set()

    def add_new_article(self,
                        title: str,
                        description: str = '',
                        page: str = '',
                        binder: str = '',
                        tags: List[str] = None) -> str:
        article = Article(title=title,
                          description=description,
                          page=page,
                          binder=binder,
                          tags=tags)
        try:
            self._article_list[article.uuid] = article
        except DuplicatedArticle:
            article.generate_uuid()
            self._article_list[article.uuid] = article
        return article.uuid

    def add_existing_article(self, article: Article):
        self._article_list[article.uuid] = article

    @property
    def articles_list(self) -> ArticleDict:
        return self._article_list

    @property
    def articles_list_sorted(self) -> OrderedDict:
        return self._article_list.sort_by_title()

    def get_article(self, uuid: str) -> Article:
        if uuid not in self._article_list.keys():
            raise InvalidUuidError(f'UUID: "{uuid}" does not exist')
        return self._article_list[uuid]

    def remove_article(self, uuid: str):
        if uuid not in self._article_list.keys():
            raise InvalidUuidError(f'UUID: "{uuid}" does not exist')
        del self._article_list[uuid]

    def edit_article(self,
                     uuid: str,
                     title: str = '',
                     description: str = '',
                     page: str = '',
                     binder: str = '',
                     tags: List[str] = None):
        if uuid not in self._article_list.keys():
            raise InvalidUuidError(f'UUID: "{uuid}" does not exist')
        article = self.get_article(uuid)
        if title:
            article.title = title
        if description:
            article.description = description
        if page:
            article.page = page
        if binder:
            article.binder = binder
        if tags:
            article.tags = tags

    def load_data(self):
        save_load = SaveLoad(self._article_list)
        save_load.load_data()
Esempio n. 7
0
 def __init__(self):
     self._article_list = ArticleDict()
     self.load_data()
     self._auto_save = AutoSave(self._article_list)
     self._auto_save.start()
Esempio n. 8
0
 def test_create_article_dict(self):
     article_dict = ArticleDict()
     self.assertIsInstance(
         article_dict, ArticleDict,
         'Verify created instance is type of ArticleDict')