def test_set_current_context_invalid(self, mock_write, mock_print, _): """ Test set_current_context() """ with patch("builtins.open", mock_open(read_data=self.TEST_CONTEXT)): ctx_obj = CtxCore() ctx_obj.set_current_context("local-dev") mock_print.assert_called_with("Not a valid context..")
def test_validate_context(self, mock_default_context): """ Test validate_context() """ with patch("builtins.open", mock_open(read_data=self.TEST_CONTEXT)): ctx_obj = CtxCore() result = ctx_obj.validate_context() mock_default_context.assert_called_once() self.assertEqual(result, True)
def test_set_current_context(self, mock_write, _): """ Test set_current_context() """ with patch("builtins.open", mock_open(read_data=self.TEST_CONTEXT)): ctx_obj = CtxCore() ctx_obj.set_current_context("local") self.assertEqual(ctx_obj.jx_context["current-context"], "local") mock_write.assert_called_once()
def test_list_context_currentname(self, mock_print, mock_write, _): """ Test list_context() """ with patch("builtins.open", mock_open(read_data=self.TEST_CONTEXT)): ctx_obj = CtxCore() ctx_obj.list_context(context_name="test") mock_print.assert_called_with( SupportJSON().list_context_by_currentname, "table", count=False)
def test_rename_context(self, mock_write, _): """ Test rename_context() """ with patch("builtins.open", mock_open(read_data=self.TEST_CONTEXT)): ctx_obj = CtxCore() ctx_obj.rename_context("local", "prod") self.assertEqual(ctx_obj.jx_context, SupportJSON().rename_context_result) mock_write.assert_called_once()
def test_delete_currentcontext(self, mock_write, _): """ Test delete_context() """ with patch("builtins.open", mock_open(read_data=self.TEST_CONTEXT)): ctx_obj = CtxCore() ctx_obj.delete_context("test") self.assertEqual(ctx_obj.jx_context, SupportJSON().delete_current_context_return) mock_write.assert_called_once()
def test_set_context(self, mock_write, _): """ Test set_context() """ with patch("builtins.open", mock_open(read_data=self.TEST_CONTEXT)): ctx_obj = CtxCore() ctx_obj.set_context("local", "test-url", "test-user", "test-token") self.assertEqual(ctx_obj.jx_context, SupportJSON().set_context_return_1) mock_write.assert_called_once()
def test_load_context(self, _): """ Test load_context() """ with patch("builtins.open", mock_open(read_data=self.TEST_CONTEXT)): ctx_obj = CtxCore() self.assertEqual("test", ctx_obj.ctx_name)
def test_load_context_raise_typeerror(self, mock_yaml, _): """ Test load_context() with exception """ mock_yaml.side_effect = TypeError() with patch("builtins.open", mock_open(read_data="")): with self.assertRaises(TypeError) as exception: ctx_obj = CtxCore() self.assertEqual(exception.exception, TypeError())
def test_load_context_raise_error(self, mock_open, _): """ Test load_context() with exception """ mock_open.side_effect = FileNotFoundError() with self.assertRaises(FileNotFoundError) as exception: ctx_obj = CtxCore() self.assertEqual(exception.exception, FileNotFoundError(ctx_obj.CONTEXT_FILE))