def test_init_load_id_store_from_json_when_file_not_exist_with_no_id_store_path(self, tmp_path): with mock.patch('nsadm.info.DATA_DIR', tmp_path): ins = file_dispatchloader.IDStore(None) ins.load_from_json() assert ins == {}
def test_save_when_saved_is_false(self, json_dump, id_file): ins = file_dispatchloader.IDStore(id_file) ins.saved = False ins.save() json_dump.assert_called_once()
def test_save_when_saved_is_true(self, json_dump, id_file): ins = file_dispatchloader.IDStore(id_file) ins.saved = True ins.save() json_dump.assert_not_called()
def test_init_load_id_store_from_json_when_file_not_exist_with_id_store_path(self): ins = file_dispatchloader.IDStore('test.json') ins.load_from_json() assert os.path.isfile('test.json') assert ins == {} os.remove('test.json')
def test_load_id_store_from_dispatch_config_with_no_remove_action_and_no_override(self, tmp_path): id_file_path = tmp_path / 'id_store.json' ins = file_dispatchloader.IDStore(id_file_path) ins['test1'] = '1234567' dispatch_config = {'nation1': {'test1': {'title': 'test_title', 'category': '1', 'subcategory': '100'}, 'test2': {'title': 'test_title', 'category': '1', 'subcategory': '100'}}, 'nation2': {'test3': {'ns_id': '9876543', 'title': 'test_title', 'category': '1', 'subcategory': '100'}}} ins.load_from_dispatch_config(dispatch_config) assert ins == {'test1': '1234567', 'test3': '9876543'}
def test_load_id_store_from_dispatch_config_with_remove_action(self, tmp_path): """Id of dispatches with remove action should not be loaded. """ id_file_path = tmp_path / 'id_store.json' ins = file_dispatchloader.IDStore(id_file_path) ins['test1'] = '1234567' dispatch_config = {'nation1': {'test1': {'title': 'test_title', 'category': '1', 'subcategory': '100'}, 'test2': {'title': 'test_title', 'category': '1', 'subcategory': '100'}}, 'nation2': {'test3': {'action': 'remove', 'ns_id': '9876543', 'title': 'test_title', 'category': '1', 'subcategory': '100'}}} ins.load_from_dispatch_config(dispatch_config) assert ins == {'test1': '1234567'}
def test_load_id_store_from_dispatch_config_with_no_remove_action_and_with_override(self, tmp_path): """Previously loaded id must be overridden with the dispatch config version when this method is called. """ id_file_path = tmp_path / 'id_store.json' ins = file_dispatchloader.IDStore(id_file_path) ins['test1'] = '1234567' dispatch_config = {'nation1': {'test1': {'title': 'test_title', 'ns_id': '456789', 'category': '1', 'subcategory': '100'}, 'test2': {'title': 'test_title', 'category': '1', 'subcategory': '100'}}, 'nation2': {'test3': {'ns_id': '9876543', 'title': 'test_title', 'category': '1', 'subcategory': '100'}}} ins.load_from_dispatch_config(dispatch_config) assert ins == {'test1': '456789', 'test3': '9876543'}
def test_init_load_id_store_when_file_already_exists(self, id_file): ins = file_dispatchloader.IDStore(id_file) ins.load_from_json() assert ins['Test'] == '12345'