def test_bad_sample_date():
    md = MetaData(sample_date="1965-20-10")

    msgs = md.validate()

    print(msgs)

    assert snippet_in_oil_status("W011", msgs)
def test_no_sample_date():
    md = MetaData()

    msgs = md.validate()

    print(msgs)

    assert snippet_not_in_oil_status("W011", msgs)
def test_missing_API_crude():
    md = MetaData()
    md.product_type = "Crude Oil NOS"

    msgs = md.validate()

    print(msgs)

    assert snippet_in_oil_status("E030", msgs)
def test_missing_API_solvent():
    md = MetaData()
    md.product_type = "Solvent"

    msgs = md.validate()

    print(msgs)

    assert snippet_not_in_oil_status("E030", msgs)
    # turned this off
    assert snippet_not_in_oil_status("W004", msgs)
def test_bad_log_date():
    md = MetaData()
    md.change_log.append(ChangeLogEntry(name="Bozo the Clown",
                                        date="2021-040-01",
                                        comment="Any random old thing",
                                        ))

    msgs = md.validate()

    print(msgs)

    print(md.py_json())
    assert snippet_in_oil_status("W011", msgs)
    def test_init_set_attr(self, attr, value, expected):
        meta = MetaData()

        assert hasattr(meta, attr)

        setattr(meta, attr, value)
        assert getattr(meta, attr) == expected
def test_API_always_float():
    """
    the API should get converte to a float if it's an integer in the JSON, etc.
    """

    md = MetaData(API=32)

    assert type(md.API) == float
def test_metadata_from_json():
    """
    see if we can make one from JSON

    fixme: there could be a lot more checks here, but ...
    """
    md = MetaData.from_py_json(json.loads(MD_JSON))

    assert md.sample_date == "2013-04-08"
    assert md.product_type == "Bitumen Blend"
    def test_init_defaults(self, attr, expected):
        meta = MetaData()

        assert hasattr(meta, attr)
        assert getattr(meta, attr) == expected
    def test_init_empty(self):
        meta = MetaData()

        for attr in ('location', 'reference', 'sample_date', 'product_type',
                     'API', 'comments', 'labels'):
            assert hasattr(meta, attr)