Пример #1
0
 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']
Пример #2
0
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()
Пример #3
0
    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()
Пример #4
0
    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()
Пример #5
0
 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)
Пример #6
0
 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")
Пример #7
0
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()
Пример #8
0
 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
Пример #9
0
 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()
Пример #10
0
def db(app):
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    _db.drop_all()
Пример #11
0
    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
Пример #12
0
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()
Пример #13
0
 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)
Пример #14
0
def db(app):
    _db.app = app

    with app.app_context():
        _db.create_all()

    yield _db

    _db.session.close()
    _db.drop_all()
Пример #15
0
 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')
Пример #17
0
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()
Пример #18
0
    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)
Пример #19
0
def database():
    db.create_all()

    user1 = User(email='*****@*****.**', password='******')

    db.session.add(user1)
    db.session.commit()

    yield db

    db.drop_all()
Пример #20
0
 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'
Пример #21
0
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()
Пример #22
0
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()
Пример #23
0
    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)
Пример #24
0
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 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()
Пример #26
0
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()
Пример #27
0
    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)
Пример #28
0
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()
Пример #29
0
    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()
Пример #30
0
 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()
Пример #31
0
 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'), '')
Пример #32
0
 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, [])
Пример #33
0
def drop_db():
    """Drops database tables."""
    if prompt_bool('Are you sure?'):
        db.drop_all()
Пример #34
0
 def create_app(self):
     app = create_app('config.TestConfig')
     with app.app_context():
         db.drop_all()
         db.create_all()
     return app
Пример #35
0
 def tearDown(self):
     db.reflect()
     db.drop_all()
     db.session.remove()
Пример #36
0
def dropdb():
    db.init_app(current_app)
    db.drop_all()
Пример #37
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
Пример #38
0
def drop_db():
    """Drops the database."""
    if click.confirm('Are you sure?', abort=True):
        db.drop_all()
Пример #39
0
def drop_db():
    db.drop_all()