def set_dumper(self, **kwargs): if 'dumper' in kwargs: self.dumper = kwargs['dumper'] else: self.dumper = Mongodump.Mongodump(host=self.host, db=self.db, collections=[self.col])
def test_cmd_multiple_collections(self): mongodump = Mongodump.Mongodump(host='127.0.0.1', db='teste', collections=['log0', 'log1']) prefix = ['mongodump', '--host', '127.0.0.1', '--db', 'teste'] par1 = {'host': '127.0.0.1', 'db': 'teste', 'collection': 'log0'} par2 = {'host': '127.0.0.1', 'db': 'teste', 'collection': 'log1'} self.assertEqual(mongodump.runpars, [par1, par2])
def test_run_dump_directory(self): mongodump = Mongodump.Mongodump(host='127.0.0.1', db='teste', collections=['log'], caller=successful_call) mongodump.run() directories = [ name for name in os.listdir(os.getcwd()) if os.path.isdir(name) ] self.assertTrue('dump' in directories)
def test_setquery(self): mongodump = Mongodump.Mongodump(host='127.0.0.1', db='teste', collections=['log']) mongodump.set_query({"timestamp": {"$gt": 10000}}) pars = [{ 'host': '127.0.0.1', 'db': 'teste', 'collection': 'log', 'query': '{"timestamp": {"$gt": 10000}}' }] self.assertEqual(mongodump.query, '{"timestamp": {"$gt": 10000}}') self.assertEqual(mongodump.runpars, pars)
def test_behavior_with_invalid_hosts(self): mongodump = Mongodump.Mongodump(host='servidor_invalido', caller=erroneoushost_call) with self.assertRaises(CalledProcessError): mongodump.run()
def test_run_objectnumber(self): mongodump = Mongodump.Mongodump(host='127.0.0.1', db='teste', collections=['log'], caller=successful_call) self.assertEqual(mongodump.get_objectsdumped(), [603980])
def test_cmd_no_collection(self): mongodump = Mongodump.Mongodump(host='127.0.0.1', db='teste') pars = {'host': '127.0.0.1', 'db': 'teste'} self.assertEqual(mongodump.runpars, [pars])