Example #1
0
 def testCleanAgreesToTos(self):
     """Tests that the agrees_to_tos field can be cleaned.
 """
     field_name = 'agrees_to_tos'
     clean_field = cleaning.clean_agrees_to_tos(field_name)
     # Test that the value of the field will be returned
     # if there is no tos document
     field_value = 'Any value'
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form), field_value)
     site = site_logic.getSingleton()
     document_properties = {
         'link_id': 'a_tos',
         'scope_path': site.link_id,
         'scope': site,
         'prefix': 'site',
         'author': self.user,
         'title': 'Home Page',
         'short_name': 'Home',
         'content': 'This is the Home Page',
         'modified_by': self.user,
     }
     document = document_logic.updateOrCreateFromFields(document_properties)
     site.tos = document
     site.put()
     # Test that True will be returned if there is a tos document and
     # the value of the field is not empty
     field_value = 'Any value'
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form), True)
     # Test that None will be returned instead of ValidationError if there is
     # a tos document and the value of the field is empty
     field_value = ''
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form), None)
     #self.assertRaises(forms.ValidationError, clean_field, self.form)
     # Test that None will be returned instead of ValidationError if there is
     # a tos document and the value of the field is False
     field_value = False
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form), None)
Example #2
0
 def testCleanAgreesToTos(self):
   """Tests that the agrees_to_tos field can be cleaned.
   """
   field_name = 'agrees_to_tos'
   clean_field = cleaning.clean_agrees_to_tos(field_name)
   # Test that the value of the field will be returned
   # if there is no tos document
   field_value = 'Any value'
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form), field_value)
   site = site_logic.getSingleton()
   document_properties = {
       'link_id': 'a_tos',
       'scope_path': site.link_id,
       'scope': site,
       'prefix': 'site',
       'author': self.user,
       'title': 'Home Page',
       'short_name': 'Home',
       'content': 'This is the Home Page',
       'modified_by': self.user,
       }
   document = document_logic.updateOrCreateFromFields(document_properties)
   site.tos = document
   site.put()
   # Test that True will be returned if there is a tos document and
   # the value of the field is not empty
   field_value = 'Any value'
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form), True)
   # Test that None will be returned instead of ValidationError if there is
   # a tos document and the value of the field is empty
   field_value = ''
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form), None)
   #self.assertRaises(forms.ValidationError, clean_field, self.form)
   # Test that None will be returned instead of ValidationError if there is
   # a tos document and the value of the field is False
   field_value = False
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form), None)
Example #3
0
  def _postCreate(self, request, entity):
    """See base.View._postCreate.
    """

    from soc.logic.models.document import logic as document_logic

    bold = lambda x: "<b>%s</b>: " % x

    parts = [
        bold("Name") + entity.name,
        bold("Registered by") + entity.founder.name,
        bold("Home page url") + str(entity.home_page),
        bold("Email") + entity.email,
        bold("Public mailing list") + entity.pub_mailing_list,
        bold("Public irc channel") + entity.irc_channel ,
        bold("Description") + entity.description ,
        bold("Development mailing list") + entity.dev_mailing_list,
        bold("Ideas list") + str(entity.ideas),
        bold("Application template") + entity.contrib_template,
        ]
    content = '<br/>'.join(parts)

    home_document = document_logic.updateOrCreateFromFields({
        'link_id': 'home',
        'scope_path': entity.key().id_or_name(),
        'scope': entity,
        'author': entity.founder,
        'title': 'Home Page for %s' % entity.name,
        'short_name': 'Home',
        'content': content,
        'prefix': self._params['document_prefix'],
        'read_access': 'public',
        'write_access': 'admin',
        'home_for': entity,
        'modified_by': entity.founder,
        })

    self._logic.updateEntityProperties(entity, {'home': home_document})

    super(View, self)._postCreate(request, entity)
