コード例 #1
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()
コード例 #2
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()
コード例 #3
0
    def test_should_update_data_package_if_preexists(self):
        with self.app.test_request_context():
            pub = Publisher.query.filter_by(name=self.publisher_one).one()
            package = Package.query.join(Publisher)\
                .filter(Publisher.name == self.publisher_one,
                        Package.name == self.package_two)\
                .one()
            package.tags.append(PackageTag(tag='tag_one', readme='old_readme'))
            pub.packages.append(package)
            db.session.add(pub)
            db.session.commit()

        package = Package.query.join(Publisher) \
            .filter(Publisher.name == self.publisher_one,
                    Package.name == self.package_two).one()

        latest_data = PackageTag.query.join(Package) \
            .filter(Package.id == package.id,
                    PackageTag.tag == 'latest').one()

        tagged_data = PackageTag.query.join(Package) \
            .filter(Package.id == package.id,
                    PackageTag.tag == 'tag_one').one()

        self.assertNotEqual(latest_data.readme, tagged_data.readme)

        logic.Package.create_or_update_tag(self.publisher_one,
                                           self.package_two, 'tag_one')
        tagged_data = PackageTag.query.join(Package) \
            .filter(Package.id == package.id,
                    PackageTag.tag == 'tag_one').one()

        self.assertEqual(latest_data.readme, tagged_data.readme)
コード例 #4
0
ファイル: test_controller.py プロジェクト: Mikanebu/dpr-api
 def test_home_shows_packages(self):
     descriptor = json.loads(open('fixtures/datapackage.json').read())
     with self.app.app_context():
         publisher = Publisher(name='core')
         metadata = Package(name='gold-prices')
         metadata.tags.append(PackageTag(descriptor=descriptor))
         publisher.packages.append(metadata)
         db.session.add(publisher)
         db.session.commit()
     rv = self.client.get('/')
     self.assertEqual(rv.status_code, 200)
     self.assertTrue('DEMO - CBOE Volatility Index' in rv.data)
コード例 #5
0
ファイル: test_controller.py プロジェクト: Mikanebu/dpr-api
 def test_data_package_page_loads_if_descriptor_has_bad_licenses(self):
     descriptor = json.loads(open('fixtures/datapackage.json').read())
     descriptor['licenses'] = {'url': 'test/url', 'type': 'Test'}
     with self.app.app_context():
         publisher = Publisher(name=self.publisher)
         metadata = Package(name=self.package)
         metadata.tags.append(PackageTag(descriptor=descriptor))
         publisher.packages.append(metadata)
         db.session.add(publisher)
         db.session.commit()
     rv = self.client.get('/%s/%s' %(self.publisher,self.package))
     self.assertEqual(200, rv.status_code)
コード例 #6
0
 def test_should_not_visible_after_soft_delete(self):
     descriptor = {'name': 'test description'}
     with self.app.app_context():
         publisher = Publisher(name=self.publisher)
         metadata = Package(name=self.package)
         metadata.tags.append(PackageTag(descriptor=descriptor))
         publisher.packages.append(metadata)
         db.session.add(publisher)
         db.session.commit()
         logic.Package.delete(self.publisher, self.package)
     response = self.client. \
         get('/api/package/%s/%s' % (self.publisher, self.package))
     self.assertEqual(response.status_code, 404)
コード例 #7
0
 def test_return_200_if_meta_data_found(self):
     descriptor = {'name': 'test description'}
     with self.app.app_context():
         publisher = Publisher(name=self.publisher)
         metadata = Package(name=self.package)
         metadata.tags.append(PackageTag(descriptor=descriptor))
         publisher.packages.append(metadata)
         db.session.add(publisher)
         db.session.commit()
     response = self.client.\
         get('/api/package/%s/%s' % (self.publisher, self.package))
     data = json.loads(response.data)
     self.assertEqual(response.status_code, 200)
コード例 #8
0
 def test_return_empty_string_if_readme_not_there(self):
     descriptor = {'name': 'test description'}
     with self.app.app_context():
         publisher = Publisher(name=self.publisher)
         metadata = Package(name=self.package)
         metadata.tags.append(PackageTag(descriptor=descriptor))
         metadata.descriptor = descriptor
         publisher.packages.append(metadata)
         db.session.add(publisher)
         db.session.commit()
     response = self.client.get('/api/package/%s/%s'%\
                                (self.publisher, self.package))
     data = json.loads(response.data)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(data['readme'], '')
コード例 #9
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()
コード例 #10
0
ファイル: test_controller.py プロジェクト: Mikanebu/dpr-api
    def test_data_package_page(self):
        descriptor = json.loads(open('fixtures/datapackage.json').read())
        with self.app.app_context():
            publisher = Publisher(name=self.publisher)
            metadata = Package(name=self.package)
            metadata.tags.append(PackageTag(descriptor=descriptor))
            publisher.packages.append(metadata)
            db.session.add(publisher)
            db.session.commit()
        rv = self.client.get('/{publisher}/{package}'.\
                             format(publisher=self.publisher,
                                    package=self.package))
        self.assertNotEqual(404, rv.status_code)
        self.assertIn('DOWNLOAD FILES', rv.data.decode("utf8"))

        rv = self.client.get('/non-existing/demo-package')
        self.assertEqual(404, rv.status_code)
