I have a factory that is responsible to build some task of my ETL process. See code below:
class ConcreteFactory(AbstractFactory):
def __init__(self, config):
super(AbstractFactory, self).__init__(config)
def build(self, command):
config = self.config
if command == "load_customers_cache":
api = ConcreteApi()
cache = ConcreteCache()
return LoadCustomersCache(cache, api)
if command == "load_customers_bseller":
db = ConcreteDB()
cache = ConcreteCache()
return LoadCustomersBSeller(db, cache)
if (command == "download_from_ftp"):
ftp = ConcreteFtp()
d = DownloadFromFTP(ftp)
return d
For testing purpose, i would like to test, for e.g., the download_from_ftp
. So i need to mock the ConcreteFTP.
What is the best approach?
-
Can I create another factory that is responsible to build the external services like ConcreteAPI, ConcreteCache and ConcreteFTP, and inject it into this
ConcreteFactory
. -
Pass **kwargs to the
ConcreteFactory
, and try to getkwargs["ftp"]
and if it returns not NONE I use it as my FTP class. So I can pass a mock to theConcreteFactory
. -
Create another factory that extends from AbstractFactory, and build the mock that I need.
-
Other suggestion, pattern...
Aucun commentaire:
Enregistrer un commentaire