]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: Add unit test for realm
authorAashish Sharma <aasharma@redhat.com>
Mon, 27 Mar 2023 13:36:21 +0000 (19:06 +0530)
committerAashish Sharma <aasharma@li-e74156cc-2f67-11b2-a85c-e98659a63c5c.ibm.com>
Thu, 10 Aug 2023 11:43:20 +0000 (17:13 +0530)
Fixes: https://tracker.ceph.com/issues/59171
Signed-off-by: Aashish Sharma <aasharma@redhat.com>
(cherry picked from commit eb56f2680c2b6fe8c8d0a930fae8aae6fee21801)

src/pybind/mgr/dashboard/controllers/rgw.py
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-realm-form/rgw-multisite-realm-form.component.spec.ts
src/pybind/mgr/dashboard/openapi.yaml
src/pybind/mgr/dashboard/requirements-test.txt
src/pybind/mgr/dashboard/services/rgw_client.py

index ffb757e86d49066d9671dd61a1f1cd3a9ca2d1d2..b5230a1fe39960af6f0670f5a525207e2c5e19a9 100644 (file)
@@ -748,7 +748,7 @@ class RgwRealm(RESTController):
 
     @allow_empty_body
     # pylint: disable=W0613
-    def set(self, realm_name: str, new_realm_name: str, default: str = None, daemon_name=None):
+    def set(self, realm_name: str, new_realm_name: str, default: str = '', daemon_name=None):
         try:
             instance = RgwClient.admin_instance(daemon_name=daemon_name)
             result = instance.edit_realm(realm_name, new_realm_name, default)
index ec3c052e4d177424f79a49d01aadbdd36866d30a..2c2ceedb0bc4e3ca6fca15d098e76266cf1704a1 100644 (file)
@@ -1,9 +1,15 @@
 import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { ReactiveFormsModule } from '@angular/forms';
+import { Router } from '@angular/router';
 import { RouterTestingModule } from '@angular/router/testing';
 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
+import _ from 'lodash';
+import { of as observableOf } from 'rxjs';
 import { ToastrModule } from 'ngx-toastr';
+import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
+import { NotificationType } from '~/app/shared/enum/notification-type.enum';
+import { NotificationService } from '~/app/shared/services/notification.service';
 import { SharedModule } from '~/app/shared/shared.module';
 
 import { RgwMultisiteRealmFormComponent } from './rgw-multisite-realm-form.component';
@@ -11,6 +17,7 @@ import { RgwMultisiteRealmFormComponent } from './rgw-multisite-realm-form.compo
 describe('RgwMultisiteRealmFormComponent', () => {
   let component: RgwMultisiteRealmFormComponent;
   let fixture: ComponentFixture<RgwMultisiteRealmFormComponent>;
+  let rgwRealmService: RgwRealmService;
 
   beforeEach(async () => {
     await TestBed.configureTestingModule({
@@ -35,4 +42,54 @@ describe('RgwMultisiteRealmFormComponent', () => {
   it('should create', () => {
     expect(component).toBeTruthy();
   });
+
+  describe('submit form', () => {
+    let notificationService: NotificationService;
+
+    beforeEach(() => {
+      spyOn(TestBed.inject(Router), 'navigate').and.stub();
+      notificationService = TestBed.inject(NotificationService);
+      spyOn(notificationService, 'show');
+      rgwRealmService = TestBed.inject(RgwRealmService);
+    });
+
+    it('should validate name', () => {
+      component.action = 'create';
+      component.createForm();
+      const control = component.multisiteRealmForm.get('realmName');
+      expect(_.isFunction(control.validator)).toBeTruthy();
+    });
+
+    it('should not validate name', () => {
+      component.action = 'edit';
+      component.createForm();
+      const control = component.multisiteRealmForm.get('realmName');
+      expect(control.asyncValidator).toBeNull();
+    });
+
+    it('tests create success notification', () => {
+      spyOn(rgwRealmService, 'create').and.returnValue(observableOf([]));
+      component.action = 'create';
+      component.multisiteRealmForm.markAsDirty();
+      component.submit();
+      expect(notificationService.show).toHaveBeenCalledWith(
+        NotificationType.success,
+        "Realm: 'null' created successfully"
+      );
+    });
+
+    it('tests update success notification', () => {
+      spyOn(rgwRealmService, 'update').and.returnValue(observableOf([]));
+      component.action = 'edit';
+      component.info = {
+        data: { name: 'null' }
+      };
+      component.multisiteRealmForm.markAsDirty();
+      component.submit();
+      expect(notificationService.show).toHaveBeenCalledWith(
+        NotificationType.success,
+        "Realm: 'null' updated successfully"
+      );
+    });
+  });
 });
index 1f79dd126705673f7d6235a82a03574d944038f7..f1a39c4df51260e3188be48633bbbea374669488 100644 (file)
@@ -8552,6 +8552,7 @@ paths:
                 daemon_name:
                   type: string
                 default:
+                  default: ''
                   type: string
                 new_realm_name:
                   type: string
index fe9dccbc44b5d650067dda09d9d1708b8a1e1a5e..4e925e8616f1ae63c5128278337c71aa7530bb92 100644 (file)
@@ -1,4 +1,4 @@
 pytest-cov
 pytest-instafail
 pyfakefs==4.5.0
-jsonschema==4.16.0
\ No newline at end of file
+jsonschema==4.16.0
index 829a0f5c1e380afe0ce0d9a2d97fa0cebeaf7bda..836531b65f9977da3ee78ee2675ce68eb5e5715f 100644 (file)
@@ -661,7 +661,7 @@ class RgwClient(RestClient):
         except SubprocessError as error:
             raise DashboardException(error, http_status_code=500, component='rgw')
 
-    def edit_realm(self, realm_name: str, new_realm_name: str, default: str = None):
+    def edit_realm(self, realm_name: str, new_realm_name: str, default: str = ''):
         rgw_realm_edit_cmd = []
         if new_realm_name != realm_name:
             rgw_realm_edit_cmd = ['realm', 'rename', '--rgw-realm',