def test_from_json_file(nested_example):
    """
    can it be re-created from an actual json file?
    """

    json_str = nested_example.to_json()
    with open("temp.json", 'w') as tempfile:
        tempfile.write(nested_example.to_json())

    with open("temp.json") as tempfile:
        reconstructed = js.from_json(tempfile)

    reconstructed = js.from_json(json_str)

    assert reconstructed == nested_example
Пример #2
0
 def load(cls, filepath):
     """
     loads a donor database from a json_save format file.
     """
     with open(filepath) as jsfile:
         db = js.from_json(jsfile)
     db.db_file = filepath
 def __init__(self):
     try:
         with open('mailroom.json', 'r') as db_handle:
             file_contents = db_handle.read()
     except IOError:
         self.donor_db = self.initial_db
     if file_contents:
         self.donor_db = js.from_json(file_contents)
def test_from_json_dict2(nested_dict):
    """
    can it be re-created from an actual json string?
    """

    json_str = nested_dict.to_json()
    reconstructed = js.from_json(json_str)

    assert reconstructed == nested_dict
Пример #5
0
def test_save(sample_db):
    # save out the DB
    sample_db.save()

    # Make a new one from the file
    with open(sample_db.db_file) as js_file:
        DB = js.from_json(js_file)

    # are they the same?
    assert sample_db == DB
Пример #6
0
def test_from_json_dict2(nested_dict):
    """
    can it be re-created from an actual json string?
    """

    json_str = nested_dict.to_json()
    print(js.Saveable.ALL_SAVEABLES)
    reconstructed = js.from_json(json_str)

    assert reconstructed == nested_dict
Пример #7
0
def test_save_on_add_donor(sample_db):
    """
    tests the DB gets saved automatcially when it's changed
    """
    sample_db.save()  # make sure it's saved before we change it.

    sample_db.add_donor("Fred Jones")
    # note: not explicitly saving it !

    # Make a new one from the file
    with open(sample_db.db_file) as js_file:
        DB = js.from_json(js_file)

    assert sample_db == DB
Пример #8
0
def test_save_changed(sample_db):
    donor = sample_db.find_donor("paul allen")

    sample_db.save()

    donor.add_donation(500)

    sample_db.save()

    # Make a new one from the file
    with open(sample_db.db_file) as js_file:
        DB = js.from_json(js_file)

    donor1 = sample_db.find_donor("paul allen")
    donor2 = DB.find_donor("paul allen")
    assert donor1 == donor2
    assert donor2.num_donations == 4
Пример #9
0
def test_save_on_change_donor(sample_db):
    """
    tests the DB gets saved automatcially when it's changed
    """
    sample_db.save()  # make sure it's saved before we change it.
    donor = sample_db.find_donor("paul allen")

    donor.add_donation(500)
    # note: not explicitly saving it !

    # Make a new one from the file
    with open(sample_db.db_file) as js_file:
        DB = js.from_json(js_file)

    donor1 = sample_db.find_donor("paul allen")
    donor2 = DB.find_donor("paul allen")
    print(donor1)
    assert donor1 == donor2
    assert donor2.num_donations == 4
Пример #10
0
def load_donors():
    with open("donors.json") as tempfile:
        reconstructed = js.from_json(tempfile)
    return reconstructed.dic
 def load(cls, file='json_in.json'):
     with open(file, 'r') as infile:
         return js.from_json(infile)
Пример #12
0
 def load_json_from_file(self):
     print("Loading from json")
     with open(self.data_file + ".json", 'r') as file_in:
         temp = js.from_json(file_in)
     self.donors_list = temp.donors_list
     return self.count
 def load_list_donors(self):
     global donors
     with open("donor_list.json") as json_file:
         donors = js.from_json(json_file)
Пример #14
0
 def load_donor_records_js(cls, file):
     """Class method for working with the json_save library."""
     # Open donor_records.json using context manager
     with open(file) as f_obj:
         temp_donors = js.from_json(f_obj)
     temp_donors.donor_data = file
Пример #15
0
 def load_json(self):
     print('loading from json')
     with open(self.DATA_FILE + ".json") as file_in:
         temp = js.from_json(file_in)
     self.donorlist = temp.donorlist
     return self.count
Пример #16
0
 def load_json(self):
     with open("save_file.json") as file_in:
         temp = js.from_json(file_in)
     self.donors = temp.donors