class TestSessionURL(TestCase):
    builder_directory = 'gamebench_api_client.api.requests_retriever.builder.url.url_builder'

    def setUp(self):
        self.session = SessionURL()

    @patch(builder_directory + '.SessionURL._set_metric')
    @patch(builder_directory + '.SessionURL._set_session_id')
    def test_set_suffix(self, mock_set_session_id, mock_set_metric):
        """ Verify the suffix is set and calls the required methods."""

        mock_set_session_id.return_value = SESSION_ID
        mock_set_metric.return_value = METRIC
        test_parameters = {"session_id": SESSION_ID, "metric": METRIC}
        self.session.set_suffix(**test_parameters)
        actual = self.session.suffix
        expected = SESSION_SUFFIX

        with self.subTest():
            mock_set_session_id.assert_called_once_with(SESSION_ID)
            mock_set_metric.assert_called_once_with(METRIC)
        self.assertEqual(actual, expected)

    @patch(builder_directory + '.SessionURL._build_url')
    def test_set_url(self, mock_build_url):
        """ Verify set_url correctly assigns the url variable."""

        mock_build_url.return_value = DEFAULT_SESSION_URL
        self.session.set_url()
        actual = self.session.url

        with self.subTest():
            mock_build_url.assert_called_once_with()
        self.assertEqual(actual, DEFAULT_SESSION_URL)

    def test_build_url(self):
        """ Verify the build_url correctly creates the URL."""

        self.session.base_url = BASE_URL
        self.session.version = VERSION
        self.session.suffix = SESSION_SUFFIX
        self.session.session_id = SESSION_ID
        self.session.metric = METRIC
        actual = self.session._build_url()

        self.assertEqual(actual, DEFAULT_SESSION_URL)

    def test_set_session_id(self):
        """ Verify the session id is set."""

        self.session._set_session_id(SESSION_ID)
        actual = self.session.session_id
        self.assertEqual(actual, SESSION_ID)

    def test_set_metric(self):
        """ Verify the metric is set."""

        self.session._set_metric(METRIC)
        actual = self.session.metric
        self.assertEqual(actual, METRIC)
Exemplo n.º 2
0
    def get_session_url(self, **request_parameters):
        """ Constructs a session URL object and returns the session
            URL string.

            :param request_parameters: Dictionary from the user containing information
                for the request.
            :return: session.url - The session URL string.
        """
        # TODO consider making this a static method unless there are instance members hiding here.
        session = SessionURL()
        director = URLDirector()
        director.construct_url(session, **request_parameters)

        return session.url
    def test_build_session_url(self):
        """ Test to check that the session URL is build correctly."""

        session_parameters = {
            "session_id": SESSION_ID,
            "metric": METRIC
        }

        session = SessionURL()
        url_director = URLDirector()
        url_director.construct_url(session, **session_parameters)

        expected = DEFAULT_SESSION_URL
        actual = session.url

        self.assertEqual(
                expected,
                actual
        )
 def setUp(self):
     self.session = SessionURL()