Example #4
0
 def testCleanRefs(self):
     """Tests that references can be cleaned.
 """
     document_prefix = 'site'
     params = {'logic': site_logic, 'document_prefix': document_prefix}
     fields = ['ref']
     clean_field = cleaning.clean_refs(params, fields)
     # Test that the format of the value of field is not validated, i.e.
     # no exception is raised even if the filled document link_id
     # is not a valid link_id
     document_link_id = 'v1_@?'
     site = site_logic.getSingleton()
     self.form.cleaned_data = {
         'link_id': site.link_id,
         'scope_path': site.scope_path,
         'ref': document_link_id,
     }
     self.form._errors = {fields[0]: None}
     clean_field(self.form)
     # Test that the value of field will be removed and error information
     # will be added to _errors field if it is a valid but nonexistent
     # document link_id
     document_link_id = 'a_document'
     site = site_logic.getSingleton()
     self.form.cleaned_data = {
         'link_id': site.link_id,
         'scope_path': site.scope_path,
         'ref': document_link_id,
     }
     self.form._errors = {fields[0]: None}
     after_cleaned_data = clean_field(self.form)
     self.assertEqual(after_cleaned_data.get('ref', None), None)
     self.assertNotEqual(self.form._errors[fields[0]], None)
     # Test that the value of field will be returned, a field named resolved_ref
     # containing the document will be added and no error messges will be added
     # if it is a valid and exisiting document link_id
     document_link_id = 'a_document'
     site = site_logic.getSingleton()
     self.form.cleaned_data = {
         'link_id': site.link_id,
         'scope_path': site.scope_path,
         'ref': document_link_id,
     }
     self.form._errors = {fields[0]: None}
     document_properties = {
         'link_id': document_link_id,
         'scope_path': site.link_id,
         'scope': site,
         'prefix': document_prefix,
         'author': self.user,
         'title': 'Home Page',
         'short_name': 'Home',
         'content': 'This is the Home Page',
         'modified_by': self.user,
     }
     document = document_logic.updateOrCreateFromFields(document_properties)
     after_cleaned_data = clean_field(self.form)
     self.assertEqual(after_cleaned_data['ref'], document_link_id)
     self.assertEqual(after_cleaned_data['resolved_ref'].link_id,
                      document_link_id)
     self.assertEqual(self.form._errors[fields[0]], None)
Example #5
0
 def testCleanRefs(self):
   """Tests that references can be cleaned.
   """
   document_prefix = 'site'
   params = {'logic': site_logic, 'document_prefix': document_prefix}
   fields = ['ref']
   clean_field = cleaning.clean_refs(params, fields)
   # Test that the format of the value of field is not validated, i.e. 
   # no exception is raised even if the filled document link_id 
   # is not a valid link_id
   document_link_id = 'v1_@?'
   site = site_logic.getSingleton()
   self.form.cleaned_data = {
       'link_id': site.link_id,
       'scope_path': site.scope_path,
       'ref': document_link_id,
       }
   self.form._errors = {fields[0]: None}
   clean_field(self.form)
   # Test that the value of field will be removed and error information 
   # will be added to _errors field if it is a valid but nonexistent 
   # document link_id
   document_link_id = 'a_document'
   site = site_logic.getSingleton()
   self.form.cleaned_data = {
       'link_id': site.link_id,
       'scope_path': site.scope_path,
       'ref': document_link_id,
       }
   self.form._errors = {fields[0]: None}
   after_cleaned_data = clean_field(self.form)
   self.assertEqual(after_cleaned_data.get('ref', None), None)
   self.assertNotEqual(self.form._errors[fields[0]], None)
   # Test that the value of field will be returned, a field named resolved_ref
   # containing the document will be added and no error messges will be added 
   # if it is a valid and exisiting document link_id
   document_link_id = 'a_document'
   site = site_logic.getSingleton()
   self.form.cleaned_data = {
       'link_id': site.link_id,
       'scope_path': site.scope_path,
       'ref': document_link_id,
       }
   self.form._errors = {fields[0]: None}
   document_properties = {
       'link_id': document_link_id,
       'scope_path': site.link_id,
       'scope': site,
       'prefix': document_prefix,
       'author': self.user,
       'title': 'Home Page',
       'short_name': 'Home',
       'content': 'This is the Home Page',
       'modified_by': self.user,
       }
   document = document_logic.updateOrCreateFromFields(document_properties)
   after_cleaned_data = clean_field(self.form)
   self.assertEqual(after_cleaned_data['ref'], document_link_id)
   self.assertEqual(after_cleaned_data['resolved_ref'].link_id, 
                    document_link_id)
   self.assertEqual(self.form._errors[fields[0]], None)