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

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

        with self.subTest():
            mock_retriever.assert_called_once()
Exemple #2
0
    def test_set_data(self, mock_return):
        """ Verify get_results returns an auth token."""

        adapter = RequestsAdapter(**AUTH_ATTRIBUTES)
        mock_return.request("POST", AUTH_URL, json=self.auth_json["response"])
        expected = adapter.request().json()
        self.mediator = AuthenticationMediator(**AUTH_DATA)
        actual = self.mediator.get_results()

        self.assertEqual(actual, expected)
    def test_init_creates_retriever(self, mock_retriever):
        """ The init instantiates the AuthResponseRetriever and assigns it to a variable."""

        mediator = AuthenticationMediator()
        with self.subTest():
            mock_retriever.assert_called_once_with()
        self.assertIsNotNone(mediator.retriever)
    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 the return from the get_token method.

            :param request_parameters: Dictionary containing the client's username and password.
        """

        super().__init__()
        self.mediator = AuthenticationMediator(**request_parameters)
        self.data = self.get_data()
        self.token = self.get_data
    def __init__(self):
        """ Sets up the mediator and data attributes.

            The mediator is set to the mediator that it will be contacting.  The data
            is the return from the get_token method.

        """

        super().__init__()
        username_and_password = get_username_and_password()
        self.mediator = AuthenticationMediator(**username_and_password)
        self.data = self.get_data()
        self.token = self.get_data
Exemple #6
0
class TestAuthenticationMediator(TestCase):
    """ Tests for the AuthenticationMediator."""
    def setUp(self):
        self.error_message = "\nTest: {} \nExpected: {}\nActual:   {}\n"
        with open(os.path.join(PARENT_DIR + API_SAMPLES +
                               "auth_sample.json")) as json_data:
            self.auth_json = json.load(json_data)

    @requests_mock.Mocker()
    def test_set_data(self, mock_return):
        """ Verify get_results returns an auth token."""

        adapter = RequestsAdapter(**AUTH_ATTRIBUTES)
        mock_return.request("POST", AUTH_URL, json=self.auth_json["response"])
        expected = adapter.request().json()
        self.mediator = AuthenticationMediator(**AUTH_DATA)
        actual = self.mediator.get_results()

        self.assertEqual(actual, expected)