Esempio n. 1
0
 def test_check_health_handles_no_slave(self, mock_from_uri):
     test_uri = "mongo://*****:*****@host1/database"
     connection_stub = ConnectionStub()
     mock_from_uri.return_value=connection_stub
     pmf = PMF.from_uri(test_uri)
     health = pmf.check_health()
     self.assertFalse(health['db_slave_can_read'])
     self.assertEquals(None, health['db_slave_url'])
Esempio n. 2
0
 def test_check_health_returns_master_and_slave_urls(self, mock_from_uri):
     test_uri = "mongo://*****:*****@host1,host2/database"
     connection_stub = ConnectionStub()
     mock_from_uri.return_value=connection_stub
     pmf = PMF.from_uri(test_uri)
     health = pmf.check_health()
     self.assertEquals('host1',health['db_master_url'])
     self.assertEquals('host2',health['db_slave_url'])
Esempio n. 3
0
 def test_check_health_returns_master_read_fail_when_master_cannot_be_read(self, mock_from_uri):
     test_uri = "mongo://*****:*****@host1,host2/database"
     connection_stub = ConnectionStub()
     connection_stub.database.collections = []
     mock_from_uri.return_value=connection_stub
     pmf = PMF.from_uri(test_uri)
     health = pmf.check_health()
     self.assertFalse(health['db_master_can_read'])
Esempio n. 4
0
 def test_check_health_returns_master_write_fail_when_master_cannot_write(self, mock_from_uri):
     test_uri = "mongo://*****:*****@host1,host2/database"
     connection_stub = ConnectionStub()
     connection_stub.database.collection.override_data = True
     connection_stub.database.collection.data = None
     mock_from_uri.return_value=connection_stub
     pmf = PMF.from_uri(test_uri)
     health = pmf.check_health()
     self.assertFalse(health['db_master_can_write'])
Esempio n. 5
0
 def test_check_health_returns_master_read_and_write_success(self, mock_from_uri):
     test_uri = "mongo://*****:*****@host1,host2/database"
     connection_stub = ConnectionStub()
     mock_from_uri.return_value=connection_stub
     pmf = PMF.from_uri(test_uri)
     health = pmf.check_health()
     self.assertTrue(health['db_master_can_read'])
     self.assertTrue(health['db_master_can_write'])
     self.assertTrue(connection_stub.database.collection.remove_called)
Esempio n. 6
0
 def test_connection_from_uri_creates_expected_details_given_no_auth(self, mock_from_uri):
     test_uri = "mongo://host1"
     mock_from_uri.return_value="Connection"
     expected_connection = PMF.from_uri(test_uri)
     self.assertEquals(None,expected_connection._username)
     self.assertEquals(None,expected_connection._password)
     self.assertEquals(None,expected_connection._database)
     self.assertEquals(['host1'],expected_connection._hosts)
     self.assertEquals('Connection', expected_connection._connection)
Esempio n. 7
0
 def test_connection_from_uri_creates_expected_details_given_one_host(self, mock_from_uri):
     test_uri = "mongo://*****:*****@host1/database"
     mock_from_uri.return_value="Connection"
     expected_connection = PMF.from_uri(test_uri)
     self.assertEquals('username',expected_connection._username)
     self.assertEquals('password',expected_connection._password)
     self.assertEquals('database',expected_connection._database)
     self.assertEquals(['host1'],expected_connection._hosts)
     self.assertEquals('Connection', expected_connection._connection)
Esempio n. 8
0
 def test_connection_from_uri_creates_expected_details_even_if_port_specified(self, mock_from_uri):
     test_uri = "mongo://*****:*****@host1:123,host2:456/database"
     mock_from_uri.return_value="Connection"
     expected_connection = PMF.from_uri(test_uri)
     self.assertEquals('username',expected_connection._username)
     self.assertEquals('password',expected_connection._password)
     self.assertEquals('database',expected_connection._database)
     self.assertEquals(['host1:123','host2:456'],expected_connection._hosts)
     self.assertEquals('Connection', expected_connection._connection)
Esempio n. 9
0
    def test_check_health_returns_slave_read_success(self, mock_from_uri):
        test_uri = "mongo://*****:*****@host1,host2/database"
        expected_slave_uri = "mongo://*****:*****@host2/database"
        master_connection_stub = ConnectionStub()
        slave_connection_stub = ConnectionStub()
        slave_connection_stub.host = 'host2'
        mock_from_uri.return_value=master_connection_stub
        pmf = PMF.from_uri(test_uri)
        mock_from_uri.return_value=slave_connection_stub
        health = pmf.check_health()

        mock_from_uri.assert_called_with(expected_slave_uri, slave_okay=True)
        self.assertTrue(health['db_slave_can_read'])
        self.assertTrue(slave_connection_stub.disconnect_called)
Esempio n. 10
0
 def test_connection_from_uri_calls_parent_with_same(self, mock_from_uri):
     test_uri = "mongo://*****:*****@url.com/database"
     mock_from_uri.return_value="Connection"
     pmf = PMF.from_uri(test_uri)
     mock_from_uri.assert_called_with(test_uri)