Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
Added tests for utils.deljson
Browse files Browse the repository at this point in the history
  • Loading branch information
MurphyMark committed Oct 20, 2017
1 parent 601ea8e commit edccc38
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,38 @@ def test_loadjson_loads_json(self):

self.assertEqual(json_dict, loaded_json)

def test_deljson_deletes_json_keys(self):
"""Does deljson correctly delete JSON entries with given keys?"""

json_dict = {u'one': u'a', u'two': u'b', u'three': u'c'}
json_dict_two_deleted = {u'one': u'a', u'three': u'c'}

with open(self.file_path + '.json', 'w') as f:
json.dump(json_dict, f)

utils.deljson(u'two', self.file_path)

with open(self.file_path + '.json') as f:
json_dict_after_deljson = json.load(f)

self.assertEqual(json_dict_two_deleted, json_dict_after_deljson)

def test_deljson_deletes_json_values(self):
"""Does deljson correctly delete JSON entries with given values?"""

json_dict = {u'one': u'a', u'two': u'b', u'three': u'c'}
json_dict_b_deleted = {u'one': u'a', u'three': u'c'}

with open(self.file_path + '.json', 'w') as f:
json.dump(json_dict, f)

utils.deljson(u'b', self.file_path)

with open(self.file_path + '.json') as f:
json_dict_after_deljson = json.load(f)

self.assertEqual(json_dict_b_deleted, json_dict_after_deljson)

def tearDown(self):
try:
os.remove(self.file_path)
Expand Down

0 comments on commit edccc38

Please sign in to comment.