def setUp(self):
        engine = create_engine('sqlite:///:memory:', echo=False)
        db.create_tables(engine)

        Session = sessionmaker(bind=engine)
        self.session = Session()
        self.category_repository = CategoryRepository(self.session)
class TestCategoryRepository(unittest.TestCase):

    def setUp(self):
        engine = create_engine('sqlite:///:memory:', echo=False)
        db.create_tables(engine)

        Session = sessionmaker(bind=engine)
        self.session = Session()
        self.category_repository = CategoryRepository(self.session)

    def tearDown(self):
        self.session.close()

    def test_create_category_with_one_new_category(self):
        self.category_repository.create_category("News")

        all_result_categories = self.category_repository.get_all_categories()
        assert len(all_result_categories) == 1
        assert all_result_categories[0][0] == 1
        assert all_result_categories[0][1] == "News"

    def test_create_category_with_three_categories(self):
        test_categories = ["News", "Childrens books", "Technical news"]

        for test_category in test_categories:
            self.category_repository.create_category(test_category)

        all_result_categories = self.category_repository.get_all_categories()

        assert len(all_result_categories) == 3
        for result_category in all_result_categories:
            assert result_category[1] in test_categories
class TestWebsiteRepository(unittest.TestCase):

    def setUp(self):
        engine = create_engine('sqlite:///:memory:', echo=False)
        db.setup_db(engine)

        Session = sessionmaker(bind=engine)
        self.session = Session()
        self.category_repository = CategoryRepository(self.session)
        self.website_repository = WebsiteRepository(self.session)

    def tearDown(self):
        self.session.close()

    def test_create_website(self):
        self.website_repository.create_website('www.wikipedia.com', 'english', 'test')

        all_result_websites = self.website_repository.get_all_websites()

        assert len(all_result_websites) == 1
        assert all_result_websites[0][0] == 1
        assert all_result_websites[0][1] == 'www.wikipedia.com'
        assert all_result_websites[0][2] == 'english'

    def test_create_three_websites(self):
        test_websites = [('www.wikipedia.com', 'english', 'english test'),
            ('www.wikipedia.it', 'italian', 'italiano'),
            ('www.simple.wikipedia.com', 'english', 'simple english')]

        for test_website in test_websites:
            self.website_repository.create_website(*test_website)

        all_result_websites = self.website_repository.get_all_websites()

        assert len(all_result_websites) == 3
        for i in range(3):
            assert all_result_websites[i][0] == i+1
            assert all_result_websites[i][1] == test_websites[i][0]
            assert all_result_websites[i][2] == test_websites[i][1]

    def test_get_website_by_category(self):
        website_id = self.website_repository.create_website('www.wikipedia.it', 'italian', 'italiano')
        category_id = self.category_repository.create_category('wiki')
        self.category_repository.add_website(category_id, website_id)

        all_result_websites = self.website_repository.get_websites_by_category(category_id)

        assert all_result_websites[0][0] == 1
        assert all_result_websites[0][1] == 'www.wikipedia.it'
        assert all_result_websites[0][2] == 'italian'

    def test_get_website_id_by_search_term(self):
        website_id = self.website_repository.create_website(
            'https://it.wikipedia.org/wiki/Lingua_italiana',
            'italian',
            'lingua italiana')
        self.session.commit()

        website_ids = self.website_repository.get_website_ids_by_title(
            'lingua')

        assert len(website_ids) == 1
        assert website_ids[0] == website_id