Пример #1
0
    def test_serialize(self):

        a_0 = ef.account()
        a_1 = ef.account()
        ci_0 = ef.catalogue_item(maintained_by=a_0)
        ci_1 = ef.catalogue_item(maintained_by=a_1)

        assert CatalogueItemListSerializer({
            'items': [ci_0, ci_1]
        }).data == {
            '@type':
            'catalogue_items_list',
            'items': [
                CatalogueItemSerializer(ci_0).data,
                CatalogueItemSerializer(ci_1).data,
            ],
        }
Пример #2
0
    def test_get_200__with_has_samples(self):

        ci_0 = ef.catalogue_item(name='iot_features', sample=[])
        ci_1 = ef.catalogue_item(name='temperatures',
                                 sample=[
                                     {
                                         'location': 'Wroclaw',
                                         'value': 12.1
                                     },
                                     {
                                         'location': 'Olawa',
                                         'value': 34.4
                                     },
                                 ])
        ci_2 = ef.catalogue_item(name='iot_events', sample=[])

        # -- with samples
        response = self.app.get(self.uri,
                                data={'has_samples': True},
                                **self.headers)

        assert response.status_code == 200
        assert response.json() == {
            '@event': 'CATALOGUEITEMS_BULK_READ',
            '@type': 'catalogue_items_list',
            'items': [
                CatalogueItemSerializer(ci_1).data,
            ],
        }

        # -- without samples
        response = self.app.get(self.uri,
                                data={'has_samples': False},
                                **self.headers)

        assert response.status_code == 200
        assert response.json() == {
            '@event':
            'CATALOGUEITEMS_BULK_READ',
            '@type':
            'catalogue_items_list',
            'items': [
                CatalogueItemSerializer(ci_0).data,
                CatalogueItemSerializer(ci_2).data,
            ],
        }
Пример #3
0
    def test_get_200(self):

        ci_0 = ef.catalogue_item(name='iot_features')
        ci_1 = ef.catalogue_item(name='iot_events')
        ci_2 = ef.catalogue_item(name='temperatures')

        response = self.app.get(self.uri, **self.headers)

        assert response.status_code == 200
        assert response.json() == {
            '@event':
            'CATALOGUEITEMS_BULK_READ',
            '@type':
            'catalogue_items_list',
            'items': [
                CatalogueItemSerializer(ci_0).data,
                CatalogueItemSerializer(ci_1).data,
                CatalogueItemSerializer(ci_2).data,
            ],
        }
Пример #4
0
    def test_get_200__query_many_words_or_not(self):

        ci_0 = ef.catalogue_item(name='iot_features')  # noqa
        ci_1 = ef.catalogue_item(name='temperatures')  # noqa
        ci_2 = ef.catalogue_item(name='iot_events')

        response = self.app.get(self.uri,
                                data={'query': 'IOT ~features | temp'},
                                **self.headers)

        assert response.status_code == 200
        assert response.json() == {
            '@event':
            'CATALOGUEITEMS_BULK_READ',
            '@type':
            'catalogue_items_list',
            'items': [
                CatalogueItemSerializer(ci_1).data,
                CatalogueItemSerializer(ci_2).data,
            ],
        }
Пример #5
0
    def test_get_200(self):

        ci_0 = ef.catalogue_item(name='temperatures')
        # -- noise
        ci_1 = ef.catalogue_item(name='iot_features')  # noqa

        response = self.app.get(self.get_uri(ci_0.id), **self.headers)

        assert response.status_code == 200
        assert response.json() == {
            '@event': 'CATALOGUEITEM_READ',
            **CatalogueItemSerializer(ci_0).data,
        }
Пример #6
0
    def test_put_200(self):

        a_0 = ef.account()
        a_1 = ef.account()
        ci = ef.catalogue_item(name='temperatures',
                               created_by=a_1,
                               updated_by=a_1)

        response = self.app.put(self.get_uri(ci.id),
                                data=json.dumps({
                                    'sample': [],
                                    'spec': [
                                        {
                                            'name': 'value',
                                            'type': 'FLOAT',
                                            'size': 19203,
                                            'is_nullable': False,
                                            'is_enum': False,
                                            'distribution': None,
                                        },
                                    ],
                                    'maintained_by_id':
                                    a_0.id,
                                    'executor_type':
                                    'DATABRICKS',
                                }),
                                content_type='application/json',
                                **self.headers)

        assert response.status_code == 200
        ci.refresh_from_db()
        assert response.json() == {
            '@event': 'CATALOGUEITEM_UPDATED',
            **CatalogueItemSerializer(ci).data
        }
        assert ci.name == 'temperatures'
        assert ci.spec == [
            {
                'name': 'value',
                'type': 'FLOAT',
                'size': 19203,
                'is_nullable': False,
                'is_enum': False,
                'distribution': None,
            },
        ]
        assert ci.maintained_by == a_0
        assert ci.created_by == a_1
        assert ci.updated_by == self.account
        assert ci.executor_type == 'DATABRICKS'
