Beispiel #1
0
def test_helpful_error_collection(duplicate_items: List[JSONDict]) -> None:
    """Test duplicate item helpful erorror message"""
    with pytest.raises(ValidationError) as e:
        collection = UploadCollection(items=duplicate_items)  # noqa: F841

    result = helpful_validation_error(e.value.errors())

    assert (
        result ==
        """The file contained the following problems:\n\t* items - Duplicate item guids detected: ['http://www.crimsonhexagon.com/post1']\n"""
    )
Beispiel #2
0
def large_upload_collection(upload_items: List[JSONDict]) -> UploadCollection:
    """Collection of 3050 unique upload items"""
    items = []

    item = upload_items[0]
    for i in range(3050):
        copy = item.copy()
        copy["guid"] = copy["guid"].replace("post1", f"post{i}")
        items.append(copy)

    collection = UploadCollection(items=items)
    return collection
Beispiel #3
0
def test_helpful_error_item(upload_items: List[JSONDict]) -> None:
    """Test invalid custom content item helpful error messages"""
    del upload_items[1]["author"]

    with pytest.raises(ValidationError) as e:
        collection = UploadCollection(items=upload_items)  # noqa: F841

    result = helpful_validation_error(e.value.errors())

    assert (
        result ==
        """The file contained the following problems:\n\t* items - 1 - author - field required\n"""
    )
Beispiel #4
0
def test_detect_duplicate_upload_items(
        duplicate_items: List[JSONDict]) -> None:
    """Test duplicate items detected"""

    with pytest.raises(ValidationError) as e:
        invalid_collection = UploadCollection(
            items=duplicate_items)  # noqa: F841

    assert e.value.errors() == [{
        "loc": ("items", ),
        "msg":
        "Duplicate item guids detected: ['http://www.crimsonhexagon.com/post1']",
        "type": "value_error",
    }]
Beispiel #5
0
def test_upload_iteration(upload_items: List[JSONDict]) -> None:
    """Test iteration over collection"""
    validated = UploadCollection(items=upload_items)
    for i, item in zip(range(len(validated)), validated):
        assert validated[i] == item
Beispiel #6
0
def test_upload_to_df(upload_dataframe: pd.DataFrame) -> None:
    """Test back and forth to dataframe is equal"""
    validated = UploadCollection.from_dataframe(upload_dataframe)
    assert upload_dataframe.equals(
        validated.to_dataframe()[upload_dataframe.columns])
Beispiel #7
0
def test_upload_from_df(upload_items: List[JSONDict],
                        upload_dataframe: pd.DataFrame) -> None:
    """Test dataframe for upload can be validated"""

    validated = UploadCollection.from_dataframe(upload_dataframe)
    assert validated.dict() == upload_items
Beispiel #8
0
def test_unique_upload_items(upload_items: List[JSONDict]) -> None:
    """Test validated dict() is same as original"""
    validated = UploadCollection(items=upload_items)
    assert validated.dict() == upload_items