]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Add unit test for realm 50529/head
authorAashish Sharma <aasharma@redhat.com>
Mon, 27 Mar 2023 13:36:21 +0000 (19:06 +0530)
committeravanthakkar <avanjohn@gmail.com>
Tue, 28 Mar 2023 06:56:17 +0000 (12:26 +0530)
Fixes: https://tracker.ceph.com/issues/59171
Signed-off-by: Aashish Sharma <aasharma@redhat.com>
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 a7c9cb9ac8ef1d3430f4aad3d75a4c9ba0d826a3..eb71504dbf4c7a32e090b2b3246c25113be611f0 100644 (file)
@@ -704,7 +704,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 00ad59bb1e69493dbdce6476818f2aa392330f2e..9b0cd30ce242d4b99aa4d2370e8820da87f4ce73 100644 (file)
@@ -8317,6 +8317,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 6b073586387237e46423e9476c8e6aa74f5879d2..214c435da2c851b10eb82cd03a8824c686329616 100644 (file)
@@ -660,7 +660,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',