Example #1
0
def test_rewrite_json(db_file, db_content):
    """Check successive write to JSON file"""
    write_json(db_file, db_content)
    write_json(db_file, db_content)
    assert read_json(db_file) == db_content
Example #2
0
def test_insert(json_dao):
    """Check insert in database"""
    key = "data"
    data = {"test": "test"}
    json_dao.insert(key, data)
    assert read_json(json_dao.db_file) == {key: data}
Example #3
0
def test_write_json_missing_file(tmp_path, db_content):
    """Check write to non existing JSON file"""
    db_file = tmp_path / "db.json"
    write_json(db_file, db_content)
    assert read_json(db_file) == db_content
Example #4
0
def test_write_json(db_file, db_content):
    """Check write to JSON file"""
    write_json(db_file, db_content)
    assert read_json(db_file) == db_content
Example #5
0
def test_read_json_missing_file():
    """Check read from non existing JSON file"""
    assert read_json(Path("missing_file")) == {}
Example #6
0
def test_read_json_empty(db_file):
    """Check read from empty JSON file"""
    assert read_json(db_file) == {}
Example #7
0
def test_read_json(db_file, db_content):
    """Check read from JSON file"""
    json.dump(db_content, open(str(db_file), "w"))
    assert read_json(db_file) == db_content