Exemple #1
0
def test_source_link_filename(db):
    ds1 = factories.DataSetFactory(
        reference_code=factories.DatasetReferenceCodeFactory(code="DW"))
    source1 = factories.SourceLinkFactory(
        dataset=ds1,
        name="A test source",
        url="s3://csv-pipelines/my-data.csv.zip",
        link_type=SourceLink.TYPE_LOCAL,
    )
    assert source1.get_filename() == "DW00001-a-test-source.zip"

    ds2 = factories.DataSetFactory()
    source2 = factories.SourceLinkFactory(
        dataset=ds2,
        name="A test source",
        url="s3://csv-pipelines/my-data.csv",
        link_type=SourceLink.TYPE_LOCAL,
    )
    assert source2.get_filename() == "a-test-source.csv"

    ds3 = factories.DataSetFactory()
    source3 = factories.SourceLinkFactory(
        dataset=ds3,
        name="A test source",
        url="http://www.google.com/index.html",
        link_type=SourceLink.TYPE_EXTERNAL,
    )
    assert source3.get_filename() == "a-test-source.csv"
Exemple #2
0
def test_dataset_source_filename(db, factory):
    ds1 = factories.DataSetFactory(
        reference_code=factories.DatasetReferenceCodeFactory(code="DW"))
    source1 = factory(dataset=ds1, name="A test source")
    assert source1.get_filename() == "DW00001-a-test-source.csv"

    ds2 = factories.DataSetFactory()
    source2 = factory(dataset=ds2, name="A test source")
    assert source2.get_filename() == "a-test-source.csv"
Exemple #3
0
def test_dataset_source_reference_code(db, factory):
    ref_code1 = factories.DatasetReferenceCodeFactory(code="Abc")
    ref_code2 = factories.DatasetReferenceCodeFactory(code="Def")
    ds = factories.DataSetFactory(reference_code=ref_code1,
                                  user_access_type=UserAccessType.OPEN)
    source = factory(dataset=ds)
    assert source.source_reference == "ABC00001"

    # Change to a new reference code
    ds.reference_code = ref_code2
    ds.save()
    ds.refresh_from_db()

    source.refresh_from_db()
    assert source.source_reference == "DEF00001"

    # Unset the reference code
    ds.reference_code = None
    ds.save()
    ds.refresh_from_db()

    source.refresh_from_db()
    assert source.source_reference is None

    # Ensure numbers are incremented
    ds.reference_code = ref_code1
    ds.save()
    ds.refresh_from_db()

    source.refresh_from_db()
    assert source.source_reference == "ABC00002"

    # Delete the reference code
    ref_code1.delete()
    ds.refresh_from_db()

    source.refresh_from_db()
    assert source.source_reference is None
def test_dataset_source_reference_code(db, factory):
    ref_code1 = factories.DatasetReferenceCodeFactory(code='Abc')
    ref_code2 = factories.DatasetReferenceCodeFactory(code='Def')
    ds = factories.DataSetFactory(reference_code=ref_code1)
    source = factory(dataset=ds)
    assert source.source_reference == f'ABC00001'

    # Change to a new reference code
    ds.reference_code = ref_code2
    ds.save()
    ds.refresh_from_db()

    source.refresh_from_db()
    assert source.source_reference == f'DEF00001'

    # Unset the reference code
    ds.reference_code = None
    ds.save()
    ds.refresh_from_db()

    source.refresh_from_db()
    assert source.source_reference is None

    # Ensure numbers are incremented
    ds.reference_code = ref_code1
    ds.save()
    ds.refresh_from_db()

    source.refresh_from_db()
    assert source.source_reference == f'ABC00002'

    # Delete the reference code
    ref_code1.delete()
    ds.refresh_from_db()

    source.refresh_from_db()
    assert source.source_reference is None