コード例 #11
0
ファイル: test_controller.py プロジェクト: Mikanebu/dpr-api
    def setUp(self):
        self.publisher = 'demo'
        self.package = 'demo-package'
        self.app = create_app()
        self.client = self.app.test_client()
        with self.app.app_context():
            db.drop_all()
            db.create_all()
            descriptor = json.loads(open('fixtures/datapackage.json').read())
            readme = open('fixtures/README.md').read()
            publisher = Publisher(name=self.publisher)
            metadata = Package(name=self.package)
            metadata.tags.append(PackageTag(descriptor=descriptor, readme=readme))

            publisher.packages.append(metadata)
            db.session.add(publisher)
            db.session.commit()
コード例 #12
0
ファイル: test_controller.py プロジェクト: Mikanebu/dpr-api
    def test_data_package_page_load_without_views(self):
        descriptor = {"data": [], "resources": []}
        with self.app.app_context():
            publisher = Publisher(name=self.publisher)
            metadata = Package(name=self.package)
            metadata.tags.append(PackageTag(descriptor=descriptor))
            publisher.packages.append(metadata)
            db.session.add(publisher)
            db.session.commit()
        rv = self.client.get('/{publisher}/{package}'.\
                             format(publisher=self.publisher,
                                    package=self.package))
        self.assertNotEqual(404, rv.status_code)
        self.assertIn('DOWNLOAD FILES', rv.data.decode("utf8"))

        rv = self.client.get('/non-existing/demo-package')
        self.assertEqual(404, rv.status_code)
コード例 #13
0
    def test_should_return_20_result_if_limit_invalid(self):
        with self.app.test_request_context():
            pub = Publisher(name='big_publisher')
            for i in range(0, 30):
                pack = Package(name='pack{i}'.format(i=i))
                pack.tags.append(
                    PackageTag(descriptor={"title": "pack1 details one"},
                               readme="Big readme one"))
                pub.packages\
                    .append(pack)
            db.session.add(pub)
            db.session.commit()

        url = "/api/search/package?limit=lem"
        response = self.client.get(url)
        result = json.loads(response.data)
        self.assertEqual(200, response.status_code)
        # extra 6 packages from the setup so we expect 36 packages
        self.assertEqual(36, len(result['items']))
コード例 #14
0
 def test_return_all_metadata_is_there(self):
     descriptor = {'name': 'test description'}
     readme = 'README'
     with self.app.app_context():
         publisher = Publisher(name=self.publisher)
         metadata = Package(name=self.package)
         metadata.tags.append(
             PackageTag(descriptor=descriptor, readme=readme))
         publisher.packages.append(metadata)
         db.session.add(publisher)
         db.session.commit()
     response = self.client.get('/api/package/%s/%s'%\
                                (self.publisher, self.package))
     data = json.loads(response.data)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(data['descriptor']['name'], 'test description')
     self.assertEqual(data['readme'], '<p>README</p>')
     self.assertEqual(data['short_readme'], 'README')
     self.assertEqual(data['id'], 1)
     self.assertEqual(data['name'], self.package)
     self.assertEqual(data['publisher'], self.publisher)
コード例 #15
0
    def setUp(self):
        self.app = create_app()
        self.app.app_context().push()
        self.pub1_name = 'pub1'
        self.pub2_name = 'pub2'
        with self.app.test_request_context():
            db.drop_all()
            db.create_all()

            self.pub1 = Publisher(name=self.pub1_name)
            self.pub2 = Publisher(name=self.pub2_name)

            pack1 = Package(name='pack1')
            pack1.tags.append(
                PackageTag(descriptor={"title": "pack1 details one"},
                           readme="Big readme one"))
            self.pub1.packages.append(pack1)

            pack2 = Package(name='pack2')
            pack2.tags.append(
                PackageTag(descriptor={"title": "pack2 details two"},
                           readme="Big readme two"))
            self.pub1.packages.append(pack2)

            pack3 = Package(name='pack3')
            pack3.tags.append(
                PackageTag(descriptor={"title": "pack3 details three"}))
            self.pub1.packages.append(pack3)

            pack4 = Package(name='pack4')
            pack4.tags.append(
                PackageTag(descriptor={"title": "pack4 details four"}))
            self.pub2.packages.append(pack4)

            pack5 = Package(name='pack5')
            pack5.tags.append(
                PackageTag(descriptor={"title": "pack5 details five"}))
            self.pub2.packages.append(pack5)

            pack6 = Package(name='pack6')
            pack6.tags.append(
                PackageTag(descriptor={"title": "pack6 details six"}))
            self.pub2.packages.append(pack6)

            db.session.add(self.pub1)
            db.session.add(self.pub2)
            db.session.commit()