def setUp(self): """Set up general variables""" server_url = "http://test_server" client_secret = "test_client_secret" client_id = "test_client_id" with patch('rocketc.api_teams.ApiTeams._init_session') as mock_session: mock_session.return_value = MagicMock() self.api = ApiTeams(client_id, client_secret, server_url)
def setUp(self): """Set up general variables""" username = "******" password = "******" server_url = "http://test_server" client_secret = "test_client_secret" client_id = "test_client_id" with patch('rocketc.api_teams.ApiTeams._get_token') as mock_token: mock_token.return_value = "test_token" self.api = ApiTeams(username, password, client_id, client_secret, server_url)
class TestApiTeams(unittest.TestCase): """""" def setUp(self): """Set up general variables""" username = "******" password = "******" server_url = "http://test_server" client_secret = "test_client_secret" client_id = "test_client_id" with patch('rocketc.api_teams.ApiTeams._get_token') as mock_token: mock_token.return_value = "test_token" self.api = ApiTeams(username, password, client_id, client_secret, server_url) @patch('rocketc.api_teams.requests.get') def test_call_api_get(self, mock_request): """Test for the method call api get""" url_path = "test_path" payload = {"data": "data_test"} url = "/".join([self.api.server_url, self.api.API_PATH, url_path]) self.api._call_api_get(url_path, payload) mock_request.assert_called_with(url, headers=self.api.headers, params=payload) @patch('rocketc.api_teams.OAuth2Session') def test_get_token(self, mock_oauth): """test get_token """ server_url = "test_server" token_url = "/".join([server_url, "oauth2/access_token/"]) self.api._get_token(server_url) mock_oauth.return_value.fetch_token.assert_called_with( token_url=token_url, client_id=self.api.client_id, client_secret=self.api.client_secret, username=self.api.username, password=self.api.password) @patch('rocketc.api_teams.ApiTeams._call_api_get') def test_get_user_team(self, mock_call): """Get the user's team""" course_id = MagicMock() course_id.to_deprecated_string.return_value = "test_course_id" username = "******" url_path = "teams" payload = {"course_id": "test_course_id", "username": username} mock_call.return_value = MagicMock(status_code=200) self.api.get_user_team(course_id, username) mock_call.assert_called_with(url_path, payload)