Permalink
Browse files

remove junk

  • Loading branch information...
1 parent 92cc05d commit 7a14c4ab1e229711c1325b1d29e74327e899848e @fafhrd91 committed Nov 8, 2012
Showing with 1 addition and 307 deletions.
  1. +1 −0 .gitignore
  2. +0 −54 pform/tests/base.py.bak
  3. +0 −253 pform/tests/test_fieldset.py.bak
View
1 .gitignore
@@ -2,6 +2,7 @@
*.egg-info
*.pyc
*.pyo
+*.bak
.DS_Store
.coverage
.noseids
View
54 pform/tests/base.py.bak
@@ -1,54 +0,0 @@
-import sys
-from pyramid import testing
-from pyramid.interfaces import IRequest
-from pyramid.interfaces import IRequestExtensions
-
-if sys.version_info[:2] == (2, 6):
- from unittest2 import TestCase
-else:
- from unittest import TestCase
-
-
-class BaseTestCase(TestCase):
-
- _settings = {}
- _environ = {
- 'wsgi.url_scheme':'http',
- 'wsgi.version':(1,0),
- 'HTTP_HOST': 'example.com',
- 'SCRIPT_NAME': '',
- 'PATH_INFO': '/'}
- registry = None
-
- def setUp(self):
- self.init_pyramid()
-
- def make_request(self, registry=None,
- environ=None, request_iface=IRequest, **kwargs):
- if registry is None:
- registry = self.registry
- if environ is None:
- environ=self._environ
- request = testing.DummyRequest(environ=dict(environ), **kwargs)
- request.request_iface = IRequest
- request.registry = registry
- request._set_extensions(registry.getUtility(IRequestExtensions))
- return request
-
- def init_extensions(self, registry):
- from pyramid.config.factories import _RequestExtensions
-
- exts = registry.queryUtility(IRequestExtensions)
- if exts is None:
- exts = _RequestExtensions()
- self.registry.registerUtility(exts, IRequestExtensions)
-
- def init_pyramid(self):
- self.config = testing.setUp(settings=self._settings, autocommit=True)
- self.config.get_routes_mapper()
- self.config.include('player')
- self.config.include('pform')
- self.init_extensions(self.config.registry)
-
- self.registry = self.config.registry
- self.request = self.make_request()
View
253 pform/tests/test_fieldset.py.bak
@@ -1,253 +0,0 @@
-"""
-Unit tests for L{pform.fieldset}
-"""
-import pform
-from base import BaseTestCase
-
-
-field = pform.TextField(
- 'test', title = 'Test node')
-
-field1 = pform.TextField(
- 'test1', title = 'Test node')
-
-
-class TestFieldset(BaseTestCase):
-
- def test_fieldset_name_title(self):
- fieldset = pform.Fieldset(field)
-
- self.assertEqual(fieldset.name, '')
- self.assertEqual(fieldset.title, '')
- self.assertEqual(fieldset.prefix, '')
-
- fieldset = pform.Fieldset(field1, name='othername', title='Other name')
-
- self.assertEqual(fieldset.name, 'othername')
- self.assertEqual(fieldset.title, 'Other name')
-
- def test_fieldset_nested(self):
- fieldset = pform.Fieldset(
- field,
- pform.Fieldset(name='fs', *(field,)))
-
- self.assertEqual(fieldset['fs'].name, 'fs')
- self.assertEqual(fieldset['fs'].prefix, 'fs.')
-
- def test_fieldset_fields(self):
- fieldset = pform.Fieldset(field, field1)
-
- self.assertEqual(list(fieldset.fields()), [field, field1])
-
- def test_fieldset_append_simple(self):
- fieldset = pform.Fieldset(field, name='test')
-
- self.assertIn('test', fieldset)
- self.assertEqual(fieldset.prefix, 'test.')
-
- self.assertIs(fieldset['test'], field)
-
- self.assertRaises(ValueError, fieldset.append, field)
- self.assertRaises(TypeError, fieldset.append, object())
-
- def test_fieldset_append_fieldset(self):
- fieldset = pform.Fieldset(field, name='schema')
- self.assertEqual(list(fieldset.fieldsets()), [fieldset])
-
- fs = pform.Fieldset(field1, name='schema2', )
-
- fieldset.append(fs)
- self.assertEqual(len(list(fieldset.fieldsets())), 2)
-
- self.assertIn('schema2', fieldset)
- self.assertIs(fieldset['schema2'], fs)
- self.assertRaises(ValueError, fieldset.append, fs)
-
- def test_fieldset_select(self):
- fieldset = pform.Fieldset(field, field1)
-
- newfs = fieldset.select('test')
- self.assertNotIn('test1', newfs)
- self.assertEqual(list(newfs.keys()), ['test'])
-
- def test_fieldset_omit(self):
- fieldset = pform.Fieldset(field, field1)
-
- newfs = fieldset.omit('test')
- self.assertNotIn('test', newfs)
- self.assertEqual(list(newfs.keys()), ['test1'])
-
- def test_fieldset_add(self):
- fieldset = pform.Fieldset(field)
- fieldset = fieldset + pform.Fieldset(field1)
-
- self.assertIn('test', fieldset)
- self.assertIn('test1', fieldset)
- self.assertEqual(list(fieldset.keys()), ['test', 'test1'])
-
- def test_fieldset_iadd(self):
- fieldset = pform.Fieldset(field)
- fieldset += pform.Fieldset(field1)
-
- self.assertIn('test', fieldset)
- self.assertIn('test1', fieldset)
- self.assertEqual(list(fieldset.keys()), ['test', 'test1'])
-
- def test_fieldset_add_err(self):
- fieldset = pform.Fieldset(field)
-
- self.assertRaises(ValueError, fieldset.__add__, object())
-
- def test_fieldset_bind(self):
- fieldset = pform.Fieldset(field)
-
- request = object()
- params = object()
- data = {'test': 'CONTENT'}
-
- fs = fieldset.bind(request, data, params)
-
- self.assertIsNot(fieldset, fs)
- self.assertEqual(len(fieldset), len(fs))
- self.assertIs(fs.request, request)
- self.assertIs(fs.params, params)
- self.assertIs(fs.data, data)
-
- self.assertIs(fs['test'].params, params)
- self.assertEqual(fs['test'].value, 'CONTENT')
-
- fs = fieldset.bind(request)
- self.assertIsNot(fieldset, fs)
- self.assertEqual(len(fieldset), len(fs))
- self.assertEqual(fs.params, {})
- self.assertEqual(fs.data, {})
- self.assertEqual(fs['test'].params, {})
- self.assertIs(fs['test'].value, pform.null)
-
- def test_fieldset_bind_nested(self):
- fieldset = pform.Fieldset(
- field,
- pform.Fieldset(name='fs', *(field,)))
-
- request = object()
- params = object()
- content = {'test': 'CONTENT',
- 'fs': {'test': 'NESTED CONTENT'}}
-
- fs = fieldset.bind(request, content, params)
-
- self.assertIs(fs['fs'].request, request)
- self.assertEqual(fs['fs']['test'].value, 'NESTED CONTENT')
-
- fs = fieldset.bind(request)
- self.assertIs(fs['fs']['test'].value, pform.null)
-
- def test_fieldset_validate(self):
- def validator(fs, data):
- raise pform.Invalid(fs, 'msg')
-
- fieldset = pform.Fieldset(field, validator=validator)
- self.assertRaises(pform.Invalid, fieldset.validate, {})
-
- fieldset.bind(object())
- self.assertRaises(pform.Invalid, fieldset.validate, {})
-
- def _makeOne(self, name, **kw):
- class MyField(pform.Field):
- def to_request(self, value):
- return value
- def from_request(self, value):
- return value
-
- return MyField(name, **kw)
-
- def test_fieldset_extract_display(self):
- field = self._makeOne('test', mode=pform.FORM_DISPLAY)
- fieldset = pform.Fieldset(field).bind(object(), None, {'test': 'VALUE'})
- data, errors = fieldset.extract()
- self.assertEqual(data, {})
- self.assertEqual(errors, [])
-
- def test_fieldset_extract_missing(self):
- field = self._makeOne('test')
- fieldset = pform.Fieldset(field).bind(object())
-
- data, errors = fieldset.extract()
- self.assertIs(errors[0].field, fieldset['test'])
- self.assertEqual(errors[0].msg, 'Required')
-
- def test_fieldset_extract_missing_nested(self):
- field = self._makeOne('test')
- fieldset = pform.Fieldset(
- field,
- pform.Fieldset(name='fs', *(field,))).bind(object())
-
- data, errors = fieldset.extract()
- self.assertIs(errors[0].field, fieldset['fs']['test'])
- self.assertIs(errors[1].field, fieldset['test'])
- self.assertEqual(errors[0].msg, 'Required')
- self.assertEqual(errors[1].msg, 'Required')
-
- def test_fieldset_extract(self):
- request = object()
- field = self._makeOne('test')
- fieldset = pform.Fieldset(field).bind(object(), params={'test': 'FORM'})
-
- data, errors = fieldset.extract()
- self.assertFalse(bool(errors))
- self.assertEqual(data['test'], 'FORM')
-
- def test_fieldset_extract_nested(self):
- field = self._makeOne('test')
- fieldset = pform.Fieldset(
- field,
- pform.Fieldset(name='fs', *(field,))
- ).bind(object, params={'test': 'FORM', 'fs.test': 'NESTED FORM'})
-
- data, errors = fieldset.extract()
- self.assertFalse(bool(errors))
- self.assertEqual(data['test'], 'FORM')
- self.assertEqual(data['fs']['test'], 'NESTED FORM')
-
- def test_fieldset_extract_preparer(self):
- def lower(val):
- return val.lower()
-
- field = self._makeOne('test', preparer=lower)
- fieldset = pform.Fieldset(field).bind(object, params={'test': 'FORM'})
-
- data, errors = fieldset.extract()
- self.assertEqual(data['test'], 'form')
-
- def test_fieldset_extract_validate(self):
- def validator(fs, data):
- raise pform.Invalid(fs, 'msg')
-
- field = self._makeOne('test')
- fieldset = pform.Fieldset(field, validator=validator)
- fieldset = fieldset.bind(object, params={'test': 'FORM'})
-
- data, errors = fieldset.extract()
- self.assertEqual(len(errors), 1)
-
-
-class TestFieldsetErrors(BaseTestCase):
-
- def test_fieldset_errors(self):
- err1 = pform.Invalid(field, 'error1')
- err2 = pform.Invalid(field1, 'error2')
-
- fieldset = object()
-
- errors = pform.FieldsetErrors(fieldset, err1, err2)
- self.assertIn(err1, errors)
- self.assertIn(err2, errors)
- self.assertIs(errors.fieldset, fieldset)
- self.assertEqual(errors.msg, {'test': 'error1', 'test1': 'error2'})
-
- self.assertEqual(str(err1), "Invalid: <TextField 'test'>: <error1>")
- self.assertEqual(repr(err1), "Invalid(<TextField 'test'>: <error1>)")
- self.assertEqual(str(pform.null), '<widget.null>')
-
- self.assertFalse(bool(pform.required))
- self.assertEqual(repr(pform.required), '<widget.required>')

0 comments on commit 7a14c4a

Please sign in to comment.