Esempio n. 1
0
 def test_sorting_articles(self):
     interface = ArticleCollection()
     for article in self.test_data['sorting_test']:
         interface.add_new_article(article)
     added_articles = [
         article.title for article in interface.articles_list.values()
     ]
     self.assertEqual(sorted(self.test_data['sorting_test']),
                      added_articles,
                      'Verify articles are sorted alphabetically')
Esempio n. 2
0
 def test_add_article_with_title_only(self):
     article_uuid = self.article_collection.add_new_article(
         title=self.first_article.title)
     article = self.article_collection.get_article(article_uuid)
     Verifiers().verify_article_with_title_only(
         article=article, reference_article=self.first_article)
     WaitMethods().wait_for_save_completed()
     new_collection = ArticleCollection()
     self.assertTrue(
         article_uuid in new_collection.articles_list.keys(),
         'Verify new article uuid is present when creating new article collection (loaded from saved file)'
     )
     Verifiers().verify_article_with_title_only(
         article=new_collection.get_article(article_uuid),
         reference_article=self.first_article)
Esempio n. 3
0
 def test_removing_article(self):
     interface = ArticleCollection()
     uuids = list()
     for article in self.test_data['add_articles']:
         uuids.append(
             interface.add_new_article(article['title'],
                                       article['description'],
                                       article['page'], article['binder'],
                                       article['tags']))
     for uuid in uuids:
         interface.remove_article(uuid)
         self.assertFalse(uuid in interface.articles_list.keys(),
                          'Verify item was removed from articles list')
     self.assertEqual(len(interface.articles_list), 0,
                      'Verify articles list is empty')
Esempio n. 4
0
 def setUpClass(cls) -> None:
     initializers.initialize_save_test()
     copy(os.path.join(Environment().test_data_path, 'database_for_test.dat'), Environment().database_file)
     cls.article_collection = ArticleCollection()
     with open(TEST_DATA_PATH) as f:
         json_loaded = json.load(f)
     cls.articles_to_add = ArticleDictTestData(json_loaded['add_articles'])
Esempio n. 5
0
 def setUpClass(cls) -> None:
     initializers.initialize_save_test()
     cls.article_collection = ArticleCollection()
     with open(TEST_DATA_PATH) as f:
         json_loaded = json.load(f)
     cls.sorting_articles = ArticleDictTestData(
         json_loaded['sorting_articles'])
Esempio n. 6
0
 def test_add_existing_article(self):
     article = Article(title=self.second_article.title,
                       description=self.second_article.description,
                       page=self.second_article.page,
                       binder=self.second_article.binder,
                       tags=self.second_article.tags)
     self.article_collection.add_existing_article(article)
     Verifiers().verify_article_with_all_fields(
         article=self.article_collection.get_article(article.uuid),
         reference_article=self.second_article)
     WaitMethods().wait_for_save_completed()
     new_collection = ArticleCollection()
     self.assertTrue(
         article.uuid in new_collection.articles_list.keys(),
         'Verify new article uuid is present when creating new article collection (loaded from saved file)'
     )
     Verifiers().verify_article_with_all_fields(
         article=new_collection.get_article(article.uuid),
         reference_article=self.second_article)
Esempio n. 7
0
 def test_adding_articles(self):
     added_articles = dict()
     interface = ArticleCollection()
     for article in self.test_data['add_articles']:
         uuid = interface.add_new_article(article['title'],
                                          article['description'],
                                          article['page'],
                                          article['binder'],
                                          article['tags'])
         added_articles[uuid] = article
     self.assertEqual(len(interface.articles_list),
                      len(self.test_data['add_articles']),
                      'Verify articles count')
     for uuid, article in added_articles.items():
         article_in_interface = interface.get_article(uuid)
         for field_key, field_value in article.items():
             self.assertEqual(field_value,
                              getattr(article_in_interface, field_key),
                              f'Verify field {field_key} is corect')
Esempio n. 8
0
class ArticleListTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        initializers.initialize_save_test()
        copy(
            os.path.join(Environment().test_data_path,
                         'database_for_test.dat'),
            Environment().database_file)
        with open(TEST_DATA_PATH) as f:
            json_loaded = json.load(f)
        cls.articles_to_add = ArticleDictTestData(json_loaded['add_articles'])
        cls.sorting_articles = json_loaded['sorting_test']

    @classmethod
    def tearDownClass(cls) -> None:
        cleanups.cleanup_save_test()

    def setUp(self) -> None:
        self.article_collection = ArticleCollection()

    def tearDown(self) -> None:
        del self.article_collection

    def test_attribute_articles_list(self):
        self.assertIsInstance(self.article_collection._article_list,
                              ArticleDict,
                              'Verify _articles_list is ArticleDict instance')

    def test_get_article(self):
        for article in self.article_collection.articles_list.values():
            self.assertEqual(
                article, self.article_collection.get_article(article.uuid),
                'Verify article returned by get_article is correct')

    def test_get_article_incorrect_uuid(self):
        with self.assertRaises(
                InvalidUuidError,
                msg=
                f'Verify exception is raised when trying to get article with invalid UUID'
        ):
            self.article_collection.get_article(
                '0000000000000000000000000000000')
