def test_should_ensure_zookeeper_path_exists_for_remote_servers(
        self,
        mock_get_ec2_client,
        mock_get_zookeeper_client,
        mock_get_clickhouse_cluster_definition,
    ):
        zookeeper = MagicMock()
        mock_get_zookeeper_client.return_value = zookeeper
        lambda_context = LambdaContext()
        lambda_context.function_name = "lambda_handler"
        lambda_context.aws_request_id = "abc-123"

        lambda_handler({}, lambda_context)

        zookeeper.ensure_path.assert_any_call(
            "clickhouse.config.remote_servers")
def test_handler_body_different_each_time_for_different_input(mock_event):
    results = set()
    for i in range(3):
        mock_event['body'] = i
        results.add(handler.lambda_handler(mock_event, 'test')['body'])

    assert len(results) == 3
    def test_all_private_ips_and_shards_matching_clickhouse_server_added_to_zookeeper(
        self,
        mock_get_ec2_client,
        mock_get_zookeeper_client,
        mock_get_clickhouse_cluster_definition,
    ):
        ec2_client = MagicMock()
        mock_get_ec2_client.return_value = ec2_client
        shard_config = {
            "shard_1": ["172.26.39.30", "172.26.99.237"],
            "shard_2": ["172.26.32.16", "172.26.97.29"],
        }
        mock_get_clickhouse_cluster_definition.return_value = shard_config
        zookeeper = MagicMock()
        mock_get_zookeeper_client.return_value = zookeeper
        lambda_context = LambdaContext()
        lambda_context.function_name = "lambda_handler"
        lambda_context.aws_request_id = "abc-123"

        result = lambda_handler({}, lambda_context)

        remote_servers_xml = b"""<hmrc_data_cluster>
  <shard>
    <internal_replication>true</internal_replication>
    <replica>
      <default_database>graphite</default_database>
      <host>172.26.39.30</host>
      <port>9000</port>
    </replica>
    <replica>
      <default_database>graphite</default_database>
      <host>172.26.99.237</host>
      <port>9000</port>
    </replica>
  </shard>
  <shard>
    <internal_replication>true</internal_replication>
    <replica>
      <default_database>graphite</default_database>
      <host>172.26.32.16</host>
      <port>9000</port>
    </replica>
    <replica>
      <default_database>graphite</default_database>
      <host>172.26.97.29</host>
      <port>9000</port>
    </replica>
  </shard>
</hmrc_data_cluster>"""

        zookeeper.set.assert_any_call("clickhouse.config.remote_servers",
                                      remote_servers_xml)
        self.assertEqual(result, {"cluster_definition": shard_config})
    def test_consumer(self):

        lambda_handler(self.eventHeartbeat, None)
        self.assertTrue(True)
    def test_lambda_handler(self, mock_post):
        event = "dummy_event"
        context = "dummy_context"

        handler.lambda_handler(event, context)
        mock_post.assert_called_once()
def test_handler_status_code_type_int(mock_event):
    result = handler.lambda_handler(mock_event, 'test')
    assert type(result['statusCode']) is int
def test_handler_returned_dict_has_status_code(mock_event):
    result = handler.lambda_handler(mock_event, 'test')
    assert 'statusCode' in result.keys()
def test_handler_returned_dict_has_body(mock_event):
    result = handler.lambda_handler(mock_event, 'test')
    assert 'body' in result.keys()
def test_handler_returns_dict(mock_event):
    result = handler.lambda_handler(mock_event, 'test')
    assert type(result) is dict