def test_render_config(self, mopen): output = """baz = foobar\nfoo = bar""" m = mongodb.MongoDB('dummy') m._render_config({'foo': 'bar', 'baz': 'foobar'}) mopen.assert_called_with(m.config_file, 'w') w = mopen.return_value.__enter__.return_value.write w.assert_called_with(output)
def test_add_upstream(self, lsb, mopen): m = mongodb.MongoDB('dummy') m.upstream_repo = 'deb http://localhost {} dummy' lsb.side_effect = [{'DISTRIB_CODENAME': 'xenial'}] m.add_upstream() mopen.assert_called_with(m.upstream_list, 'w') w = mopen.return_value.__enter__.return_value.write w.assert_called_with('deb http://localhost xenial dummy')
def test_run(self, ms): mjson = b''' { "ok": 1 }''' com = ms.Popen.return_value com.communicate.return_value = [mjson, None] com.returncode = 0 self.assertEqual({'ok': 1}, mongodb.MongoDB('dummy').run('doit()')) com.communicate.assert_called_with(input=b'doit()')
def test_failed_init_replicaset(self, mrun): mrun.return_value = {'ok': 0, 'errmsg': 'danger will robinson'} self.assertFalse(mongodb.MongoDB('dummy').init_replicaset())
def test_already_init_replicaset(self, mrun): mrun.return_value = {'ok': 0, 'errmsg': 'already initialized'} self.assertTrue(mongodb.MongoDB('dummy').init_replicaset())
def test_init_replicaset(self, mrun): mrun.return_value = {'ok': 1} self.assertTrue(mongodb.MongoDB('dummy').init_replicaset()) mrun.assert_called_with('rs.initiate()')
def test_failed_run(self, ms): com = ms.Popen.return_value com.communicate.return_value = [None, b'Err'] com.returncode = 1 self.assertRaises(IOError, mongodb.MongoDB('dummy').run, 'fail()')
def test_configure(self, mcfg): m = mongodb.MongoDB('dummy') m.configure({'dbpath': 'foo', 'replicaset': 'test', 'noop': True}) mcfg.assert_called_with({'dbpath': 'foo', 'replSet': 'test'})
def test_uninstall(self, mrac, mapt): m = mongodb.MongoDB('dummy', '99.9') m.uninstall() mapt.assert_called_with(['foo=99.9', 'baz']) mrac.assert_called_with( ['apt-get', 'autoremove', '--purge', '--assume-yes'])
def test_install(self, mapt): m = mongodb.MongoDB('dummy', '99.9') m.install() mapt.assert_called_with(['foo=99.9', 'baz'])
def test_packages(self): m = mongodb.MongoDB('dummy', '9.9') self.assertEqual(['foo=9.9', 'baz'], m.packages())
def test_mongodb(self): m = mongodb.MongoDB('dummy') self.assertEqual('dummy', m.source) self.assertEqual(None, m.version) self.assertRaises(Exception, mongodb.MongoDB, 'archive')