def setUp(self): self.mock_component = Component("mock_component", "mock component 2", "shreya", ["mock_tag"]) self.mock_component_dict = { "name": self.mock_component.name, "description": self.mock_component.description, "owner": self.mock_component.owner, "tags": self.mock_component.tags, }
class TestComponent(unittest.TestCase): def setUp(self): self.mock_component = Component( "mock_component", "mock component 2", "shreya", ["mock_tag"] ) self.mock_component_dict = { "name": self.mock_component.name, "description": self.mock_component.description, "owner": self.mock_component.owner, "tags": self.mock_component.tags, } def testSerialize(self): """ Test the serialization functionality. """ mock_component_dict = self.mock_component.to_dictionary() self.assertEqual(mock_component_dict, self.mock_component_dict) def testChangeProperty(self): """ Test changing a property. Should return an error. """ mock_component_copy = copy.deepcopy(self.mock_component) with self.assertRaises(AttributeError): mock_component_copy.name = "changed_name"
def get_component_information(component_name: str) -> Component: """Returns a Component with the name, info, owner, and tags.""" store = Store(_db_uri) c = store.get_component(component_name) if not c: raise RuntimeError(f"Component with name {component_name} not found.") tags = [tag.name for tag in c.tags] d = copy.deepcopy(c.__dict__) d.update({"tags": tags}) return Component.from_dictionary(d)
def get_components_with_tag(tag: str) -> typing.List[Component]: """Returns a list of components with the specified tag.""" store = Store(_db_uri) res = store.get_components_with_tag(tag) # Convert to client-facing Components components = [] for c in res: tags = [tag.name for tag in c.tags] d = copy.deepcopy(c.__dict__) d.update({"tags": tags}) components.append(Component.from_dictionary(d)) return components
def get_components(tag="", owner="") -> typing.List[Component]: """Returns all components with the specified owner and/or tag. Else, returns all components.""" store = Store(_db_uri) res = store.get_components(tag=tag, owner=owner) # Convert to client-facing Components components = [] for c in res: tags = [tag.name for tag in c.tags] d = copy.deepcopy(c.__dict__) d.update({"tags": tags}) components.append(Component.from_dictionary(d)) return components