def test_missing_group_for_customer_is_created(self, mock_client): customer = structure_factories.CustomerFactory(name='customer') mock_client().group_find.return_value = {'result': []} FreeIPABackend().synchronize_groups() mock_client().group_add.assert_called_once_with( 'waldur_org_%s' % customer.uuid.hex, description='customer,-1.0', )
def test_backend_is_called_with_correct_parameters_if_update_gecos( self, mock_client): FreeIPABackend().update_gecos(self.profile) mock_client().user_mod.assert_called_once_with( self.profile.username, gecos=','.join( [self.user.full_name, self.user.email, self.user.phone_number]), )
def test_stale_groups_are_removed(self, mock_client): mock_client().group_find.return_value = { 'result': [{ 'cn': ['waldur_stale_customer'], }] } FreeIPABackend().synchronize_groups() mock_client().group_del.assert_called_once_with( 'waldur_stale_customer')
def test_missing_group_for_project_is_created(self, mock_client): project = structure_factories.ProjectFactory(name='project') mock_client().group_find.return_value = {'result': []} FreeIPABackend().synchronize_groups() mock_client().group_add.has_calls([ mock.call( 'waldur_project_%s' % project.uuid.hex, description='project,-1.0', ) ])
def test_missing_children_are_added_to_customer_group(self, mock_client): fixture = structure_fixtures.ProjectFixture() customer = fixture.customer project = fixture.project mock_client().group_find.return_value = {'result': []} FreeIPABackend().synchronize_groups() mock_client().group_add_member.assert_called_once_with( 'waldur_org_%s' % customer.uuid.hex, groups=['waldur_project_%s' % project.uuid], skip_errors=True, )
def test_project_quota_is_serialized_as_group_description(self, mock_client): project = structure_factories.ProjectFactory(name='project') quota_models.Quota.objects.create(scope=project, limit=100) mock_client().group_find.return_value = { 'result': [] } FreeIPABackend().synchronize_groups() mock_client().group_add.has_calls([mock.call( 'waldur_project_%s' % project.uuid, description='project,100', )])
def test_customer_quota_is_serialized_as_group_description(self, mock_client): customer = structure_factories.CustomerFactory(name='customer') quota_models.Quota.objects.create(scope=customer, limit=100) mock_client().group_find.return_value = { 'result': [] } FreeIPABackend().synchronize_groups() mock_client().group_add.has_calls([mock.call( 'waldur_org_%s' % customer.uuid, description='customer,100', )])
def test_missing_users_are_added_to_customer_group(self, mock_client): fixture = structure_fixtures.CustomerFixture() customer = fixture.customer owner = fixture.owner models.Profile.objects.create(user=owner, username=owner.username) mock_client().group_find.return_value = {'result': []} FreeIPABackend().synchronize_groups() mock_client().group_add_member.assert_called_once_with( 'waldur_org_%s' % customer.uuid.hex, users=[owner.username], skip_errors=True, )
def test_group_description_is_updated_from_project_name(self, mock_client): project = structure_factories.ProjectFactory(name='project') mock_client().group_find.return_value = { 'result': [{ 'cn': ['waldur_project_%s' % project.uuid], 'description': ['New project name'], }] } FreeIPABackend().synchronize_groups() mock_client().group_mod.assert_called_once_with( 'waldur_project_%s' % project.uuid.hex, description='project,-1.0', )
def test_group_description_is_updated_from_customer_name( self, mock_client): customer = structure_factories.CustomerFactory(name='customer') mock_client().group_find.return_value = { 'result': [{ 'cn': ['waldur_org_%s' % customer.uuid], 'description': ['New customer name'], }] } FreeIPABackend().synchronize_groups() mock_client().group_mod.assert_called_once_with( 'waldur_org_%s' % customer.uuid.hex, description='customer,-1.0', )
def test_stale_children_are_removed_from_customer_group(self, mock_client): customer = structure_factories.CustomerFactory() mock_client().group_find.return_value = { 'result': [{ 'cn': ['waldur_org_%s' % customer.uuid], 'member_group': ['waldur_stale_child'], }] } FreeIPABackend().synchronize_groups() mock_client().group_remove_member.assert_called_once_with( 'waldur_org_%s' % customer.uuid.hex, groups=['waldur_stale_child'], skip_errors=True, )
def get_or_create_profile(user, username, password): profile = Profile.objects.filter(user=user).first() if profile: return profile, False profile = Profile.objects.create( user=user, username=username, ) try: FreeIPABackend().create_profile(profile, password=password) tasks.schedule_sync() except freeipa_exceptions.DuplicateEntry: pass return profile, True
def test_backend_is_called_with_correct_parameters_if_update_full_name( self, names, mock_client): full_name = names[0] first_name = names[1] last_name = names[2] user = self.profile.user user.full_name = full_name user.first_name = first_name user.last_name = last_name user.save() self.profile.refresh_from_db() FreeIPABackend().update_name(self.profile) mock_client().user_mod.assert_called_once_with( self.profile.username, cn=full_name, displayname=full_name, givenname=first_name or 'N/A', sn=last_name or 'N/A', )