예제 #1
0
def test_version_none():
    """
    If it doesn't have a version string, it should get the current one.
    """
    oil = Oil('XXXXXX')
    oil.metadata.name = 'An oil name'
    pyjs = oil.py_json()
    # remove the version:
    pyjs.pop('adios_data_model_version', None)

    oil = Oil.from_py_json(pyjs)

    assert oil.adios_data_model_version == ADIOS_DATA_MODEL_VERSION
예제 #2
0
    def test_json_minimal(self):
        """
        When we convert our dataclass into a JSON struct, empty fields
        will be sparse.  The field will not be included in the struct.
        So if we create an Oil with only a name, it will look like this:

            {'name': 'A name for an oil'}
        """
        oil = Oil(oil_id=OIL_ID)
        assert oil.oil_id == OIL_ID

        py_json = oil.py_json()

        assert py_json["oil_id"] == OIL_ID
        assert py_json['adios_data_model_version'] == str(
            ADIOS_DATA_MODEL_VERSION)
        print(py_json)
        assert len(py_json) == 3
예제 #3
0
    def test_json_minimal_nonsparse(self):
        oil = Oil(oil_id=OIL_ID)
        py_json = oil.py_json(sparse=False)

        pprint(py_json)

        assert len(py_json) == 8

        for attr in [
                'oil_id',
                'adios_data_model_version',
                'metadata',
                'sub_samples',
                'status',
                'permanent_warnings',
                'extra_data',
                'review_status',
        ]:
            assert attr in py_json