Beispiel #1
0
 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)
Beispiel #2
0
    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')
Beispiel #3
0
    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()')
Beispiel #4
0
 def test_failed_init_replicaset(self, mrun):
     mrun.return_value = {'ok': 0, 'errmsg': 'danger will robinson'}
     self.assertFalse(mongodb.MongoDB('dummy').init_replicaset())
Beispiel #5
0
 def test_already_init_replicaset(self, mrun):
     mrun.return_value = {'ok': 0, 'errmsg': 'already initialized'}
     self.assertTrue(mongodb.MongoDB('dummy').init_replicaset())
Beispiel #6
0
 def test_init_replicaset(self, mrun):
     mrun.return_value = {'ok': 1}
     self.assertTrue(mongodb.MongoDB('dummy').init_replicaset())
     mrun.assert_called_with('rs.initiate()')
Beispiel #7
0
    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()')
Beispiel #8
0
 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'})
Beispiel #9
0
 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'])
Beispiel #10
0
 def test_install(self, mapt):
     m = mongodb.MongoDB('dummy', '99.9')
     m.install()
     mapt.assert_called_with(['foo=99.9', 'baz'])
Beispiel #11
0
 def test_packages(self):
     m = mongodb.MongoDB('dummy', '9.9')
     self.assertEqual(['foo=9.9', 'baz'], m.packages())
Beispiel #12
0
    def test_mongodb(self):
        m = mongodb.MongoDB('dummy')
        self.assertEqual('dummy', m.source)
        self.assertEqual(None, m.version)

        self.assertRaises(Exception, mongodb.MongoDB, 'archive')