def test_request_download_permission_3(self):
        """Description: We will send a request for preliminary data
           needed to form a data download request
        """
        aSymbol = "AAPL"
        sdate = self.start_date
        edate = self.end_date
        interval = self.interval

        ADR = AssetDataRequest(aSymbol, sdate, edate, interval)
        response_data = ADR.request_download_permission()

        self.assertEqual(
            response_data["error"], 0,
            "In case of successful data download error should be equal to 0")
        self.assertEqual(
            response_data["status_code"], 200,
            "In case of successful data download status code should be equal to 200"
        )
        self.assertIsNotNone(
            response_data["cookies"],
            "In case of successful download the cookies object is not None")
        self.assertIsNotNone(
            response_data["crumb"],
            "In case of successful download the crumb object is not None")
Beispiel #2
0
    def test_return_value_on_http_error(self, mock_requests_get,
                                        request_download_permission):
        """Description: Response error on HTTPError, i.e. response status code is not equal to 200
        """
        status_code = 404
        expected_response_error = 2
        # mocking response from requests_download_permission
        permission_response = {
            "cookies": "cookies_placeholder",
            "crumb": "crumb_placeholder",
            "status_code": 200,
            "error": 0
        }
        request_download_permission.return_value = permission_response

        # mocking response from requests
        response = Mock()
        response.status_code = status_code
        response.raise_for_status.side_effect = requests.exceptions.HTTPError
        mock_requests_get.return_value = response

        # action
        asset_data_request = AssetDataRequest(self.symbol, self.sdate,
                                              self.edate, self.interval)
        resp = asset_data_request.request_data_download()

        # assertion
        self.assertEqual(
            resp["error"], expected_response_error,
            "The response error should be equal to {0}".format(
                expected_response_error))
Beispiel #3
0
    def test_return_value_on_download_permission_error_2(
            self, request_download_permission):
        """Description: Response error when request_download_permission response['error']=2
        """
        # mocking a response from requests_download_permission
        permission_response = {"error": 2}
        request_download_permission.return_value = permission_response

        expected_response_error = -permission_response['error']

        # action
        asset_data_request = AssetDataRequest(self.symbol, self.sdate,
                                              self.edate, self.interval)
        resp = asset_data_request.request_data_download()

        # assertion
        self.assertEqual(
            resp["error"], expected_response_error,
            "The response error should be equal to {0}".format(
                expected_response_error))
Beispiel #4
0
    def test_valid_download_request_3(self):
        """Description: Sending a valid data download request"""
        aSymbol = "AAPL"
        sdate = self.start_date["date"]
        edate = self.end_date["date"]
        interval = "1mo"

        ADR = AssetDataRequest(aSymbol, sdate, edate, interval)
        response_data = ADR.request_data_download()

        self.assertEqual(
            response_data["error"], 0,
            "In case of successful data download error should be equal to 0")
        self.assertEqual(
            response_data["status_code"], 200,
            "In case of successful data download status code should be equal to 200"
        )
        self.assertIsNotNone(
            response_data["response_object"],
            "In case of successful download the response objec is not None")
Beispiel #5
0
    def test_return_value_on_timeout_error(self, requests_get,
                                           request_download_permission):
        """Description: Response error on Timeout
        """
        expected_response_error = 1
        # mocking a response from requests_download_permission
        permission_response = {
            "cookies": "cookies_placeholder",
            "crumb": "crumb_placeholder",
            "status_code": 200,
            "error": 0
        }
        request_download_permission.return_value = permission_response

        # action
        asset_data_request = AssetDataRequest(self.symbol, self.sdate,
                                              self.edate, self.interval)
        resp = asset_data_request.request_data_download()
        # assertion
        self.assertEqual(
            resp["error"], expected_response_error,
            "The response error should be equal to {0}".format(
                expected_response_error))
    def test_initialize_with_correct_parameters_1(self):
        """ Description: initialization of AssetDataRequest object when parameters are correct
        """
        aSymbol = "MSFT"
        sdate = self.start_date["date"]
        edate = self.end_date["date"]
        sdate_timestamp = self.start_date["ts"]
        edate_timestamp = self.end_date["ts"]
        interval = "1d"

        ADR = AssetDataRequest(aSymbol, sdate, edate, interval)
        self.assertEqual(ADR.symbol, aSymbol,
                         "Expected symbol is {0}".format(aSymbol))
        self.assertEqual(ADR.interval, interval,
                         "Expected interval is {0}".format(interval))
        self.assertEqual(
            ADR.start_date, sdate_timestamp,
            "Start date is expected to be equal {0}".format(sdate_timestamp))
        self.assertEqual(
            ADR.end_date, edate_timestamp,
            "End date is expected to be equal {0}".format(edate_timestamp))