def test_new_format(self): lp = standardize_params('cfr', 'version/label') self.assertEqual(lp.doc_type, 'cfr') self.assertEqual(lp.doc_id, 'version/label') self.assertEqual(lp.tree_id, 'label') lp = standardize_params('preamble', 'docid') self.assertEqual(lp.doc_type, 'preamble') self.assertEqual(lp.doc_id, 'docid') self.assertEqual(lp.tree_id, 'docid')
def test_child_layers_no_results(self, storage): """If the db returns no regulation data, nothing should get saved""" storage.for_documents.get.return_value = None layer_params = standardize_params('cfr', 'vvv/lll') self.assertEqual([], layer.child_layers(layer_params, {})) self.assertTrue(storage.for_documents.get.called) storage.for_documents.get.assert_called_with('cfr', 'lll', 'vvv') storage.for_documents.get.return_value = None layer_params = standardize_params('preamble', 'docdoc') self.assertEqual([], layer.child_layers(layer_params, {})) storage.for_documents.get.assert_called_with('preamble', 'docdoc')
def get(request, name, doc_type, doc_id): """Find and return the layer with this name, referring to this doc_id""" params = standardize_params(doc_type, doc_id) layer = storage.for_layers.get(name, params.doc_type, params.doc_id) if layer is not None: return success(layer) else: return four_oh_four()
def delete(request, name, doc_type, doc_id): """Delete the layer node and all of its children from the db""" params = standardize_params(doc_type, doc_id) if params.doc_type not in ('preamble', 'cfr'): return user_error('invalid doc type') storage.for_layers.bulk_delete(name, params.doc_type, params.doc_id) return success()
def add(request, name, doc_type, doc_id): """Add the layer node and all of its children to the db""" layer = request.json_body if not isinstance(layer, dict): return user_error('invalid format') params = standardize_params(doc_type, doc_id) if params.doc_type not in ('preamble', 'cfr'): return user_error('invalid doc type') for key in layer.keys(): # terms layer has a special attribute if not child_label_of(key, params.tree_id) and key != 'referenced': return user_error('label mismatch: {}, {}'.format( params.tree_id, key)) storage.for_layers.bulk_put(child_layers(params, layer), name, params.doc_type, params.doc_id) return success()
def test_old_format(self): lp = standardize_params('label', 'version') self.assertEqual(lp.doc_type, 'cfr') self.assertEqual(lp.doc_id, 'version/label') self.assertEqual(lp.tree_id, 'label')