Ejemplo n.º 1
0
class TestRepo(unittest.TestCase):
    def setUp(self):
        self._repo = Repository({})
        self._repo.save(Book('1', "The Dream", 'Jack Sparrow'))
        self._repo.save(Book('2', "Good Day", 'Salam de Sibiu'))
        self._repo.save(Book('3', "I have no Ideea", 'Someone'))
        self._repo.save(Book('4', "The legend", 'Guta'))
        self._repo.save(Book('5', "Unknown", 'Nicoae Balcescu'))
        self._repo.save(Book('6', "Cocalar", 'Dani Mocanu'))
        try:
            self._repo.save(Book('6', "Cocalar", 'Dani Mocanu'))
        except RepositoryException:
            pass

    def test_repo_save(self):
        a = self._repo.get_entities()
        self.assertNotEqual(len(a), 0)
        self.assertIn('1', a)
        self.assertIn('2', a)
        self.assertIn('3', a)
        self.assertIn('4', a)
        self.assertIn('5', a)
        self.assertIn('6', a)
        self.assertIs('Jack Sparrow', a['1'].author)
        self.assertEqual(len(a), 6)

    def test_find_by(self):
        self.assertEqual(self._repo.find_by_id('12'), None)
        self.assertNotEqual(self._repo.find_by_id('1'), None)

    def test_remove(self):
        self._repo.remove('1')
        self.assertEqual(self._repo.find_by_id('1'), None)
        try:
            self._repo.remove('1')
        except RepositoryException:
            pass
Ejemplo n.º 2
0
class TestBookService(unittest.TestCase):
    def setUp(self):
        self._book_validator = BookValidator()
        self._book_repository = Repository({})
        self._book_service = BookService(self._book_repository, self._book_validator)
        self._book_service.add_book('1', 'The Book', 'King Arthur')
        self._book_service.add_book('2', 'The Prize', 'Im Somebody')
        self._book_service.add_book('3', 'Im Out Of Ideeas', 'Some random dude')
        try:
            self._book_service.add_book('4', '4', '434')
        except BookValidatorException:
            pass

    def test_book_add(self):
        a = self._book_repository.get_entities()
        self.assertEqual(len(a), 3)
        self.assertEqual(a['1'].title, 'The Book')
        self.assertEqual(a['1'].author, 'King Arthur')
        self.assertEqual(a['2'].title, 'The Prize')
        self.assertEqual(a['2'].author, 'Im Somebody')

    def test_book_remove(self):
        self._book_service.remove_book('1')
        a = self._book_repository.get_entities()
        self.assertEqual(len(a), 2)
        self.assertEqual(self._book_repository.find_by_id('1'), None)

    def test_search_by_id(self):
        a = self._book_service.search_book_by_id('1')
        self.assertEqual(a[0].id, '1')
        self.assertEqual(a[0].author, 'King Arthur')
        self.assertEqual(a[0].title, 'The Book')

    def test_search_by_title(self):
        a = self._book_service.search_book_by_title('The')
        self.assertEqual(a[0].id, '1')
        self.assertEqual(a[0].author, 'King Arthur')
        self.assertEqual(a[0].title, 'The Book')
        self.assertEqual(len(a), 2)
        self.assertEqual(a[1].id, '2')
        self.assertEqual(a[1].author, 'Im Somebody')
        self.assertEqual(a[1].title, 'The Prize')

    def test_search_by_author(self):
        a = self._book_service.search_book_by_author('King')
        self.assertEqual(a[0].id, '1')
        self.assertEqual(a[0].author, 'King Arthur')
        self.assertEqual(a[0].title, 'The Book')
Ejemplo n.º 3
0
class TestClientService(unittest.TestCase):
    def setUp(self):
        self._client_validator = ClientValidator()
        self._client_repository = Repository({})
        self._client_service = ClientService(self._client_repository, self._client_validator)
        self._client_service.add_client('1', 'King Arthur')
        self._client_service.add_client('2', 'Im Somebody')
        self._client_service.add_client('3', 'Some random dude')
        try:
            self._client_service.add_client('4', '43')
        except ClientValidatorException:
            pass

    def test_client_add(self):
        a = self._client_repository.get_entities()

        self.assertEqual(len(a), 3)
        self.assertEqual(a['1'].name, 'King Arthur')
        self.assertEqual(a['2'].name, 'Im Somebody')
        self.assertEqual(a['3'].name, 'Some random dude')

    def test_client_remove(self):
        self._client_service.remove_client('1')
        a = self._client_repository.get_entities()
        assert len(a) == 2
        self.assertEqual(self._client_repository.find_by_id('1'), None)

    def test_search_by_id(self):
        a = self._client_service.search_client_by_id('1')
        self.assertEqual(a[0].id, '1')
        self.assertEqual(a[0].name, 'King Arthur')

    def test_search_by_name(self):
        a = self._client_service.search_client_by_name('King')
        self.assertEqual(a[0].id, '1')
        self.assertEqual(a[0].name, 'King Arthur')
        self.assertEqual(len(a), 1)