Exemplo n.º 1
0
 def _test_ensure_absent(is_present):
     name = 'example'
     tenant = ctera_portal_tenant.CteraPortalTenant()
     tenant.parameters = dict(name=name)
     tenant._ensure_absent(tenant.parameters if is_present else None)
     if is_present:
         tenant._ctera_portal.portals.delete.assert_called_once_with(name)
     else:
         tenant._ctera_portal.portals.delete.assert_not_called()
Exemplo n.º 2
0
 def _test__get_plan_name(self, exists):
     plan = {'name': 'Best', 'baseObjectRef': '/objs/1234'}
     tenant = ctera_portal_tenant.CteraPortalTenant()
     tenant._ctera_portal.get = mock.MagicMock(
         return_value=munch.Munch(plan) if exists else None)
     plan_name = tenant._get_plan_name(plan['baseObjectRef'])
     if exists:
         self.assertEqual(plan['name'], plan_name)
     else:
         self.assertIsNone(plan_name)
Exemplo n.º 3
0
 def _test_ensure_present(is_present):
     tenant = ctera_portal_tenant.CteraPortalTenant()
     tenant._handle_create = mock.MagicMock()
     tenant._handle_modify = mock.MagicMock()
     tenant._ensure_present({'name': 'example'} if is_present else None)
     if is_present:
         tenant._handle_modify.assert_called_once_with(mock.ANY)
         tenant._handle_create.assert_not_called()
     else:
         tenant._handle_create.assert_called_once_with()
         tenant._handle_modify.assert_not_called()
Exemplo n.º 4
0
 def _test__execute(is_present):
     tenant = ctera_portal_tenant.CteraPortalTenant()
     tenant.parameters = dict(state='present' if is_present else 'absent')
     tenant._get_tenant = mock.MagicMock(return_value=dict())
     tenant._ensure_present = mock.MagicMock()
     tenant._ensure_absent = mock.MagicMock()
     tenant._execute()
     if is_present:
         tenant._ensure_present.assert_called_once_with(mock.ANY)
         tenant._ensure_absent.assert_not_called()
     else:
         tenant._ensure_absent.assert_called_once_with(mock.ANY)
         tenant._ensure_present.assert_not_called()
Exemplo n.º 5
0
 def test__handle_create(self):
     parameters = dict(
         name='Example',
         display_name='Tenant for the Example Company Ltd',
         billing_id='123',
         company='Example Company Ltd',
         comment='Another comment',
         plan='Best',
     )
     tenant = ctera_portal_tenant.CteraPortalTenant()
     tenant.parameters = parameters
     tenant._handle_create()
     tenant._ctera_portal.portals.add.assert_called_with(**parameters)
Exemplo n.º 6
0
 def _test__handle_modify(is_deleted=False, change_attributes=False):
     current_attributes = dict(
         name='Example',
         display_name='Tenant for the Example Company Ltd',
         billing_id='123',
         company='Example Company Ltd',
         comment='Another comment',
         plan='Best',
         activation_status='Disabled' if is_deleted else 'Enabled')
     desired_attributes = copy.deepcopy(current_attributes)
     desired_attributes.pop('activation_status')
     if change_attributes:
         desired_attributes['billing_id'] = '456'
         desired_attributes['plan'] = 'Good'
     tenant = ctera_portal_tenant.CteraPortalTenant()
     tenant.parameters = desired_attributes
     tenant._ensure_present(current_attributes)
     if is_deleted:
         tenant._ctera_portal.portals.undelete.assert_called_with(
             desired_attributes['name'])
     if change_attributes:
         tenant._ctera_portal.portals.subscribe.assert_called_with(
             desired_attributes['name'], desired_attributes['plan'])
Exemplo n.º 7
0
    def test_get_tenant_exists(self):
        expected_tenant_dict = dict(
            name='Example',
            display_name='Tenant for the Example Company Ltd',
            billing_id='123',
            company='Example Company Ltd',
            comment='Another comment',
            plan='Best',
            activation_status='Enabled')
        tenant_obj_dict = copy.deepcopy(expected_tenant_dict)
        tenant_obj_dict['displayName'] = tenant_obj_dict.pop('display_name')
        tenant_obj_dict['externalPortalId'] = tenant_obj_dict.pop('billing_id')
        tenant_obj_dict['companyName'] = tenant_obj_dict.pop('company')
        tenant_obj_dict['activationStatus'] = tenant_obj_dict.pop(
            'activation_status')

        tenant = ctera_portal_tenant.CteraPortalTenant()
        tenant.parameters = dict(name=expected_tenant_dict['name'])
        tenant._ctera_portal.portals.get = mock.MagicMock(
            return_value=munch.Munch(tenant_obj_dict))
        tenant._ctera_portal.get = mock.MagicMock(return_value=munch.Munch(
            dict(baseObjectRef=tenant_obj_dict['plan'],
                 name=tenant_obj_dict['plan'])))
        self.assertDictEqual(expected_tenant_dict, tenant._get_tenant())
Exemplo n.º 8
0
 def test__get_tenant_doesnt_exist(self):
     tenant = ctera_portal_tenant.CteraPortalTenant()
     tenant.parameters = dict(name='example')
     tenant._ctera_portal.portals.get = mock.MagicMock(
         side_effect=CTERAException(response=munch.Munch(code=404)))
     self.assertIsNone(tenant._get_tenant())