Beispiel #1
0
def resource_with_csv_file_converted_to_jsonld(csv2jsonld_csv_file, csv2jsonld_jsonld_file, params_str):
    from mcod.resources.models import Resource
    params = json.loads(params_str)
    obj_id = params.pop('id')
    if is_enabled('S40_new_file_model.be'):
        res = ResourceFactory(
            main_file__file=csv2jsonld_csv_file,
            id=obj_id,
            type='file',
            format='csv',
            link=None,
            **params,)
        ResourceFileFactory.create(
            file=csv2jsonld_jsonld_file,
            format='jsonld',
            resource=res,
            is_main=False
        )
        resource_score, files_score = res.get_openness_score()
        Resource.objects.filter(pk=res.pk).update(openness_score=resource_score)
        res = Resource.objects.get(pk=res.pk)
        res.revalidate()
    else:
        res = ResourceFactory.create(
            id=obj_id,
            type='file',
            format='csv',
            link=None,
            file=csv2jsonld_csv_file,
            jsonld_file=csv2jsonld_jsonld_file,
            **params,
        )
        res.openness_score = res.get_openness_score()
        res.save()
    return res
Beispiel #2
0
def datasets_with_resources_of_type(datasets_data):
    data = json.loads(datasets_data)
    for item in data:
        _dataset = DatasetFactory.create()
        for res_type, res_count in item.items():
            ResourceFactory.create_batch(res_count, dataset=_dataset, type=res_type)
    time.sleep(1)  # time to index data before request is made.
Beispiel #3
0
def showcase_with_id_and_datasets(showcase_id, num):
    showcase = ShowcaseFactory.create(
        id=showcase_id, title='showcase {} with datasets'.format(showcase_id))
    datasets = DatasetFactory.create_batch(num, showcases=(showcase, ))
    for dataset in datasets:
        ResourceFactory.create_batch(3, dataset=dataset)
    return showcase
Beispiel #4
0
def active_editor():
    usr = EditorFactory.create(email='*****@*****.**',
                               password='******',
                               phone='0048123456789')
    org = OrganizationFactory.create(users=(usr, ))
    ds = DatasetFactory.create(organization=org)
    ResourceFactory.create_batch(2, dataset=ds)
    return usr
Beispiel #5
0
def application_with_id_and_datasets(application_id, num):
    application = ApplicationFactory.create(
        id=application_id,
        title='application {} with datasets'.format(application_id))
    datasets = DatasetFactory.create_batch(num, applications=(application, ))
    for dataset in datasets:
        ResourceFactory.create_batch(3, dataset=dataset)
    return application
Beispiel #6
0
def dataset_with_resource_and_params(field_name, field_value):
    _dataset = DatasetFactory.create()
    kwargs = {
        field_name: field_value
    }
    ResourceFactory.create(dataset=_dataset, **kwargs)
    CategoryFactory.create_batch(2, datasets=(_dataset,))
    return _dataset
Beispiel #7
0
def _resource_with_date_and_datetime(csv_with_date_and_datetime):
    if is_enabled('S40_new_file_model.be'):
        res = ResourceFactory.create(
            type='file',
            format='csv',
            main_file__file=File(csv_with_date_and_datetime)
        )
    else:
        res = ResourceFactory.build(
            type='file',
            format='csv',
            file=File(csv_with_date_and_datetime)
        )
    return res
Beispiel #8
0
def resource_with_xls_file_converted_to_csv(res_id, example_xls_file, buzzfeed_dataset, buzzfeed_editor):
    if is_enabled('S40_new_file_model.be'):
        from mcod.resources.models import Resource
        params = {
            'id': res_id,
            'type': 'file',
            'format': 'xls',
            'link': None,
            'filename': 'example_xls_file.xls',
            'openness_score': 1
        }
        res = create_res(buzzfeed_dataset, buzzfeed_editor, **params)
        resource_score, files_score = res.get_openness_score()
        Resource.objects.filter(pk=res.pk).update(openness_score=resource_score)
        res.revalidate()
    else:
        res = ResourceFactory.create(
            id=res_id,
            type='file',
            format='xls',
            link=None,
            file=example_xls_file,
        )
        res.revalidate()
        res.increase_openness_score()
    return res
Beispiel #9
0
def given_resource_views_count_is(resource_id, counter_type, val):
    kwargs = {
        'id': resource_id,
        counter_type: val,
        'type': 'file'
    }
    return ResourceFactory.create(**kwargs)
Beispiel #10
0
def resource_with_file(file_csv):
    if is_enabled('S40_new_file_model.be'):
        res = ResourceFactory.create(
            type="file",
            format='csv',
            main_file__file=factory.django.FileField(
                from_path=os.path.join(settings.TEST_SAMPLES_PATH, 'simple.csv'), filename='simple.csv'
            )
        )
    else:
        res = ResourceFactory.build(
            type="file",
            format='csv',
            file=File(file_csv)
        )
    return res
Beispiel #11
0
def three_resources_with_different_created_at(dates):
    dates_ = dates.split("|")
    resources = []
    for d in dates_:
        date = parser.parse(d)
        res = ResourceFactory.create(created=date)
        resources.append(res)
    return resources
Beispiel #12
0
def given_unpublished_resource_views_count_is(resource_id, counter_type, val):
    kwargs = {
        'id': resource_id,
        counter_type: val,
        'status': 'draft',
        'type': 'file'
    }
    return ResourceFactory.create(**kwargs)
