def test_raises_session_commit_exception(self): db = Database('sqlite://') # init engine and session db.session with patch.object(db._session, 'commit', Mock(side_effect=ValueError)): with self.assertRaises(ValueError): db.commit()
def test_commits_session(self): db = Database('sqlite://') # init engine and session db.session with patch.object(db._session, 'commit', Mock()) as fake_commit: db.commit() fake_commit.assert_called_once_with()
def test_table_basic(self): """Basic operations on datasets""" db = Database(self.dsn) db.open() ds = db.new_dataset(vid=self.dn[0], source='source', dataset='dataset') ds.new_table('table1') db.commit() t1 = db.dataset(ds.vid).table('table1') t1.add_column('col1', description='foobar') db.commit()
class ConvertSchemaTest(unittest.TestCase): """ tests _convert_schema function. """ def setUp(self): self.sqlite_db = Database('sqlite://') self.sqlite_db.create() def _test_converts_schema_to_resource_dict(self): DatasetFactory._meta.sqlalchemy_session = self.sqlite_db.session FileFactory._meta.sqlalchemy_session = self.sqlite_db.session ds1 = DatasetFactory() partition1 = PartitionFactory(dataset=ds1) self.sqlite_db.commit() partition1._datafile = MagicMock() ret = _convert_partition(partition1) self.assertIn('package_id', ret) self.assertEqual(ret['package_id'], ds1.vid) self.assertEqual(ret['name'], partition1.name)
class ConvertDatasetTest(unittest.TestCase): def setUp(self): self.sqlite_db = Database('sqlite://') self.sqlite_db.create() def test_converts_bundle_to_dict(self): DatasetFactory._meta.sqlalchemy_session = self.sqlite_db.session ds1 = DatasetFactory() bundle = _get_fake_bundle(ds1) self.sqlite_db.commit() ret = _convert_bundle(bundle) self.assertIn('name', ret) self.assertIsNotNone(ret['name']) self.assertEqual(ret['name'], ds1.vid) self.assertIn('title', ret) self.assertIsNotNone(ret['title']) self.assertEqual(ret['title'], ds1.config.metadata.about.title) self.assertIn('author', ret) self.assertIn('author_email', ret) self.assertIn('maintainer', ret) self.assertIn('maintainer_email', ret) def test_extends_notes_with_dataset_documentation(self): DatasetFactory._meta.sqlalchemy_session = self.sqlite_db.session FileFactory._meta.sqlalchemy_session = self.sqlite_db.session ds1 = DatasetFactory() FileFactory(dataset=ds1, path='documentation.md', contents='### Dataset documentation.') self.sqlite_db.commit() bundle = _get_fake_bundle(ds1) ret = _convert_bundle(bundle) self.assertIn('### Dataset documentation.', ret['notes'])