def setUp(self): self.app = create_app() # self.app.app_context().push() self.client = self.app.test_client() with self.app.app_context(): db.drop_all() db.create_all() self.user = User() self.user.id = self.user_id self.user.email, self.user.name, self.user.secret = \ '*****@*****.**', self.publisher, 'super_secret' publisher = Publisher(name=self.publisher) association = PublisherUser(role=UserRoleEnum.owner) publisher.packages.append(Package(name=self.package)) association.publisher = publisher self.user.publishers.append(association) db.session.add(self.user) db.session.commit() response = self.client.post(self.jwt_url, data=json.dumps({ 'username': self.publisher, 'secret': 'super_secret' }), content_type='application/json') data = json.loads(response.data) self.jwt = data['token']
def make_db(num_users=5): db.drop_all() db.create_all() users = [ User( admin_username, admin_email, admin_password, fake.ipv4(), active=True, is_admin=True ) ] for _ in range(num_users): u = User( fake.userName(), fake.email(), fake.word() + fake.word(), fake.ipv4() ) users.append(u) [db.session.add(x) for x in users] db.session.commit()
def tearDown(self): """Metodo que se ejecutal al final ddel test para deconstruir el aparato de prueba después de probarlo.""" db.session.remove() db.drop_all() self.app_context.pop()
def setUp(self): self.publisher = 'demo' self.package = 'demo-package' self.publisher_one = 'test_publisher1' self.publisher_two = 'test_publisher2' self.package_one = 'test_package1' self.package_two = 'test_package2' self.package_three = 'test_package3' self.descriptor = json.loads(open('fixtures/datapackage.json').read()) self.app = create_app() self.app.app_context().push() with self.app.test_request_context(): db.drop_all() db.create_all() create_test_package(self.publisher, self.package, self.descriptor) user1 = User(name=self.publisher_one) publisher1 = Publisher(name=self.publisher_one) association1 = PublisherUser(role=UserRoleEnum.owner) association1.publisher = publisher1 user1.publishers.append(association1) user2 = User(name=self.publisher_two) publisher2 = Publisher(name=self.publisher_two) association2 = PublisherUser(role=UserRoleEnum.owner) association2.publisher = publisher2 user2.publishers.append(association2) metadata1 = Package(name=self.package_one) tag1 = PackageTag(descriptor=dict(name='test_one')) metadata1.tags.append(tag1) publisher1.packages.append(metadata1) metadata2 = Package(name=self.package_two) tag2 = PackageTag(descriptor=dict(name='test_two')) metadata2.tags.append(tag2) publisher1.packages.append(metadata2) metadata3 = Package(name=self.package_one) tag3 = PackageTag(descriptor=dict(name='test_three')) metadata3.tags.append(tag3) publisher2.packages.append(metadata3) metadata4 = Package(name=self.package_two) tag4 = PackageTag(descriptor=dict(name='test_four')) metadata4.tags.append(tag4) publisher2.packages.append(metadata4) metadata5 = Package(name=self.package_three) tag5 = PackageTag(descriptor=dict(name='test_four')) metadata5.tags.append(tag5) publisher2.packages.append(metadata5) db.session.add(user1) db.session.add(user2) db.session.commit()
def setup_class(self): self.app = create_app() self.client = self.app.test_client() with self.app.app_context(): db.drop_all() db.create_all() base.make_fixtures(self.app, self.package, self.publisher, self.user_id)
def test_throw_error_if_role_is_invalid(self): with self.app.test_request_context(): db.drop_all() db.create_all() publisher = Publisher(name='test_pub_id') association = PublisherUser() association.publisher = publisher self.assertRaises(ValueError, association.role, "NOT_MEMBER")
def _reset_db(): from flask_migrate import upgrade, stamp db.drop_all() db.engine.execute('DROP TABLE IF EXISTS alembic_version;') db.create_all() stamp() upgrade()
def setUpClass(cls): """Run once at the start""" app = create_app(test_config) db.app = app # hack for using db.init_app(app) in app/__init__.py db.drop_all() db.create_all() populate_db() cls.app = app
def setUp(self): self.publisher = 'test_publisher' self.package = 'test_package' self.app = create_app() self.client = self.app.test_client() with self.app.app_context(): db.drop_all() db.create_all()
def db(app): _db.app = app with app.app_context(): _db.create_all() yield _db _db.drop_all()
def setUp(self): self.app = create_app() self.client = self.app.test_client() with self.app.app_context(): self.bucket_name = self.app.config['S3_BUCKET_NAME'] db.drop_all() db.create_all() self.user = User() self.user.id = self.user_id self.user.email, self.user.name, self.user.secret = \ '*****@*****.**', self.publisher_name, 'super_secret' self.publisher = Publisher(name=self.publisher_name) association = PublisherUser(role=UserRoleEnum.owner) association.publisher = self.publisher metadata = MetaDataDB(name=self.package) self.publisher.packages.append(metadata) self.user.publishers.append(association) self.user_not_allowed = User() self.user_not_allowed.id = self.user_not_allowed_id self.user_not_allowed.email, self.user_not_allowed.name, \ self.user_not_allowed.secret = \ '*****@*****.**', self.user_not_allowed_name, 'super_secret' self.publisher_not_allowed = Publisher( name=self.user_not_allowed_name) association_not_allowed = PublisherUser(role=UserRoleEnum.owner) association_not_allowed.publisher = self.publisher_not_allowed metadata = MetaDataDB(name=self.package) self.publisher_not_allowed.packages.append(metadata) self.user_not_allowed.publishers.append(association_not_allowed) self.user_member = User() self.user_member.id = self.user_member_id self.user_member.email, self.user_member.name, self.user_member.secret = \ '*****@*****.**', self.user_member_name, 'super_secret' association_member = PublisherUser(role=UserRoleEnum.member) association_member.publisher = self.publisher self.user_member.publishers.append(association_member) db.session.add(self.user) db.session.add(self.user_not_allowed) db.session.commit() response = self.client.post(self.jwt_url, data=json.dumps({ 'username': self.publisher_name, 'secret': 'super_secret' }), content_type='application/json') data = json.loads(response.data) self.jwt = data['token'] self.auth = "bearer %s" % self.jwt
def flask_app(): app = create_app(environment='testing') from app.database import db with app.app_context(): db.create_all() yield app db.session.close_all() db.drop_all()
def test_throw_404_if_user_not_exists(self): with self.app.app_context(): db.drop_all() db.create_all() auth = "bearer %s" % self.jwt response = self.client.post(self.url, data=json.dumps(dict()), headers=dict(Authorization=auth)) self.assertEqual(404, response.status_code)
def db(app): _db.app = app with app.app_context(): _db.create_all() yield _db _db.session.close() _db.drop_all()
def setUp(self): self.user = '******' self.email = 'email' self.full_name = 'Demo' self.app = create_app() self.app.app_context().push() with self.app.test_request_context(): db.drop_all() db.create_all() db.session.commit()
def setUp(self): self.app = create_app() self.client = self.app.test_client() with self.app.app_context(): db.drop_all() db.create_all() base.make_fixtures(self.app, self.package, self.publisher, self.user_id) self.jwt = base.get_valid_token(self.publisher) self.jwt1 = base.get_valid_token('test1')
def client(): with app.test_client() as client: app_ctx = app.app_context() app_ctx.push() db.drop_all() db.create_all() yield client db.session.remove() db.drop_all() app_ctx.pop()
def setUp(self): self.publisher = 'demo' self.package = 'demo-package' self.app = create_app() self.app.app_context().push() self.descriptor = json.loads(open('fixtures/datapackage.json').read()) with self.app.test_request_context(): db.drop_all() db.create_all() create_test_package(self.publisher, self.package, self.descriptor)
def database(): db.create_all() user1 = User(email='*****@*****.**', password='******') db.session.add(user1) db.session.commit() yield db db.drop_all()
def setUp(self): self.app = app.test_client() with app.app_context(): db.session.close() db.drop_all() db.create_all() setup_db(db.session) app.config['MONTRACKER_SERVER_ADDR'] = 'http://127.0.0.1:10000' app.config['MONTRACKER_SERVER_API_VERSION'] = 'v1' app.config['ARCGIS_PATH_PREFIX'] = 'http://127.0.0.1:11000' app.config['ARCGIS_PATH_SUFFIX'] = '/maps'
def client(): with app.test_client() as client: app_ctx = app.app_context() app_ctx.push() db.drop_all() db.create_all() db_fill_data(import_values=False) yield client db.session.remove() db.drop_all() app_ctx.pop()
def db(app): """A database for the tests.""" _db.app = app with app.app_context(): _db.create_all() yield _db # Explicitly close DB connection _db.session.close() _db.drop_all()
def test_return_404_if_user_not_found(self, save): with self.app.app_context(): db.drop_all() db.create_all() save.return_value = None auth = "bearer %s" % self.jwt response = self.client.put(self.url, headers=dict(Authorization=auth), data=json.dumps({'name': 'package'})) self.assertEqual(404, response.status_code)
def setUp(self): self.app = create_app() self.client = self.app.test_client() with self.app.app_context(): db.drop_all() db.create_all() self.user = User() self.user.user_id = 'trial_id' self.user.email, self.user.name, self.user.secret = \ '*****@*****.**', 'test_user', 'super_secret' db.session.add(self.user) db.session.commit()
def client(): with app.test_client() as client: app_ctx = app.app_context() app_ctx.push() db.drop_all() db.create_all() db_fill_data() register(client) login(client) yield client db.session.remove() db.drop_all() app_ctx.pop()
def setUp(self): self.publisher = 'demo' self.package = 'demo-package' self.app = create_app() self.app.app_context().push() self.descriptor = json.loads(open('fixtures/datapackage.json').read()) self.datapackage_url = 'https://bits.datapackaged.com/metadata/' \ '{pub}/{pack}/_v/latest/datapackage.com'.\ format(pub=self.publisher, pack=self.package) with self.app.test_request_context(): db.drop_all() db.create_all() create_test_package(self.publisher, self.package, self.descriptor)
def db(app, postgres_db): _db.app = app if app.config['SQLALCHEMY_DATABASE_URI'] is None: app.config['SQLALCHEMY_DATABASE_URI'] = postgres_db.url with app.app_context(): _db.create_all() yield _db # Explicitly close DB connection _db.session.close() _db.drop_all()
def setUp(self): self.publisher = 'demo' self.package = 'demo-package' self.app = create_app() self.app.app_context().push() with self.app.test_request_context(): db.drop_all() db.create_all() user = User(id=11, name=self.publisher, secret='supersecret') publisher = Publisher(name=self.publisher) association = PublisherUser(role=UserRoleEnum.owner) association.publisher = publisher user.publishers.append(association) db.session.add(user) db.session.commit()
def setUp(self): self.publisher = 'test_publisher' self.package1 = 'test_package1' self.package2 = 'test_package2' self.app = create_app() self.client = self.app.test_client() with self.app.app_context(): db.drop_all() db.create_all() publisher = Publisher(name=self.publisher) metadata1 = MetaDataDB(name=self.package1) metadata2 = MetaDataDB(name=self.package2) publisher.packages.append(metadata1) publisher.packages.append(metadata2) db.session.add(publisher) db.session.commit()
def test_adds_empty_readme_if_there_is_not(self): descriptor = {'name': 'test', 'resources': []} with self.app.app_context(): db.drop_all() db.create_all() publisher = Publisher(name=self.publisher) metadata = Package(name=self.package) metadata.descriptor = json.dumps(descriptor) publisher.packages.append(metadata) db.session.add(publisher) db.session.commit() response = self.client.get('/api/package/%s/%s'%\ (self.publisher, self.package)) catalog = Catalog(json.loads(response.data)) dataset = catalog.construct_dataset() self.assertEqual(dataset.get('readme'), '')
def test_get_views_if_views_dont_exist(self): descriptor = {'name': 'test', 'resources': []} with self.app.app_context(): db.drop_all() db.create_all() publisher = Publisher(name=self.publisher) metadata = Package(name=self.package) metadata.descriptor = json.dumps(descriptor) publisher.packages.append(metadata) db.session.add(publisher) db.session.commit() response = self.client.get('/api/package/%s/%s'%\ (self.publisher, self.package)) catalog = Catalog(json.loads(response.data)) views = catalog.get_views() self.assertEqual(views, [])
def drop_db(): """Drops database tables.""" if prompt_bool('Are you sure?'): db.drop_all()
def create_app(self): app = create_app('config.TestConfig') with app.app_context(): db.drop_all() db.create_all() return app
def tearDown(self): db.reflect() db.drop_all() db.session.remove()
def dropdb(): db.init_app(current_app) db.drop_all()
def tearDown(self): db.session.remove() db.drop_all() self.app_context.pop()
def drop_db(): """Drops the database.""" if click.confirm('Are you sure?', abort=True): db.drop_all()
def drop_db(): db.drop_all()