예제 #1
0
    def from_dict(cls, data):
        sources = []
        actions = []
        for source in data["sources"]:
            sources.append(Source.fromDict(source))

        if data.get("actions"):
            for action in data["actions"]:
                actions.append(Action.from_dict(action))

        return cls(sources=sources, actions=actions)
예제 #2
0
	def test_from_dict(self):
		reg = Source("id", "name", "fetcher", "parser", [], {}, parameters={"test": "true"})
		dictionary = Source.fromDict({
			"id": "id",
			"name": "name",
			"parser": "parser",
			"fetcher": "fetcher",
			"urls": [],
			"map": {},
			"parameters": {
				"test": "true"
			}
		})
		self.assertEqual(reg.id, dictionary.id)
		self.assertEqual(reg.name, dictionary.name)
		self.assertEqual(reg.fetcher_name, dictionary.fetcher_name)
		self.assertEqual(reg.urls, dictionary.urls)
		self.assertEqual(reg.parser_name, dictionary.parser_name)
		self.assertEqual(reg.parameters["test"], dictionary.get_parameter("test"))