Beispiel #1
0
def test_build():
    """Test building a record.

    This will check to make sure that all dataclasses
    associated with a Record can be built and added to
    appropriate containers.
    """
    r = Record("Test")

    ## StructuredData
    sd = StructuredData("TestName", 1.1, DataType.CONTINUOUS, Target.YES)
    assert sd.record is None
    sd.record = r
    assert sd in list(r.structured_data)
    assert len(list(r.structured_data)) == 1

    ## UnstructuredData
    ud = UnstructuredData("http://example.com", FileType.TEXT)
    assert ud.record is None
    ud.record = r
    assert ud in list(r.unstructured_data)
    assert len(list(r.unstructured_data)) == 1

    ## Validate
    rv = RecordValidator(True)
    rv(r)
Beispiel #2
0
def test_format_record_restructuredtext():
    """TBW."""
    r = Record("Formatted Record")

    sd_info = [
        ("sold_price", 1368411.0, DataType.CONTINUOUS, Target.NO),
        ("basement", 2412.0, DataType.CONTINUOUS, Target.NO),
        (
            "garage_parking",
            "uncovered; rv parking; storage above; extra length; workbench",
            DataType.CATEGORY,
            Target.NO,
        ),
        ("lot", "auto-part; private", DataType.CATEGORY, Target.NO),
    ]
    for info in sd_info:
        sd = StructuredData(*info)
        sd.record = r

    ud_info = [
        ("https://www.example.com/properties/photo_5.jpg", "image/jpg",
         "home_photo"),
        ("https://www.example.com/properties/photo_37.jpg", "image/jpg",
         "home_photo"),
        ("https://www.example.com/properties/photo_6.jpg", "image/jpg",
         "home_photo"),
    ]
    for info in ud_info:
        ud = UnstructuredData(*info)
        ud.record = r

    result = StringIO()
    format_record_restructuredtext(r, out=result)
Beispiel #3
0
def test_valid_file():
    """Test building a UnstructuredData with file."""
    validator = RecordValidator(True)
    ud = UnstructuredData(f"file://{__file__}", FileType.TEXT)
    assert ud.record is None
    validator.validate_unstructured_data(ud)
    assert ud.accessible == "OK"
Beispiel #4
0
def test_valid_http():
    """Test building a UnstructuredData."""
    validator = RecordValidator(True)
    ud = UnstructuredData("http://example.com", FileType.TEXT)
    assert ud.record is None
    validator.validate_unstructured_data(ud)
    assert ud.accessible == "OK"
Beispiel #5
0
def test_invalid_mediatype():
    """Attempt to set an invalid media type."""
    validator = RecordValidator(True)
    with pytest.raises(TypeError):
        ud = UnstructuredData("http://example.com", "InvalidMedia")
        validator.validate_unstructured_data(ud)
Beispiel #6
0
def test_invalid_url_scheme():
    """Test building a UnstructuredData with invalid URL scheme."""
    validator = RecordValidator(True)
    ud = UnstructuredData("spam://example.com/", FileType.TEXT)
    validator.validate_unstructured_data(ud)
    assert ud.accessible.lower().startswith("unknown url scheme")
Beispiel #7
0
def test_permissions_file():
    """Test building a UnstructuredData with no read permissions."""
    validator = RecordValidator(True)
    ud = UnstructuredData("file:///etc/sudoers", FileType.TEXT)
    validator.validate_unstructured_data(ud)
    assert ud.accessible != "OK"
Beispiel #8
0
def test_invalid_file():
    """Test building a UnstructuredData with invalid file."""
    validator = RecordValidator(True)
    ud = UnstructuredData("file:///var", FileType.TEXT)
    validator.validate_unstructured_data(ud)
    assert ud.accessible == "not a file"
Beispiel #9
0
def test_missing_file():
    """Test building a UnstructuredData with missing file."""
    validator = RecordValidator(True)
    ud = UnstructuredData("file:///spam", FileType.TEXT)
    validator.validate_unstructured_data(ud)
    assert ud.accessible == "file missing"