Exemplo n.º 1
0
 def test___init__(self, mock_warning):
     Persistence()
     mock_warning.assert_called_with(
         "This persistence can`t access the database.")
     mock_session = mock.Mock()
     Persistence(mock_session)
     mock_session.get_session.assert_called_with()
Exemplo n.º 2
0
 def test_add_db(self, mock_flush):
     p = Persistence()
     self.assertFalse(p.add_db())
     mock_session = mock.Mock()
     mock_sessionobj = mock.Mock()
     mock_sessionobj.get_session.return_value = mock_session
     p = Persistence(mock_sessionobj)
     self.assertTrue(p.add_db())
     mock_flush.assert_called_with()
     mock_session.add.assert_called_with(Base)
     mock_session.commit.assert_called_with()
     mock_session.add.side_effect = IntegrityError(1, 2, 3)
     self.assertFalse(p.add_db())
     mock_session.rollback.assert_called_with()
Exemplo n.º 3
0
 def test_add_db(self, mock_flush):
     p = Persistence()
     self.assertFalse(p.add_db())
     mock_session = mock.Mock()
     mock_sessionobj = mock.Mock()
     mock_sessionobj.get_session.return_value = mock_session
     p = Persistence(mock_sessionobj)
     self.assertTrue(p.add_db())
     mock_flush.assert_called_with()
     mock_session.add.assert_called_with(Base)
     mock_session.commit.assert_called_with()
     mock_session.add.side_effect = IntegrityError(1, 2, 3)
     self.assertFalse(p.add_db())
     mock_session.rollback.assert_called_with()
Exemplo n.º 4
0
 def setUp(self):
     mock_session = mock.Mock()
     mock_session.get_session.return_value = "session"
     self.persistence = Persistence(mock_session)
Exemplo n.º 5
0
class TestPersistence(unittest.TestCase):
    def setUp(self):
        mock_session = mock.Mock()
        mock_session.get_session.return_value = "session"
        self.persistence = Persistence(mock_session)

    @mock.patch("ocr.persistence.warning")
    def test___init__(self, mock_warning):
        Persistence()
        mock_warning.assert_called_with(
            "This persistence can`t access the database.")
        mock_session = mock.Mock()
        Persistence(mock_session)
        mock_session.get_session.assert_called_with()

    def test_flush_db(self):
        with self.assertRaises(NotImplementedError):
            self.persistence._flush_db()

    @mock.patch("ocr.persistence.Persistence._flush_db")
    def test_add_db(self, mock_flush):
        p = Persistence()
        self.assertFalse(p.add_db())
        mock_session = mock.Mock()
        mock_sessionobj = mock.Mock()
        mock_sessionobj.get_session.return_value = mock_session
        p = Persistence(mock_sessionobj)
        self.assertTrue(p.add_db())
        mock_flush.assert_called_with()
        mock_session.add.assert_called_with(Base)
        mock_session.commit.assert_called_with()
        mock_session.add.side_effect = IntegrityError(1, 2, 3)
        self.assertFalse(p.add_db())
        mock_session.rollback.assert_called_with()

    def test_load(self):
        with self.assertRaises(NotImplementedError):
            self.persistence.load()

    @mock.patch("ocr.persistence.Persistence.add_db")
    def test_save(self, mock_add_db):
        self.persistence.save()
        mock_add_db.assert_called_with()
        mock_add_db.return_value = True
        self.assertTrue(self.persistence.save())
        mock_add_db.return_value = False
        self.assertFalse(self.persistence.save())

    def test_delete(self):
        with self.assertRaises(NotImplementedError):
            self.persistence.delete()

    def test_search(self):
        with self.assertRaises(NotImplementedError):
            self.persistence.search()
Exemplo n.º 6
0
 def setUp(self):
     mock_session = mock.Mock()
     mock_session.get_session.return_value = "session"
     self.persistence = Persistence(mock_session)
Exemplo n.º 7
0
class TestPersistence(unittest.TestCase):
    def setUp(self):
        mock_session = mock.Mock()
        mock_session.get_session.return_value = "session"
        self.persistence = Persistence(mock_session)

    @mock.patch("ocr.persistence.warning")
    def test___init__(self, mock_warning):
        Persistence()
        mock_warning.assert_called_with("This persistence can`t access the database.")
        mock_session = mock.Mock()
        Persistence(mock_session)
        mock_session.get_session.assert_called_with()

    def test_flush_db(self):
        with self.assertRaises(NotImplementedError):
            self.persistence._flush_db()

    @mock.patch("ocr.persistence.Persistence._flush_db")
    def test_add_db(self, mock_flush):
        p = Persistence()
        self.assertFalse(p.add_db())
        mock_session = mock.Mock()
        mock_sessionobj = mock.Mock()
        mock_sessionobj.get_session.return_value = mock_session
        p = Persistence(mock_sessionobj)
        self.assertTrue(p.add_db())
        mock_flush.assert_called_with()
        mock_session.add.assert_called_with(Base)
        mock_session.commit.assert_called_with()
        mock_session.add.side_effect = IntegrityError(1, 2, 3)
        self.assertFalse(p.add_db())
        mock_session.rollback.assert_called_with()

    def test_load(self):
        with self.assertRaises(NotImplementedError):
            self.persistence.load()

    @mock.patch("ocr.persistence.Persistence.add_db")
    def test_save(self, mock_add_db):
        self.persistence.save()
        mock_add_db.assert_called_with()
        mock_add_db.return_value = True
        self.assertTrue(self.persistence.save())
        mock_add_db.return_value = False
        self.assertFalse(self.persistence.save())

    def test_delete(self):
        with self.assertRaises(NotImplementedError):
            self.persistence.delete()

    def test_search(self):
        with self.assertRaises(NotImplementedError):
            self.persistence.search()