def test_public_repos(self, mock_json): """ Test that the list of repos is what you expect from the chosen payload. Test that the mocked property and the mocked get_json was called once. """ json_payload = [{"name": "Google"}, {"name": "Twitter"}] mock_json.return_value = json_payload with patch('client.GithubOrgClient._public_repos_url', new_callable=PropertyMock) as mock_public: mock_public.return_value = "hello/world" test_class = GithubOrgClient('test') result = test_class.public_repos() check = [i["name"] for i in json_payload] self.assertEqual(result, check) mock_public.assert_called_once() mock_json.assert_called_once()
def test_public_repos_url(self): """ Test that the result of _public_repos_url is the expected one based on the mocked payload """ with patch('client.GithubOrgClient.org', new_callable=PropertyMock) as mock: payload = {"repos_url": "World"} mock.return_value = payload test_class = GithubOrgClient('test') result = test_class._public_repos_url self.assertEqual(result, payload["repos_url"])
def test_public_repos_url(self): """Testing public_repos_url """ with mock.patch.object(GithubOrgClient, "org", new_callable=PropertyMock) as mock_org: test_json = {"url": "facebook", "repos_url": "http://testurl.com"} mock_org.return_value = test_json g_client = GithubOrgClient(test_json.get("url")) res = g_client._public_repos_url mock_org.assert_called_once() self.assertEqual(res, test_json.get("repos_url"))
def test_public_repos_url(self): """ to unit-test GithubOrgClient._public_repos_url """ with patch.object(GithubOrgClient, "org", new_callable=PropertyMock, return_value={"repos_url": "holberton"}) as mock_get: test_json = {"repos_url": "holberton"} test_client = GithubOrgClient(test_json.get("repos_url")) test_return = test_client._public_repos_url mock_get.assert_called_once self.assertEqual(test_return, mock_get.return_value.get("repos_url"))
def test_public_repos(self, get_patch): ''' Test list of repos is expected from payload. ''' get_patch.return_value = [{"name": "google"}, {"name": "abc"}] with patch.object(GithubOrgClient, "_public_repos_url", new_callable=Property, return_value="http://google.com") as mock_o: G_client = GithubOrgClient("facebook") self.assertEqual( G_client.public_repos(), ["google", "abc"] ) get_patch.assert_called_once() mock_o.assert_called_once()
def test_public_repos_url(self): """[test_public_repos_url] """ with patch.object(GithubOrgClient, "org", new_callable=PropertyMock, return_value={ "repos_url": "holbertonschool" }) as mock_get: json = {"repos_url": "holbertonschool"} client = GithubOrgClient(json.get("repos_url")) response = client._public_repos_url mock_get.assert_called_once self.assertEqual(response, mock_get.return_value.get("repos_url"))
def test_public_repos(self, mocked_method): '''self descriptive''' payload = [{"name": "Google"}, {"name": "TT"}] mocked_method.return_value = payload with patch('client.GithubOrgClient._public_repos_url', new_callable=PropertyMock) as mocked_public: mocked_public.return_value = "world" response = GithubOrgClient('test').public_repos() self.assertEqual(response, ["Google", "TT"]) mocked_public.assert_called_once() mocked_method.assert_called_once()
def test_public_repos(self, mock_get): """ this method unit-tests _puplic_repos """ with patch('client.GithubOrgClient._public_repos_url', new_callable=PropertyMock) as mock_repo: payload_pl = { 'id': '1242', 'user': '******', 'repos_url': 'http://fakeone.com' } test_org = GithubOrgClient('Fakeone') mock_get.return_value = payload_pl new_org = test_org.org mock_repo.return_value = new_org.get('repos_url') self.assertEqual(test_org._public_repos_url, 'http://fakeone.com') mock_get.assert_called_once() mock_repo.assert_called_once()
def test_public_repos(self, mock_method): """[public repos] Args: mock_method ([type]): [metodh get_json] """ GithubOrgClient = __import__('client').GithubOrgClient mock_method.return_value = [{"name": "google"}, {"name": "abc"}] with patch.object(GithubOrgClient, '_public_repos_url', new_callable=PropertyMock) as mock_public: mock_public.return_value = 'google' response = GithubOrgClient("google").public_repos() self.assertEqual(response, ['google', 'abc']) mock_method.assert_called_once() mock_public.assert_called_once()
def test_public_repos_url(self): ''' Test that the result of _public_repos_url. ''' data = { "url": "facebook", "repos_url": "http://google.com" } with patch.object(GithubOrgClient, "org", new_callable=Property, return_value=data) as mock_o: G_client = GithubOrgClient(data.get("url")) mock_o.assert_called_once() self.assertEqual( G_client._public_repos_url, data.get("repos_url") )
def test_public_repos(self, get_json_mock): """ Tests if GithubOrgClient.public_repos result is as expected """ get_json_mock.return_value = [ {'name': 'my_repo_num_0'}, {'name': 'my_repo_num_1'}, {'name': 'my_repo_num_2'}, {'name': 'my_repo_num_3'} ] get_json_mock() with patch( 'client.GithubOrgClient._public_repos_url', new_callable=PropertyMock ) as mocked_public_repos: mocked_public_repos.return_value = [ {'name': 'random_name_0'}, {'name': 'random_name_1'}, {'name': 'random_name_2'}, {'name': 'random_name_3'} ] gc = GithubOrgClient('abc') r = gc._public_repos_url self.assertEqual(r, mocked_public_repos.return_value) mocked_public_repos.assert_called_once() get_json_mock.assert_called_once()
def test_has_license(self, repo, license, expected): """ test the license checker """ self.assertEqual(GithubOrgClient.has_license(repo, license), expected)
def test_org(self, org, expected, get_patch): """ Test the org of the client """ get_patch.return_value = expected x = GithubOrgClient(org) self.assertEqual(x.org, expected) get_patch.assert_called_once_with("https://api.github.com/orgs/" + org)
def test_has_license(self, repo, license, expected): """Testing for test_has_license""" g_client = GithubOrgClient("facebook") res = (g_client.has_license(repo, license)) self.assertEqual(res, expected)
def test_has_license(self, rep, key, license): """Method to unit-test GithubOrgClient.has_license""" self.assertEqual(GithubOrgClient.has_license(rep, key), license)
def test_public_repos_with_license(self): """ method to test the public_repos with the argument license """ test_class = GithubOrgClient("holberton") assert True
def test_public_repos_url(self, name, result): '''self descriptive''' with patch('client.GithubOrgClient.org', PropertyMock(return_value=result)): response = GithubOrgClient(name)._public_repos_url self.assertEqual(response, result.get('repos_url'))
def test_org(self, org_name, mock_json): """ returns correct output """ gc = GithubOrgClient(org_name) gc.org() mock_json.assert_called_once_with( f"https://api.github.com/orgs/{org_name}")
def test_org(self, org_name, mock_get): """ test that GithubOrgClient.org returns the correct value """ test_client = GithubOrgClient(org_name) test_return = test_client.org self.assertEqual(test_return, mock_get.return_value) mock_get.assert_called_once
def test_has_license(self, repo, license, expected): '''Test the existence of license''' self.assertEqual(GithubOrgClient.has_license(repo, license), expected)
def test_public_repos_with_license(self): """ Test function for public_repos with license argument """ new_client = GithubOrgClient("google") self.assertEqual(new_client.public_repos(license="apache-2.0"), self.__class__.apache2_repos)
def test_org(self, name, mock): """ Method that tests org function """ gitcli = GithubOrgClient(name) gitcli.org() mock.assert_called_once_with(f'https://api.github.com/orgs/{name}')
def test_has_license(self, repo, license, expected): """ Method that tests has_license function """ git_client = GithubOrgClient("facebook") res = (git_client.has_license(repo, license)) self.assertEqual(res, expected)
def test_has_license(self, repo, key, expectation): '''self descriptive''' result = GithubOrgClient.has_license(repo, key) self.assertEqual(result, expectation)
def test_has_license(self, key: dict, license_key: str, expected: bool) -> Any: """Method: Test has license""" test = GithubOrgClient('google') test_license = test.has_license(key, license_key) self.assertEqual(test_license, expected)
def test_has_license(self, expected, repo, license_key): 'test GithubOrgClient.has_license' self.assertEqual( GithubOrgClient.has_license(repo=repo, license_key=license_key), expected)
def test_has_license(self, repo, license_key, expected_return): """ Method to unit-test GithubOrgClient.has_license """ test_client = GithubOrgClient("twitter") test_return = test_client.has_license(repo, license_key) self.assertEqual(expected_return, test_return)
def test_public_repos(self): """ method to test GithubOrgClient.public_repos """ test_class = GithubOrgClient("holberton") assert True
def test_has_license(self, repo, license_key, expected): """ unit-test for GithubOrgClient.has_license """ result = GithubOrgClient.has_license(repo, license_key) self.assertEqual(result, expected)
def test_org(self, data, mock): ''' self descriptive ''' endpoint = 'https://api.github.com/orgs/{}'.format(data) spec = GithubOrgClient(data) spec.org() mock.assert_called_once_with(endpoint)