def testCleanUserAccount(self):
   """Test that user account can be cleaned.
   """
   field_name = 'user_account'
   clean_field = cleaning.clean_user_account(field_name)
   # Test that a new account will be returned if the value of field is
   # a valid new email address
   field_value = '*****@*****.**'
   self.form.cleaned_data = {field_name: field_value}
   cleaned_data_after = clean_field(self.form)
   self.assertEqual(cleaned_data_after.email(), field_value)
   # Test that the existing account will be returned if the value of field is
   # an existent user's email address
   field_value = self.user.account.email()
   self.form.cleaned_data = {field_name: field_value}
   cleaned_data_after = clean_field(self.form)
   self.assertEqual(cleaned_data_after.email(), field_value)
   self.assertEqual(cleaned_data_after, self.user.account)
   # Test that a new account will be returned even if the value of field is
   # an invalid email address
   field_value = 'invalid_*mail'
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form).email(), field_value)
 def testCleanUserAccount(self):
     """Test that user account can be cleaned.
 """
     field_name = 'user_account'
     clean_field = cleaning.clean_user_account(field_name)
     # Test that a new account will be returned if the value of field is
     # a valid new email address
     field_value = '*****@*****.**'
     self.form.cleaned_data = {field_name: field_value}
     cleaned_data_after = clean_field(self.form)
     self.assertEqual(cleaned_data_after.email(), field_value)
     # Test that the existing account will be returned if the value of field is
     # an existent user's email address
     field_value = self.user.account.email()
     self.form.cleaned_data = {field_name: field_value}
     cleaned_data_after = clean_field(self.form)
     self.assertEqual(cleaned_data_after.email(), field_value)
     self.assertEqual(cleaned_data_after, self.user.account)
     # Test that a new account will be returned even if the value of field is
     # an invalid email address
     field_value = 'invalid_*mail'
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form).email(), field_value)
Exemple #3
0
  def __init__(self, params=None):
    """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

    Params:
      params: a dict with params for this View
    """

    rights = access.Checker(params)
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = ['checkIsDeveloper']
    rights['delete'] = ['checkIsDeveloper']
    rights['show'] = ['allow']
    rights['list'] = ['checkIsDeveloper']
    rights['list_developers'] = ['checkIsDeveloper']

    new_params = {}
    new_params['logic'] = soc.logic.models.user.logic
    new_params['rights'] = rights
    
    new_params['name'] = "User"

    new_params['edit_template'] = 'soc/user/edit.html'
    new_params['pickable'] = True
    new_params['cache_pick'] = True

    new_params['sidebar_heading'] = 'Users'

    new_params['extra_dynaexclude'] = ['former_accounts', 'agreed_to_tos',
        'agreed_to_tos_on', 'status']
    new_params['create_extra_dynaproperties'] = {
        'clean_link_id': cleaning.clean_user_not_exist('link_id'),
        'clean_account': cleaning.clean_user_account_not_in_use('account')}

    # recreate the choices for the edit form
    status_choices = []
    for choice in user_logic.getModel().status.choices:
      status_choices.append((choice, choice))

    new_params['edit_extra_dynaproperties'] = {
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
            required=True),
        'clean_link_id': cleaning.clean_link_id('link_id'),
        'agreed_to_tos_on': forms.DateTimeField(
            widget=widgets.ReadOnlyInput(attrs={'disabled':'true'}),
            required=False),
        'status': forms.ChoiceField(choices=status_choices),
        'clean_account': cleaning.clean_user_account('account'),
        'clean': cleaning.validate_user_edit('link_id', 'account'),
    }

    patterns = []

    patterns += [(r'^%(url_name)s/(?P<access_type>list_developers)$',
                  'soc.views.models.%(module_name)s.list_developers', 
                  "List Developers")]

    new_params['extra_django_patterns'] = patterns

    new_params['sidebar_developer'] = [('/%s/list_developers', 'List Developers',
                                        'list_developers')]

    new_params['public_field_prefetch'] = ['account']
    new_params['public_field_extra'] = lambda entity: {
        "email": entity.account.email(),
    }
    new_params['public_field_keys'] = ['email', 'name', 'link_id']
    new_params['public_field_names'] = ['Email', 'Public name', 'Link ID']

    params = dicts.merge(params, new_params)

    super(View, self).__init__(params=params)