Пример #1
0
def test_transform_response():
    # function should read through JSON data to output dictionary of Daily Time Series data parsed by timestamp
    parsed_response = {
        "Meta Data": {
            "1. Information":
            "Daily Prices (open, high, low, close) and Volumes",
            "2. Symbol": "MSFT",
            "3. Last Refreshed": "2018-06-08",
            "4. Output Size": "Full size",
            "5. Time Zone": "US/Eastern"
        },
        "Time Series (Daily)": {
            "2019-06-08": {
                "1. open": "101.0924",
                "2. high": "101.9500",
                "3. low": "100.5400",
                "4. close": "101.6300",
                "5. volume": "22165128"
            },
            "2019-06-07": {
                "1. open": "102.6500",
                "2. high": "102.6900",
                "3. low": "100.3800",
                "4. close": "100.8800",
                "5. volume": "28232197"
            }
        }
    }

    transformed_response = [{
        "timestamp": "2019-06-08",
        "open": 101.0924,
        "high": 101.95,
        "low": 100.54,
        "close": 101.63,
        "volume": 22165128
    }, {
        "timestamp": "2019-06-07",
        "open": 102.65,
        "high": 102.69,
        "low": 100.38,
        "close": 100.88,
        "volume": 28232197
    }]

    assert transform_response(parsed_response) == transformed_response
Пример #2
0
def test_transform_response():
    wsd = {
        "2020-04-15": {
            "1. open": "164.3500",
            "2. high": "173.7500",
            "3. low": "162.3000",
            "4. close": "171.8800",
            "5. volume": "135368325"
        },
        "2020-04-09": {
            "1. open": "160.3200",
            "2. high": "170.0000",
            "3. low": "157.5800",
            "4. close": "165.1400",
            "5. volume": "229630744"
        },
        "2020-04-03": {
            "1. open": "152.4400",
            "2. high": "164.7800",
            "3. low": "150.0100",
            "4. close": "153.8300",
            "5. volume": "290191457"
        }
    }

    transformed_response = [[
        "timestamp", "open", "high", "low", "close", "volume"
    ],
                            [
                                "2020-04-15", "164.3500", "173.7500",
                                "162.3000", "171.8800", "135368325"
                            ],
                            [
                                "2020-04-09", "160.3200", "170.0000",
                                "157.5800", "165.1400", "229630744"
                            ],
                            [
                                "2020-04-03", "152.4400", "164.7800",
                                "150.0100", "153.8300", "290191457"
                            ]]

    Dates = list(wsd.keys())
    Headers = ['timestamp', 'open', 'high', 'low', 'close', 'volume']
    Rows = [Headers]

    assert transform_response(wsd, Dates, Rows) == transformed_response
Пример #3
0
def test_transform_response():
    parsed_response = {
        "Meta Data": {
            "1. Information":
            "Daily Prices (open, high, low, close) and Volumes",
            "2. Symbol": "AAPL",
            "3. Last Refreshed": "2019-05-02 16:00:01",
            "4. Output Size": "Compact",
            "5. Time Zone": "US/Eastern"
        },
        "Time Series (Daily)": {
            "2019-05-02": {
                "1. open": "209.8400",
                "2. high": "212.6500",
                "3. low": "208.1300",
                "4. close": "209.1500",
                "5. volume": "29368219"
            },
            "2019-05-01": {
                "1. open": "209.8800",
                "2. high": "215.3100",
                "3. low": "209.2300",
                "4. close": "210.5200",
                "5. volume": "63420533"
            }
        }
    }
    transformed_response = transform_response(parsed_response)
    expected_response = [{
        'timestamp': '2019-05-02',
        'open': '209.8400',
        'high': '212.6500',
        'low': '208.1300',
        'close': '209.1500',
        'volume': '29368219'
    }, {
        'timestamp': '2019-05-01',
        'open': '209.8800',
        'high': '215.3100',
        'low': '209.2300',
        'close': '210.5200',
        'volume': '63420533'
    }]
    assert transformed_response == expected_response
Пример #4
0
def test_transform_response():
    parsed_response = {
        "Meta Data": {
            "1. Information":
            "Daily Prices (open, high, low, close) and Volumes",
            "2. Symbol": "MSFT",
            "3. Last Refreshed": "2018-06-08",
            "4. Output Size": "Full size",
            "5. Time Zone": "US/Eastern"
        },
        "Time Series (Daily)": {
            "2019-06-08": {
                "1. open": "101.0924",
                "2. high": "101.9500",
                "3. low": "100.5400",
                "4. close": "101.6300",
                "5. volume": "22165128"
            },
            "2019-06-07": {
                "1. open": "102.6500",
                "2. high": "102.6900",
                "3. low": "100.3800",
                "4. close": "100.8800",
                "5. volume": "28232197"
            },
            "2019-06-06": {
                "1. open": "102.4800",
                "2. high": "102.6000",
                "3. low": "101.9000",
                "4. close": "102.4900",
                "5. volume": "21122917"
            }
        }
    }

    transformed_response = [
        {
            "timestamp": "2019-06-08",
            "open": 101.0924,
            "high": 101.95,
            "low": 100.54,
            "close": 101.63,
            "volume": 22165128
        },
        {
            "timestamp": "2019-06-07",
            "open": 102.65,
            "high": 102.69,
            "low": 100.38,
            "close": 100.88,
            "volume": 28232197
        },
        {
            "timestamp": "2019-06-06",
            "open": 102.48,
            "high": 102.60,
            "low": 101.90,
            "close": 102.49,
            "volume": 21122917
        },
    ]

    assert transform_response(parsed_response) == transformed_response
Пример #5
0
def test_transform_response():
    parsed_response = {
        "Meta Data": {
            "1. Information":
            "Daily Prices (open, high, low, close) and Volumes",
            "2. Symbol": "MSFT",
            "3. Last Refreshed": "2019-05-01",
            "4. Output Size": "Full size",
            "5. Time Zone": "US/Eastern"
        },
        "Time Series (Daily)": {
            "2019-05-31": {
                "1. open": "123.4500",
                "2. high": "123.8900",
                "3. low": "120.3400",
                "4. close": "123.5600",
                "5. volume": "12345678"
            },
            "2019-05-30": {
                "1. open": "124.5600",
                "2. high": "124.8900",
                "3. low": "123.3400",
                "4. close": "124.5600",
                "5. volume": "22345678"
            },
            "2019-05-29": {
                "1. open": "122.4500",
                "2. high": "122.8900",
                "3. low": "121.3400",
                "4. close": "122.5600",
                "5. volume": "32345678"
            }
        }
    }
    #Referenced Prof. Rossetti's solution
    transformed_response = [
        {
            "timestamp": "2019-05-31",
            "open": 123.4500,
            "high": 123.8900,
            "low": 120.3400,
            "close": 123.5600,
            "volume": 12345678
        },
        {
            "timestamp": "2019-05-30",
            "open": 124.5600,
            "high": 124.8900,
            "low": 123.3400,
            "close": 124.5600,
            "volume": 22345678
        },
        {
            "timestamp": "2019-05-29",
            "open": 122.4500,
            "high": 122.8900,
            "low": 121.3400,
            "close": 122.5600,
            "volume": 32345678
        },
    ]
    assert transform_response(parsed_response) == transformed_response