Esempio n. 9
0
 def test_removing_article(self):
     self.article_collection.remove_article(self.remove_uuid)
     self.assertEqual(len(self.article_collection.articles_list), 1,
                      'Verify len of articles list is 1 after remove')
     self.assertTrue(
         self.remove_uuid
         not in self.article_collection.articles_list.keys(),
         'Verify article was removed')
     WAIT_METHODS.wait_for_save_completed()
     new_collection = ArticleCollection()
     self.assertEqual(len(new_collection.articles_list), 1,
                      'Verify len of articles list is 1 after load')
     self.assertTrue(
         self.remove_uuid not in new_collection.articles_list.keys(),
         'Verify article is not present after load')
Esempio n. 10
0
class ArticleListTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        initializers.initialize_save_test()
        with open(TEST_DATA_PATH) as f:
            json_loaded = json.load(f)
        cls.first_article = ArticleTestData(json_loaded['add_articles'][0])
        cls.second_article = ArticleTestData(json_loaded['add_articles'][1])

    @classmethod
    def tearDownClass(cls) -> None:
        cleanups.cleanup_save_test()

    def setUp(self) -> None:
        self.article_collection = ArticleCollection()
        self.article_collection.add_new_article(self.first_article.title)
        self.remove_uuid = self.article_collection.add_new_article(
            self.second_article.title)
        WAIT_METHODS.wait_for_save_completed()

    def tearDown(self) -> None:
        del self.article_collection

    def test_removing_article(self):
        self.article_collection.remove_article(self.remove_uuid)
        self.assertEqual(len(self.article_collection.articles_list), 1,
                         'Verify len of articles list is 1 after remove')
        self.assertTrue(
            self.remove_uuid
            not in self.article_collection.articles_list.keys(),
            'Verify article was removed')
        WAIT_METHODS.wait_for_save_completed()
        new_collection = ArticleCollection()
        self.assertEqual(len(new_collection.articles_list), 1,
                         'Verify len of articles list is 1 after load')
        self.assertTrue(
            self.remove_uuid not in new_collection.articles_list.keys(),
            'Verify article is not present after load')

    def test_removing_article_invalid_uuid(self):
        with self.assertRaises(
                InvalidUuidError,
                msg=
                f'Verify exception is raised when trying to remove article with invalid UUID'
        ):
            self.article_collection.remove_article(
                '0000000000000000000000000000000')
Esempio n. 11
0
 def setUp(self) -> None:
     self.article_collection = ArticleCollection()
Esempio n. 12
0
 def setUp(self) -> None:
     self.article_collection = ArticleCollection()
     self.article_collection.add_new_article(self.first_article.title)
     self.remove_uuid = self.article_collection.add_new_article(
         self.second_article.title)
     WAIT_METHODS.wait_for_save_completed()
