Beispiel #1
0
    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.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 = Package(name=self.package)
            self.publisher.packages.append(metadata)
            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_name,
                                        'secret': 'super_secret'
                                    }),
                                    content_type='application/json')
        data = json.loads(response.data)
        self.jwt = data['token']
        self.auth = "bearer %s" % self.jwt
Beispiel #2
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")
Beispiel #3
0
def create_test_package(publisher='demo', package='demo-package', descriptor={}, readme=''):
    user = User(name=publisher, secret='supersecret', email='*****@*****.**')
    publisher = Publisher(name=publisher)
    association = PublisherUser(role=UserRoleEnum.owner)
    association.publisher = publisher
    user.publishers.append(association)

    package = Package(name=package, descriptor=descriptor, readme=readme)
    publisher.packages.append(package)

    db.session.add(user)
    db.session.commit()
Beispiel #4
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 = Package(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 = Package(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 = "%s" % self.jwt
Beispiel #5
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()
Beispiel #6
0
def create_test_package(publisher='demo',
                        package='demo-package',
                        descriptor={}):

    user = User(name=publisher)
    publisher = Publisher(name=publisher)
    association = PublisherUser(role=UserRoleEnum.owner)
    association.publisher = publisher
    user.publishers.append(association)

    metadata = Package(name=package)
    tag = PackageTag(descriptor=descriptor)
    metadata.tags.append(tag)
    publisher.packages.append(metadata)

    db.session.add(user)
    db.session.commit()
Beispiel #7
0
    def setUp(self):
        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='test_user_id',
                        secret='supersecret',
                        auth0_id="123|auth0")
            publisher = Publisher(name='test_pub_id')
            association = PublisherUser(role=UserRoleEnum.owner)
            association.publisher = publisher
            user.publishers.append(association)

            db.session.add(user)
            db.session.commit()
Beispiel #8
0
    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.id = 1
            self.user.email, self.user.name, self.user.secret = \
                '*****@*****.**', self.publisher, 'super_secret'

            self.publisherObj = Publisher(name=self.publisher)

            association = PublisherUser(role=UserRoleEnum.owner)
            association.publisher = self.publisherObj
            self.user.publishers.append(association)

            db.session.add(self.user)
            db.session.commit()
Beispiel #9
0
def populate_db(auth0_id, email, user_name, full_name, secret):
    user = User.query.filter_by(name=user_name).first()

    publisher = Publisher.query.filter_by(name=user_name).first()
    if user is None:
        user = User()
        user.auth0_id, user.email, user.name, user.full_name, user.secret \
            = auth0_id, email, user_name, full_name, secret
        db.session.add(user)
        db.session.commit()

    if publisher is None:

        publisher = Publisher(name=user_name)

        association = PublisherUser(role=UserRoleEnum.owner)
        association.publisher = publisher
        user.publishers.append(association)

        db.session.add(user)
        db.session.commit()
Beispiel #10
0
    def setup_class(self):
        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.app = create_app()
        self.app.app_context().push()

        with self.app.test_request_context():
            db.drop_all()
            db.create_all()

            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)

            db.session.add(user1)
            db.session.add(user2)
            db.session.commit()
Beispiel #11
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()
    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 = 1
            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 = Package(name=self.package)
            self.publisher.packages.append(metadata)
            self.user.publishers.append(association)

            db.session.add(self.user)
            db.session.commit()
    def setUp(self):
        self.app = create_app()
        self.app.app_context().push()
        with self.app.test_request_context():
            db.drop_all()
            db.create_all()

            self.user = User(id=11,
                             name=self.user_name,
                             secret='supersecret',
                             auth0_id="123|auth0")

            self.publisher = Publisher(name=self.user_name)
            self.publisher.packages.append(Package(name='test_package'))

            association = PublisherUser(role=UserRoleEnum.owner)
            association.publisher = self.publisher

            self.user.publishers.append(association)

            self.publisher1 = Publisher(name="test_publisher")
            self.publisher1.packages.append(Package(name='test_package'))

            association1 = PublisherUser(role=UserRoleEnum.member)
            association1.publisher = self.publisher1

            self.user.publishers.append(association1)

            db.session.add(self.user)

            self.sysadmin = User(id=12, name='admin', sysadmin=True)
            db.session.add(self.sysadmin)

            self.random_user = User(id=13, name='random')
            db.session.add(self.random_user)

            self.publisher2 = Publisher(name="test_publisher1", private=True)
            self.publisher2.packages.append(
                Package(name='test_package', private=True))
            db.session.add(self.publisher2)

            self.publisher3 = Publisher(name="test_publisher2", private=False)
            self.publisher3.packages.append(Package(name='test_package'))
            db.session.add(self.publisher3)

            db.session.commit()
    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)

            self.user1 = User()
            self.user1.id = self.user_id1
            self.user1.email, self.user1.name, self.user1.secret = \
                '*****@*****.**', self.publisher1, 'super_secret'
            publisher1 = Publisher(name=self.publisher1)
            association1 = PublisherUser(role=UserRoleEnum.owner)
            association1.publisher = publisher1
            self.user.publishers.append(association1)

            db.session.add(self.user)
            db.session.add(self.user1)
            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']

        response = self.client.post(self.jwt_url,
                                    data=json.dumps({
                                        'username': self.publisher1,
                                        'secret': 'super_secret'
                                    }),
                                    content_type='application/json')
        data = json.loads(response.data)
        self.jwt1 = data['token']
Beispiel #15
0
    def setUp(self):
        self.publisher_one = 'test_publisher1'
        self.publisher_two = 'test_publisher2'
        self.package_one = 'test_package1'
        self.package_two = 'test_package2'
        self.app = create_app()
        self.app.app_context().push()

        with self.app.test_request_context():
            db.drop_all()
            db.create_all()

            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)
            metadata1.descriptor = json.dumps(dict(name='test_one'))
            publisher1.packages.append(metadata1)

            metadata2 = Package(name=self.package_two)
            metadata2.descriptor = json.dumps(dict(name='test_two'))
            publisher1.packages.append(metadata2)

            metadata3 = Package(name=self.package_one)
            metadata3.descriptor = json.dumps(dict(name='test_three'))
            publisher2.packages.append(metadata3)

            metadata4 = Package(name=self.package_two)
            metadata4.descriptor = json.dumps(dict(name='test_four'))
            publisher2.packages.append(metadata4)

            db.session.add(user1)
            db.session.add(user2)

            db.session.commit()
Beispiel #16
0
def make_fixtures(app, package, publisher, user_id):
    with app.app_context():
        user = User(
                id=user_id,
                email='*****@*****.**',
                name=publisher,
                secret='super_secret'
                )
        pub = Publisher(name=publisher)
        pub.packages.append(Package(name=package))
        association = PublisherUser(role=UserRoleEnum.owner)
        association.publisher = pub
        user.publishers.append(association)

        user1 = User(id=2, name='test1',
                     secret='super_secret1', email="*****@*****.**")
        pub1 = Publisher(name='test1')
        association1 = PublisherUser(role=UserRoleEnum.owner)
        association1.publisher = pub1
        user1.publishers.append(association1)

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