diff --git a/lms/djangoapps/mfe_api/tests/test_views.py b/lms/djangoapps/mfe_api/tests/test_views.py index b3592d87a0..8084f563a1 100644 --- a/lms/djangoapps/mfe_api/tests/test_views.py +++ b/lms/djangoapps/mfe_api/tests/test_views.py @@ -25,58 +25,66 @@ class MFEConfigTestCase(APITestCase): """Test the get mfe config from site configuration with the mfe api. Expected result: - - Inside self.get_json pass the response is a json and the status is 200 asserts. - - The configuration obtained by the api is equal to its site configuration in the - MFE_CONFIG key. + - The get_value method of the configuration_helpers in the views is called once with the + parameters ("MFE_CONFIG", {}). + - The status of the response of the request is a HTTP_200_OK. + - The json of the response of the request is equal to the mocked configuration. """ - configuration_helpers_mock.get_value.return_value = {"logo": "logo.jpg"} + configuration_helpers_mock.get_value.return_value = {"EXAMPLE_VAR": "value"} response = self.client.get(self.mfe_config_api_url) configuration_helpers_mock.get_value.assert_called_once_with("MFE_CONFIG", {}) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.json(), {"logo": "logo.jpg"}) + self.assertEqual(response.json(), {"EXAMPLE_VAR": "value"}) @patch("lms.djangoapps.mfe_api.views.configuration_helpers") - def test_get_mfe_config_with_queryparams(self, configuration_helpers_mock): - """Test the get mfe config with a query params from site configuration. + def test_get_mfe_config_with_queryparam(self, configuration_helpers_mock): + """Test the get mfe config with a query param from site configuration. Expected result: - - Inside self.get_json pass the response is a json and the status is 200 asserts. - - The configuration obtained by the api is equal to its site configuration in the - MFE_CONFIG and MFE_CONFIG_MYMFE merged on top. + - The get_value method of the configuration_helpers in the views is called twice, once with the + parameters ("MFE_CONFIG", {}) and once with the parameters ("MFE_CONFIG_MYMFE", {}). + and one for get_value("MFE_CONFIG_MYMFE", {}). + - The json of the response is the merge of both mocked configurations. """ - configuration_helpers_mock.get_value.side_effect = [{"logo": "logo.jpg", "other": "other"}, - {"logo": "logo_mymfe.jpg"}] + configuration_helpers_mock.get_value.side_effect = [{"EXAMPLE_VAR": "value", "OTHER": "other"}, + {"EXAMPLE_VAR": "mymfe_value"}] response = self.client.get(f"{self.mfe_config_api_url}?mfe=mymfe") self.assertEqual(response.status_code, status.HTTP_200_OK) calls = [call("MFE_CONFIG", {}), call("MFE_CONFIG_MYMFE", {})] configuration_helpers_mock.get_value.assert_has_calls(calls) - self.assertEqual(response.json(), {"logo": "logo_mymfe.jpg", "other": "other"}) + self.assertEqual(response.json(), {"EXAMPLE_VAR": "mymfe_value", "OTHER": "other"}) @patch("lms.djangoapps.mfe_api.views.configuration_helpers") @ddt.data( [{}, {}, {}], - [{"logo": "logo.jpg"}, {}, {"logo": "logo.jpg"}], - [{}, {"logo": "logo_mymfe.jpg"}, {"logo": "logo_mymfe.jpg"}], - [{"logo": "logo.jpg"}, {"logo": "logo_mymfe.jpg"}, {"logo": "logo_mymfe.jpg"}], - [{"logo": "logo.jpg", "other": "other"}, {"logo": "logo_mymfe.jpg"}, - {"logo": "logo_mymfe.jpg", "other": "other"}], + [{"EXAMPLE_VAR": "value"}, {}, {"EXAMPLE_VAR": "value"}], + [{}, {"EXAMPLE_VAR": "mymfe_value"}, {"EXAMPLE_VAR": "mymfe_value"}], + [{"EXAMPLE_VAR": "value"}, {"EXAMPLE_VAR": "mymfe_value"}, {"EXAMPLE_VAR": "mymfe_value"}], + [{"EXAMPLE_VAR": "value", "OTHER": "other"}, {"EXAMPLE_VAR": "mymfe_value"}, + {"EXAMPLE_VAR": "mymfe_value", "OTHER": "other"}], ) @ddt.unpack - def test_get_mfe_config_with_queryparams_other_cases( + def test_get_mfe_config_with_queryparam_multiple_configs( self, mfe_config, mfe_config_mymfe, expected_response, configuration_helpers_mock ): - """_summary_ + """Test the get mfe config with a query param and different settings in mfe_config and mfe_config_mfe inside + the site configuration to test that the merge of the configurations is done correctly and mymfe config take + precedence. - Args: - configuration_helpers_mock (_type_): _description_ + In the ddt data the following structure is being passed: + [mfe_config, mfe_config_mymfe, expected_response] + + Expected result: + - The get_value method of the configuration_helpers in the views is called twice, once with the + parameters ("MFE_CONFIG", {}) and once with the parameters ("MFE_CONFIG_MYMFE", {}). + - The json of the response is the expected_response passed by ddt.data. """ - configuration_helpers_mock.get_value.side_effect = [mfe_config, mfe_config_mymfe] response = self.client.get(f"{self.mfe_config_api_url}?mfe=mymfe") @@ -91,8 +99,9 @@ class MFEConfigTestCase(APITestCase): """Test the 404 not found response from get mfe config. Expected result: - - Response status code equal to 404 + - The get_value method of configuration_helpers is not called. + - The status of the response of the request is a HTTP_404_NOT_FOUND. """ response = self.client.get(self.mfe_config_api_url) configuration_helpers_mock.get_value.assert_not_called() - assert response.status_code == status.HTTP_404_NOT_FOUND + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)