def testGetScopeForPrefix(self): """Tests if the scope for a given prefix and key_name is returned. """ prefix = 'user' scope_returned = prefixes.getScopeForPrefix(prefix, self.user.key.id()) self.assertEqual(scope_returned.key.id(), self.user.key.id()) self.assertEqual(type(scope_returned), type(self.user)) prefix = 'site' key_name = self.site_key_name scope_returned = prefixes.getScopeForPrefix(prefix, key_name) self.assertEqual(scope_returned.key().name(), key_name) self.assertEqual(type(scope_returned), type(self.site)) prefix = 'org' key_name = self.org_key_name scope_returned = prefixes.getScopeForPrefix(prefix, key_name) self.assertEqual(scope_returned.key().name(), key_name) self.assertEqual(type(scope_returned), type(self.organization)) prefix = 'gsoc_org' key_name = self.gsoc_org_key_name scope_returned = prefixes.getScopeForPrefix(prefix, key_name) self.assertEqual(scope_returned.key.id(), key_name) self.assertEqual(type(scope_returned), type(self.gsoc_organization)) prefix = 'gci_org' key_name = self.gci_org_key_name scope_returned = prefixes.getScopeForPrefix(prefix, key_name) self.assertEqual(scope_returned.key().name(), key_name) self.assertEqual(type(scope_returned), type(self.gci_organization)) prefix = 'program' key_name = self.program_key_name scope_returned = prefixes.getScopeForPrefix(prefix, key_name) self.assertEqual(scope_returned.key().name(), key_name) self.assertEqual(type(scope_returned), type(self.program)) prefix = 'gsoc_program' key_name = self.gsoc_program_key_name scope_returned = prefixes.getScopeForPrefix(prefix, key_name) self.assertEqual(scope_returned.key().name(), key_name) self.assertEqual(type(scope_returned), type(self.gsoc_program)) prefix = 'gci_program' key_name = self.gci_program_key_name scope_returned = prefixes.getScopeForPrefix(prefix, key_name) self.assertEqual(scope_returned.key().name(), key_name) self.assertEqual(type(scope_returned), type(self.gci_program)) #When prefix is invalid. prefix = 'invalid_prefix' key_name = 'some_key_name' with self.assertRaises(ValueError): prefixes.getScopeForPrefix(prefix, key_name)
def validateForm(data, document_form): if not document_form.is_valid(): return cleaned_data = document_form.cleaned_data cleaned_data['modified_by'] = data.ndb_user.key.to_old_key() if data.document: document = document_form.save() else: prefix = data.kwargs['prefix'] cleaned_data['link_id'] = data.kwargs['document'] cleaned_data['author'] = data.ndb_user.key.to_old_key() cleaned_data['prefix'] = prefix if prefix in ['gsoc_program', 'gci_program']: scope_key_name = '%s/%s' % (data.kwargs['sponsor'], data.kwargs['program']) else: scope_key_name = '%s/%s/%s' % (data.kwargs['sponsor'], data.kwargs['program'], data.kwargs['organization']) cleaned_data['scope'] = prefixes.getScopeForPrefix( prefix, scope_key_name) document = document_form.create(key_name=data.key_name) return document
def validateForm(data, document_form): if not document_form.is_valid(): return cleaned_data = document_form.cleaned_data cleaned_data['modified_by'] = data.ndb_user.key.to_old_key() if data.document: document = document_form.save() else: prefix = data.kwargs['prefix'] cleaned_data['link_id'] = data.kwargs['document'] cleaned_data['author'] = data.ndb_user.key.to_old_key() cleaned_data['prefix'] = prefix if prefix in ['gsoc_program', 'gci_program']: scope_key_name = '%s/%s' % ( data.kwargs['sponsor'], data.kwargs['program']) else: scope_key_name = '%s/%s/%s' % ( data.kwargs['sponsor'], data.kwargs['program'], data.kwargs['organization']) cleaned_data['scope'] = prefixes.getScopeForPrefix(prefix, scope_key_name) document = document_form.create(key_name=data.key_name) return document
def validateForm(data, document_form): if not document_form.is_valid(): return cleaned_data = document_form.cleaned_data cleaned_data['modified_by'] = data.user if data.document: document = document_form.save() else: prefix = data.kwargs['prefix'] cleaned_data['link_id'] = data.kwargs['document'] cleaned_data['author'] = data.user cleaned_data['prefix'] = prefix cleaned_data['scope'] = prefixes.getScopeForPrefix(prefix, data.scope_path) cleaned_data['scope_path'] = data.scope_path document = document_form.create(key_name=data.key_name) return document
def validate(self): document_form = DocumentForm(self.data.POST, instance=self.data.document) if not document_form.is_valid(): return data = document_form.cleaned_data data['modified_by'] = self.data.user if self.data.document: document = document_form.save() else: prefix = self.kwargs['prefix'] data['link_id'] = self.kwargs['document'] data['author'] = self.data.user data['prefix'] = prefix data['scope'] = prefixes.getScopeForPrefix(prefix, self.data.scope_path) data['scope_path'] = self.data.scope_path document = document_form.create(key_name=self.data.key_name) return document