def test_set_data(self, mock_retriever, mock_utility):
        """ Verify the proper methods are called."""

        mock_retriever.get_response_json.return_value = SAMPLE_RESPONSE
        mediator = GenericMediator(**NO_METRIC_REQUEST_PARAMS)
        mediator.get_results()

        with self.subTest():
            mock_retriever.assert_called_once()
        mock_utility.assert_called_once()
Exemple #2
0
    def test_set_data(self, mock_return):
        """ Verify get_results returns a DataFrame."""

        adapter = RequestsAdapter(**DEFAULT_EXPECTED_REQUEST_PARAMS)
        mock_return.request("GET",
                            DEFAULT_SESSION_URL,
                            json=self.generic_frame_json["response"])

        expected = pandas.DataFrame([adapter.request().json()])
        self.mediator = GenericMediator(**DEFAULT_REQUEST_PARAMS)
        actual = self.mediator.get_results()

        assert_frame_equal(expected, actual)
    def test_init_creates_retriever(self, mock_retriever):
        """ Verify the init calls the ResponseRetriever and assigns it to a variable."""

        mediator = GenericMediator()
        with self.subTest():
            mock_retriever.assert_called_once_with()
        self.assertIsNotNone(mediator.retriever)
Exemple #4
0
class TestGenericFrameMediator(TestCase):
    """ Tests for the GenericMediator."""

    def setUp(self):
        self.error_message = "\nTest: {} \nExpected: {}\nActual:   {}\n"
        with open(os.path.join(
                PARENT_DIR + API_SAMPLES + "sessionid.json")) as json_data:
            self.generic_frame_json = json.load(json_data)

    @requests_mock.Mocker()
    def test_set_data(self, mock_return):
        """ Verify get_results returns a DataFrame."""

        adapter = RequestsAdapter(**DEFAULT_EXPECTED_REQUEST_PARAMS)
        mock_return.request(
            "GET",
            DEFAULT_SESSION_URL,
            json=self.generic_frame_json["response"]
        )

        expected = pandas.DataFrame(adapter.request().json())
        self.mediator = GenericMediator(**DEFAULT_REQUEST_PARAMS)
        actual = self.mediator.get_results()

        assert_frame_equal(
            expected,
            actual
        )
Exemple #5
0
    def __init__(self, **request_parameters):
        """ Sets up the mediator and data attributes.

            The mediator is set to the mediator that it will be contacting.  The data
            is set to the DataFrame returned from the get_results method.

            :param request_parameters: Dictionary passed in from the model Creator.  Contains information to
                build and send a response.
        """

        super().__init__()
        self.mediator = GenericMediator(**request_parameters)
        self.data = self.get_data()
Exemple #6
0
    def __init__(self, **request_parameters):
        """ Sets up the mediator and data attributes.

            The mediator is set to the mediator that it will be contacting.  The data
            is set to the DataFrame returned from the get_results method.

        """

        super().__init__(**request_parameters)
        self.request_parameters = request_parameters
        self.authenticator = Authenticator()
        self.request_parameters['auth_token'] = self.authenticator.data[
            'token']
        self.request_parameters['metric'] = self.METRIC_PATH
        self.mediator = GenericMediator(**self.request_parameters)
        self.data = self.get_data()