Exemplo n.º 1
0
    def test_create_server(self):
        """Creates and returns a server dict."""
        expected = {'serverId': 'server-abc',
                    'groupId': 'group-def',
                    'entityId': 'entity-ghi',
                    'tenantId': '101010'}

        def execute(query, data, consistency):
            if 'INSERT' in query:
                return defer.succeed(None)
            elif 'SELECT' in query:
                return defer.succeed([expected])
        self.client.execute.side_effect = execute

        d = cass.create_server(self.client, expected['tenantId'], expected['serverId'], expected['entityId'],
                               expected['groupId'])

        result = self.successResultOf(d)
        self.assertEqual(result, expected)

        calls = [
            mock.call(
                ' '.join([
                    'INSERT INTO servers ("serverId", "entityId", "groupId")',
                    'VALUES (:serverId, :entityId, :groupId);']),
                {'serverId': 'server-abc',
                 'entityId': 'entity-ghi',
                 'groupId': 'group-def'},
                1),
            mock.call(
                'SELECT * FROM servers WHERE "groupId"=:groupId AND "serverId"=:serverId;',
                {'serverId': 'server-abc', 'groupId': 'group-def'},
                1)]
        self.assertEqual(self.client.execute.mock_calls, calls)
Exemplo n.º 2
0
    def test_create_server(self):
        """Creates and returns a server dict."""
        expected = {
            'serverId': 'server-abc',
            'groupId': 'group-def',
            'entityId': 'entity-ghi',
            'tenantId': '101010'
        }

        def execute(query, data, consistency):
            if 'INSERT' in query:
                return defer.succeed(None)
            elif 'SELECT' in query:
                return defer.succeed([expected])

        self.client.execute.side_effect = execute

        d = cass.create_server(self.client, expected['tenantId'],
                               expected['serverId'], expected['entityId'],
                               expected['groupId'])

        result = self.successResultOf(d)
        self.assertEqual(result, expected)

        calls = [
            mock.call(
                ' '.join([
                    'INSERT INTO servers ("serverId", "entityId", "groupId")',
                    'VALUES (:serverId, :entityId, :groupId);'
                ]), {
                    'serverId': 'server-abc',
                    'entityId': 'entity-ghi',
                    'groupId': 'group-def'
                }, 1),
            mock.call(
                'SELECT * FROM servers WHERE "groupId"=:groupId AND "serverId"=:serverId;',
                {
                    'serverId': 'server-abc',
                    'groupId': 'group-def'
                }, 1)
        ]
        self.assertEqual(self.client.execute.mock_calls, calls)
Exemplo n.º 3
0
 def create_server_record(entity_id):
     return cass.create_server(self._db, tenant_id, server.get('id'),
                               entity_id, group_id)
Exemplo n.º 4
0
 def create_server_record(entity_id):
     return cass.create_server(self._db, tenant_id, server.get('id'), entity_id, group_id)