Пример #7
0
    def test_serialize(self):

        a_0 = ef.account()
        a_1 = ef.account()

        ci = ef.catalogue_item(name='names',
                               created_by=a_0,
                               maintained_by=a_1,
                               spec=[{
                                   'name': 'name',
                                   'type': 'STRING',
                                   'is_nullable': False,
                                   'is_enum': False,
                                   'size': None,
                                   'distribution': None,
                               }],
                               sample=[{
                                   'name': 'Jack'
                               }],
                               executor_type='ATHENA')

        assert CatalogueItemSerializer(ci).data == {
            '@type':
            'catalogue_item',
            'id':
            ci.id,
            'created_by':
            AccountSerializer(a_0).data,
            'updated_by':
            None,
            'maintained_by':
            AccountSerializer(a_1).data,
            'name':
            'names',
            'spec': [
                {
                    'name': 'name',
                    'type': 'STRING',
                    'is_nullable': False,
                    'is_enum': False,
                    'size': None,
                    'distribution': None,
                },
            ],
            'sample': [{
                'name': 'Jack'
            }],
            'executor_type':
            'ATHENA',
        }
Пример #8
0
    def test_post_201(self):

        a = ef.account()

        assert CatalogueItem.objects.all().count() == 0

        response = self.app.post(self.uri,
                                 data=json.dumps({
                                     'name':
                                     'iot_events',
                                     'sample': [],
                                     'spec': [
                                         {
                                             'name': 'value',
                                             'type': 'FLOAT',
                                             'size': 19203,
                                             'is_nullable': False,
                                             'is_enum': False,
                                             'distribution': None,
                                         },
                                     ],
                                     'maintained_by_id':
                                     a.id,
                                     'executor_type':
                                     'DATABRICKS',
                                 }),
                                 content_type='application/json',
                                 **self.headers)

        assert response.status_code == 201
        assert CatalogueItem.objects.all().count() == 1
        ci = CatalogueItem.objects.all().first()

        assert response.json() == {
            '@event': 'CATALOGUEITEM_CREATED',
            **CatalogueItemSerializer(ci).data,
        }
        assert ci.created_by == self.account
        assert ci.updated_by == self.account
Пример #9
0
class DownloadRequestSerializer(serializers.ModelSerializer):

    _type = 'download_request'

    created_by = AccountSerializer()

    catalogue_item = CatalogueItemSerializer()

    class Meta:
        model = DownloadRequest

        fields = (
            # -- model fields
            'spec',
            'download_uri',
            'blob_name',
            'real_size',
            'estimated_size',
            'executor_job_id',
            'catalogue_item',
            'created_by',
            'is_cancelled',
        )
Пример #10
0
    def test_serialize(self):

        a = ef.account()
        ci = ef.catalogue_item(spec=[
            {
                'name': 'product',
                'type': 'STRING',
                'is_nullable': True,
                'is_enum': True,
                'size': None,
                'distribution': None,
            },
            {
                'name': 'price',
                'type': 'INTEGER',
                'is_nullable': False,
                'is_enum': False,
                'size': None,
                'distribution': None,
            },
        ])

        r = ef.download_request(created_by=a,
                                spec={
                                    'columns': ['product'],
                                    'filters': [
                                        {
                                            'name': 'price',
                                            'operator': '>=',
                                            'value': 120,
                                        },
                                    ],
                                    'randomize_ratio':
                                    0.9,
                                },
                                blob_name=None,
                                real_size=1829,
                                estimated_size=1933,
                                catalogue_item=ci,
                                executor_job_id='fd90-fd89')

        assert DownloadRequestSerializer(r).data == {
            '@type': 'download_request',
            'created_by': AccountSerializer(a).data,
            'spec': {
                'columns': ['product'],
                'filters': [
                    {
                        'name': 'price',
                        'operator': '>=',
                        'value': 120,
                    },
                ],
                'randomize_ratio': 0.9,
            },
            'blob_name': None,
            'download_uri': None,
            'real_size': 1829,
            'estimated_size': 1933,
            'catalogue_item': CatalogueItemSerializer(ci).data,
            'executor_job_id': 'fd90-fd89',
            'is_cancelled': False,
        }