Beispiel #13
0
def onlyheaderscsv_resource(onlyheaders_csv_file):
    from mcod.resources.models import Resource
    if is_enabled('S40_new_file_model.be'):
        resource = ResourceFactory.create(
            type='file',
            format='csv',
            link=None,
            main_file__file=onlyheaders_csv_file,
        )
        resource = Resource.objects.get(pk=resource.pk)
    else:
        resource = ResourceFactory.create(
            type='file',
            format='csv',
            link=None,
            file=onlyheaders_csv_file,
        )
    return resource
Beispiel #14
0
def resource_of_type_website():
    if is_enabled('S40_new_file_model.be'):
        res = ResourceFactory.create(
            type="website",
            format=None,
            main_file__file=factory.django.FileField(
                from_func=get_html_file, filename='{}.html'.format(str(uuid.uuid4()))
            ),
            main_file__content_type="text/html",
        )
    else:
        res = ResourceFactory.create(
            type="website",
            format=None,
            file=factory.django.FileField(from_func=get_html_file, filename='{}.html'.format(str(uuid.uuid4()))),
            content_type="text/html",
        )
    return res
Beispiel #15
0
def dataset_with_chart_as_visualization_type():
    _dataset = DatasetFactory.create()
    _resource = ResourceFactory(
        dataset=_dataset,
        link='https://github.com/frictionlessdata/goodtables-py/blob/master/data/valid.csv',
    )
    ChartFactory.create(resource=_resource, is_default=True)
    _dataset.save()
    return _dataset
Beispiel #16
0
def resource_of_type_api():
    from mcod.resources.models import Resource
    if is_enabled('S40_new_file_model.be'):
        res = ResourceFactory(
            type="api",
            format=None,
            main_file__file=factory.django.FileField(from_func=get_json_file, filename='{}.json'.format(str(uuid.uuid4()))),
            main_file__content_type="application/json",
        )
        res = Resource.objects.get(pk=res.pk)
    else:
        res = ResourceFactory.create(
            type="api",
            format=None,
            file=factory.django.FileField(from_func=get_json_file, filename='{}.json'.format(str(uuid.uuid4()))),
            content_type="application/json",

        )
    return res
Beispiel #17
0
def resource_with_xls_file(example_xls_file):
    from mcod.resources.models import Resource
    if is_enabled('S40_new_file_model.be'):
        res = ResourceFactory.create(
            type='file',
            format='xls',
            link=None,
            main_file__file=example_xls_file,
        )
        res = Resource.objects.get(pk=res.pk)
    else:
        res = ResourceFactory.create(
            type='file',
            format='xls',
            link=None,
            file=example_xls_file,
        )
        res.revalidate()
    res.increase_openness_score()
    return res
Beispiel #18
0
def draft_remote_file_resource(obj_id, httpsserver_custom):
    httpsserver_custom.serve_content(
        content=get_json_file().read(),
        headers={
            'content-type': 'application/json'
        },
    )
    kwargs = {
        'id': obj_id,
        'link': httpsserver_custom.url,
        'status': 'draft'
    }
    if is_enabled('S40_new_file_model.be'):
        kwargs['main_file'] = None
    else:
        kwargs['file'] = None
    res = ResourceFactory.create(**kwargs)
    return res
Beispiel #19
0
def resource_with_simple_csv(res_id, simple_csv_file):
    if is_enabled('S40_new_file_model.be'):
        res = ResourceFactory(
            id=res_id,
            type='file',
            format='csv',
            link=None,
            main_file__file=simple_csv_file,
        )
        res.data_tasks_last_status = res.data_tasks.all().last().status
        res.file_tasks_last_status = res.file_tasks.all().last().status
        res.save()

    else:
        res = ResourceFactory.create(
            id=res_id,
            type='file',
            format='csv',
            link=None,
            file=simple_csv_file,
        )
        res.tracker.saved_data['file'] = None
        res.save()
    return res
Beispiel #20
0
def x_resources(num):
    return ResourceFactory.create_batch(num)
Beispiel #21
0
def resource_with_type(num, res_type):
    return ResourceFactory.create_batch(num, type=res_type)
Beispiel #22
0
def resources():
    return ResourceFactory.create_batch(3)
Beispiel #23
0
def removed_resource_with_id(resource_id):
    res = ResourceFactory.create(id=resource_id, title='Removed resource {}'.format(resource_id),
                                 is_removed=True)
    return res
Beispiel #24
0
def draft_resource_with_id(resource_id):
    res = ResourceFactory.create(id=resource_id, title='Draft resource {}'.format(resource_id),
                                 status='draft')
    return res
Beispiel #25
0
def another_resource_with_id(resource_id):
    res = ResourceFactory.create(id=resource_id, title='Another resource %s' % resource_id)
    return res
Beispiel #26
0
def two_charts_for_resource_id(context, data_str):
    data = json.loads(data_str)
    resource = ResourceFactory.create(**data)
    ChartFactory.create(resource=resource, created_by=context.user, is_default=True)
    ChartFactory.create(resource=resource, created_by=context.user, is_default=False)
Beispiel #27
0
def resource_with_region(res_id, dataset_id, main_region, additional_regions):
    resource = ResourceFactory.create(id=res_id, dataset_id=dataset_id)
    resource.regions.set([main_region])
    resource.regions.add(*additional_regions, through_defaults={'is_additional': True})
    resource.save()
Beispiel #28
0
def removed_resource():
    res = ResourceFactory.create(is_removed=True, title='Removed resource')
    return res
Beispiel #29
0
def draft_resource():
    res = ResourceFactory.create(status="draft", title='Draft resource')
    return res
Beispiel #30
0
def second_resource_with_id(resource_id):
    res = ResourceFactory.create(id=resource_id, title='Second resource %s' % resource_id)
    return res