def test_clear_all_empty(self): """Test the clear source command successfully. With stubbed data empty list of sources """ source_out = StringIO() get_url = get_server_location() + SOURCE_URI with requests_mock.Mocker() as mocker: mocker.get(get_url, status_code=200, json={'count': 0}) ncc = SourceClearCommand(SUBPARSER) args = Namespace(name=None) with self.assertRaises(SystemExit): with redirect_stdout(source_out): ncc.main(args) expected = 'No sources exist to be removed\n' self.assertEqual(source_out.getvalue(), expected)
def test_clear_all(self): """Testing the clear source command successfully with stubbed data.""" source_out = StringIO() get_url = BASE_URL + SOURCE_URI delete_url = BASE_URL + SOURCE_URI + '1/' source_entry = { 'id': 1, 'name': 'source1', 'hosts': ['1.2.3.4'], 'credential': ['credential1', 'cred2'], 'port': 22 } data = [source_entry] with requests_mock.Mocker() as mocker: mocker.get(get_url, status_code=200, json=data) mocker.delete(delete_url, status_code=204) ncc = SourceClearCommand(SUBPARSER) args = Namespace(name=None) with redirect_stdout(source_out): ncc.main(args) expected = 'All sources were removed\n' self.assertEqual(source_out.getvalue(), expected)
def test_clear_all(self): """Testing the clear source command successfully with stubbed data.""" source_out = StringIO() get_url = get_server_location() + SOURCE_URI delete_url = get_server_location() + SOURCE_URI + '1/' source_entry = { 'id': 1, 'name': 'source1', 'hosts': ['1.2.3.4'], 'credential': ['credential1', 'cred2'], 'port': 22 } results = [source_entry] data = {'count': 1, 'results': results} with requests_mock.Mocker() as mocker: mocker.get(get_url, status_code=200, json=data) mocker.delete(delete_url, status_code=204) ncc = SourceClearCommand(SUBPARSER) args = Namespace(name=None) with redirect_stdout(source_out): ncc.main(args) expected = messages.SOURCE_CLEAR_ALL_SUCCESS + '\n' self.assertEqual(source_out.getvalue(), expected)