Esempio n. 13
0
class AddArticleTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        initializers.initialize_save_test()
        with open(TEST_DATA_PATH) as f:
            json_loaded = json.load(f)
        cls.first_article = ArticleTestData(json_loaded['add_articles'][0])
        cls.second_article = ArticleTestData(json_loaded['add_articles'][1])

    def setUp(self) -> None:
        self.article_collection = ArticleCollection()

    def tearDown(self) -> None:
        del self.article_collection

    @classmethod
    def tearDownClass(cls) -> None:
        cleanups.cleanup_save_test()

    def test_add_article_with_title_only(self):
        article_uuid = self.article_collection.add_new_article(
            title=self.first_article.title)
        article = self.article_collection.get_article(article_uuid)
        Verifiers().verify_article_with_title_only(
            article=article, reference_article=self.first_article)
        WaitMethods().wait_for_save_completed()
        new_collection = ArticleCollection()
        self.assertTrue(
            article_uuid in new_collection.articles_list.keys(),
            'Verify new article uuid is present when creating new article collection (loaded from saved file)'
        )
        Verifiers().verify_article_with_title_only(
            article=new_collection.get_article(article_uuid),
            reference_article=self.first_article)

    def test_add_article_with_all_fields(self):
        article_uuid = self.article_collection.add_new_article(
            title=self.second_article.title,
            description=self.second_article.description,
            page=self.second_article.page,
            binder=self.second_article.binder,
            tags=self.second_article.tags)
        article = self.article_collection.get_article(article_uuid)
        Verifiers().verify_article_with_all_fields(
            article=article, reference_article=self.second_article)
        WaitMethods().wait_for_save_completed()
        new_collection = ArticleCollection()
        self.assertTrue(
            article_uuid in new_collection.articles_list.keys(),
            'Verify new article uuid is present when creating new article collection (loaded from saved file)'
        )
        Verifiers().verify_article_with_all_fields(
            article=new_collection.get_article(article_uuid),
            reference_article=self.second_article)

    def test_add_existing_article(self):
        article = Article(title=self.second_article.title,
                          description=self.second_article.description,
                          page=self.second_article.page,
                          binder=self.second_article.binder,
                          tags=self.second_article.tags)
        self.article_collection.add_existing_article(article)
        Verifiers().verify_article_with_all_fields(
            article=self.article_collection.get_article(article.uuid),
            reference_article=self.second_article)
        WaitMethods().wait_for_save_completed()
        new_collection = ArticleCollection()
        self.assertTrue(
            article.uuid in new_collection.articles_list.keys(),
            'Verify new article uuid is present when creating new article collection (loaded from saved file)'
        )
        Verifiers().verify_article_with_all_fields(
            article=new_collection.get_article(article.uuid),
            reference_article=self.second_article)
Esempio n. 14
0
 def test_modifying_article(self):
     interface = ArticleCollection()
     article = self.test_data['editing_test']
     title = article['title']
     description = article['description']
     page = article['page']
     binder = article['binder']
     tags = article['tags']
     uuid = interface.add_new_article(title, description, page, binder,
                                      tags)
     interface.edit_article(uuid=uuid,
                            title=f'{title}_edited',
                            description=f'{description}_edited',
                            page=f'{page}_edited',
                            binder=f'{binder}_edited',
                            tags=['tagi_edited'])
     self.assertEqual(
         interface.get_article(uuid).title, f'{title}_edited',
         'Verify title was edited')
     self.assertEqual(
         interface.get_article(uuid).description, f'{description}_edited',
         'Verify description was edited')
     self.assertEqual(
         interface.get_article(uuid).page, f'{page}_edited',
         'Verify page was edited')
     self.assertEqual(
         interface.get_article(uuid).binder, f'{binder}_edited',
         'Verify binder was edited')
     self.assertEqual(
         interface.get_article(uuid).tags, ['tagi_edited'],
         'Verify tags was edited')
     interface.edit_article(uuid=uuid,
                            title=f'{title}_edited2',
                            binder=f'{binder}_edited2')
     self.assertEqual(
         interface.get_article(uuid).title, f'{title}_edited2',
         'Verify title was edited')
     self.assertEqual(
         interface.get_article(uuid).description, f'{description}_edited',
         'Verify description was edited')
     self.assertEqual(
         interface.get_article(uuid).page, f'{page}_edited',
         'Verify page was edited')
     self.assertEqual(
         interface.get_article(uuid).binder, f'{binder}_edited2',
         'Verify binder was edited')
     self.assertEqual(
         interface.get_article(uuid).tags, ['tagi_edited'],
         'Verify tags was edited')
     interface.get_article(uuid).tags.append('tag_added')
     self.assertEqual(
         interface.get_article(uuid).tags, ['tagi_edited', 'tag_added'],
         'Verify tag was added')
Esempio n. 15
0
 def setUpClass(cls) -> None:
     initializers.initialize_save_test()
     cls.article_collection = ArticleCollection()
Esempio n. 16
0
from lib.article import Article
from lib.article_dict import ArticleDict
from lib.article_collection import ArticleCollection
from lib.search_engine import SearchEngine
from lib.save_load import AutoSave

INTERFACE = ArticleCollection()


def print_articles(articles=INTERFACE.articles_list_sorted):
    for article in articles.values():
        print(article.title)
        # print(f'\t{article.description}\n\t{article.binder}\n\t{article.page}')
        # for tag in article.tags:
        #     print(f'\t\t{tag}')
        # print(f'\t{article.uuid}')
        print(
            '===============================================================')


search = SearchEngine(INTERFACE.articles_list, 'wlochy')
search.search()
print_articles(search.search_results.sort_by_title())

print_articles()
pass