def test_create_store_store(self, mock_create): testItem = { 'source': 'testing', 'links': [{ 'url': 'other.org/records/1' }] } mock_inst = MagicMock() record = Item.createOrStore('session', testItem, mock_inst) self.assertEqual(record, 'test_item')
def test_create_store_create(self, mock_upsert, mock_create): testItem = { 'source': 'testing', 'links': [{ 'url': 'gutenberg.org/ebooks/1.epub.images' }, { 'url': None }] } mock_inst = MagicMock() mock_inst.id = None mock_session = MagicMock() record = Item.createOrStore(mock_session, testItem, mock_inst) self.assertEqual(record, None) mock_session.add.assert_called_once() mock_session.flush.assert_called_once() mock_create.assert_called_once() mock_upsert.assert_not_called()