File size: 1,145 Bytes
065fee7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import logging

import pytest

from redshift_connector import InterfaceError, RedshiftProperty

LOGGER = logging.getLogger(__name__)
LOGGER.propagate = True


def test_set_region_from_endpoint_lookup(db_kwargs) -> None:
    rp: RedshiftProperty = RedshiftProperty()
    rp.put(key="host", value=db_kwargs["host"])
    rp.put(key="port", value=db_kwargs["port"])
    rp.set_region_from_host()

    expected_region = rp.region
    rp.region = None

    rp.set_region_from_endpoint_lookup()
    assert rp.region == expected_region


@pytest.mark.parametrize("host, port", [("x", 1000), ("amazon.com", -1), ("-o", 5439)])
def test_set_region_from_endpoint_lookup_raises(host, port, caplog) -> None:
    import logging

    rp: RedshiftProperty = RedshiftProperty()
    rp.put(key="host", value=host)
    rp.put(key="port", value=port)
    expected_msg: str = "Unable to automatically determine AWS region from host {} port {}. Please check host and port connection parameters are correct.".format(
        host, port
    )

    with caplog.at_level(logging.DEBUG):
        rp.set_region_from_endpoint_lookup()
    assert expected_msg in caplog.text