def test_public_repos(self): """ public repos test """ y = GithubOrgClient("x") self.assertEqual(y.org, self.org_payload) self.assertEqual(y.repos_payload, self.repos_payload) self.assertEqual(y.public_repos(), self.expected_repos) self.assertEqual(y.public_repos("NONEXISTENT"), []) self.get.assert_has_calls([call("https://api.github.com/orgs/x"), call(self.org_payload["repos_url"])])
def test_public_repos(self): """ public repos""" test_class = GithubOrgClient("google") self.assertEqual(test_class.org, self.org_payload) self.assertEqual(test_class.repos_payload, self.repos_payload) self.assertEqual(test_class.public_repos(), self.expected_repos) self.assertEqual(test_class.public_repos("XLICENSE"), []) self.mock.assert_called()
def test_public_repos_with_license(self): """ public repos with License """ test_class = GithubOrgClient("google") self.assertEqual(test_class.public_repos(), self.expected_repos) self.assertEqual(test_class.public_repos("XLICENSE"), []) self.assertEqual(test_class.public_repos("apache-2.0"), self.apache2_repos) self.mock.assert_called()
def test_public_repos_with_license(self): '''Check the license of public repo''' y = GithubOrgClient("x") self.assertEqual(y.org, self.org_payload) self.assertEqual(y.repos_payload, self.repos_payload) self.assertEqual(y.public_repos(), self.expected_repos) self.assertEqual(y.public_repos("NONEXISTENT"), []) self.assertEqual(y.public_repos("apache-2.0"), self.apache2_repos) self.get.assert_has_calls([ call("https://api.github.com/orgs/x"), call(self.org_payload["repos_url"]) ])
def test_public_repos_with_license(self): """ public repos test """ test_client = GithubOrgClient("repo") self.assertEqual(test_client.org, self.org_payload) self.assertEqual(test_client.repos_payload, self.repos_payload) self.assertEqual(test_client.public_repos(), self.expected_repos) self.assertEqual(test_client.public_repos("NONEXISTENT"), []) self.assertEqual(test_client.public_repos("apache-2.0"), self.apache2_repos) self.get.assert_has_calls([ call("https://api.github.com/orgs/repo"), call(self.org_payload["repos_url"]) ])
def test_public_repos(self, get_json_mock): """ test the public repos """ jeff = {"name": "Jeff", "license": {"key": "a"}} bobb = {"name": "Bobb", "license": {"key": "b"}} suee = {"name": "Suee"} to_mock = 'client.GithubOrgClient._public_repos_url' get_json_mock.return_value = [jeff, bobb, suee] with patch(to_mock, PropertyMock(return_value="www.yes.com")) as y: x = GithubOrgClient("x") self.assertEqual(x.public_repos(), ['Jeff', 'Bobb', 'Suee']) self.assertEqual(x.public_repos("a"), ['Jeff']) self.assertEqual(x.public_repos("c"), []) self.assertEqual(x.public_repos(45), []) get_json_mock.assert_called_once_with("www.yes.com") y.assert_called_once_with()
def test_public_repos(self, m_get_json): """test_public_repos""" m_get_json.return_value = [{"name": "google"}, {"name": "abc"}] with patch('client.GithubOrgClient._public_repos_url', new_callable=PropertyMock) as mock_g: mock_g.return_value = "http://google.com" g = GithubOrgClient("instagram") res = g.public_repos() self.assertEqual(res, ["google", "abc"]) m_get_json.assert_called_once() mock_g.assert_called_once()
def test_public_repos(self, test_payload): """Method to unit-test GitHubOrgClient.public_repos""" return_value = [{'name': 'hi'}, {'name': 'hello'}] test_payload.return_value = return_value with patch('GithubOrgClient._public_repos_url', PropertyMock(return_value=return_value)) as mock: i = GithubOrgClient('test') self.assertEqual(i.public_repos(), ['hi', 'hello']) test_payload.assert_called_once() mock.assert_called_once()
def test_public_repos(self, mock_get): """ to unit-test GithubOrgClient.public_repos """ with patch.object(GithubOrgClient, "_public_repos_url", new_callable=PropertyMock, return_value="https://api.github.com/") as mock_pub: test_client = GithubOrgClient("hoberton") test_return = test_client.public_repos() self.assertEqual(test_return, ["holberton"]) mock_get.assert_called_once mock_pub.assert_called_once
def test_public_repos(self, mock_get_json): """Testing public_repos method""" mock_get_json.return_value = [{"name": "google"}, {"name": "abc"}] with mock.patch.object(GithubOrgClient, "_public_repos_url", new_callable=PropertyMock) as mock_public: mock_public.return_value = "http://testurl.com" g_client = GithubOrgClient("facebook") res = g_client.public_repos() self.assertEqual(res, ["google", "abc"]) mock_get_json.assert_called_once() mock_public.assert_called_once()
def test_public_repos(self, mock_get: Any) -> Any: """Method: Test Public Repos""" mock_get.return_value = [{"name": "google"}] with patch.object(GithubOrgClient, '_public_repos_url', new_callable=PropertyMock, return_value="google") as mock_req: thing = GithubOrgClient('google') repos = thing.public_repos() self.assertEqual(repos, ['google']) mock_req.assert_called_once() mock_get.assert_called_once()
def test_public_repos(self, mock_get): """[test_public_repos] """ url = "https://api.github.com/" with patch.object(GithubOrgClient, "_public_repos_url", new_callable=PropertyMock, return_value=url) as mocked: client = GithubOrgClient("hoberton") response = client.public_repos() self.assertEqual(response, ["holbertonschool"]) mock_get.assert_called_once mocked.assert_called_once
def test_public_repos(self, first_patch): """ GithubOrgClient.public_repos unittesting """ with patch('client.GithubOrgClient._public_repos_url', new_callable=PropertyMock, return_value=[] ) as second_patch: test_class = GithubOrgClient("BigBrain") result = test_class.public_repos(license="SmallBrain") self.assertEqual(result, second_patch.return_value) first_patch.assert_called_once() second_patch.assert_called_once()
def test_public_repos(self, mock_get_json): 'test GithubOrgClient.public_repos' return_value = "https://api.github.com/orgs/google/repos" with unittest.mock.patch( 'client.GithubOrgClient._public_repos_url', new_callable=PropertyMock, return_value=return_value) as mock_public_repos_url: github_org_client = GithubOrgClient(org_name='google') response = github_org_client.public_repos() self.assertEqual(response, []) mock_public_repos_url.assert_called_once() mock_get_json.assert_called_once()
def test_public_repos(self, mock_get_json): """ Test function for client.GithubOrgClient.public_repos """ mock_get_json.return_value = [{ "name": "public_repo_0" }, { "name": "public_repo_1" }] with patch('client.GithubOrgClient._public_repos_url', new_callable=PropertyMock) as mock_pru: mock_pru.return_value = "https://api.github.com/users/google/repos" new_client = GithubOrgClient("google") self.assertEqual( new_client.public_repos(), [repo.get("name") for repo in mock_get_json.return_value]) mock_get_json.assert_called_once() mock_pru.assert_called_once()
def test_public_repos(self, mock_json): """ Text more public repos """ 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(self, mock): """ Method to unit test GithubOrgClient.public_repos, Use @patch as a decorator and return a payload of your choice (Patching) """ payload = [{"name": "Google"}, {"name": "Twitter"}] mock.return_value = payload with patch('client.GithubOrgClient._public_repos_url', new_callable=PropertyMock) as mock_instance: mock_instance.return_value = "hello" TestClass = GithubOrgClient('org') response = TestClass.public_repos() result = [i["name"] for i in payload] self.assertEqual(response, result) mock_instance.assert_called_once() mock.assert_called_once()
def test_public_repos(self, mock_json): """ Test public repos function """ test_payload = [{"name": "Google"}, {"name": "Facebook"}] mock_json.return_value = test_payload with patch('client.GithubOrgClient._public_repos_url', new_callable=PropertyMock) as mock_public: mock_public.return_value = "hello/world" test_class = GithubOrgClient('test') res = test_class.public_repos() verify_dict = [{"name": i} for i in res] self.assertEqual(verify_dict, test_payload) mock_public.assert_called_once() mock_json.assert_called_once()
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(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(self): """ Test function for public_repos """ new_client = GithubOrgClient("google") self.assertEqual(new_client.public_repos(), self.__class__.expected_repos)
def test_public_repos(self): """ GithubOrgClient integration testing public_repos """ test_class = GithubOrgClient("BigBrain") self.assertEqual(test_class.public_repos(), self.expected_repos) self.assertEqual(test_class.public_repos("random"), [])
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_public_repos_with_license(self): """ GithubOrgClient integration testing public_repos with a valid licence""" test_class = GithubOrgClient("BigBrain") self.assertEqual(test_class.public_repos(license="apache-2.0"), self.apache2_repos)