more test cov
This commit is contained in:
		@@ -184,9 +184,6 @@ class DocumentMetaclass(type):
 | 
			
		||||
                if issubclass(new_class, EmbeddedDocument):
 | 
			
		||||
                    raise InvalidDocumentError('CachedReferenceFields is not '
 | 
			
		||||
                                               'allowed in EmbeddedDocuments')
 | 
			
		||||
                if not f.document_type:
 | 
			
		||||
                    raise InvalidDocumentError(
 | 
			
		||||
                        'Document is not available to sync')
 | 
			
		||||
 | 
			
		||||
                if f.auto_sync:
 | 
			
		||||
                    f.start_listener()
 | 
			
		||||
 
 | 
			
		||||
@@ -31,7 +31,6 @@ def _import_class(cls_name):
 | 
			
		||||
 | 
			
		||||
    field_classes = _field_list_cache
 | 
			
		||||
 | 
			
		||||
    queryset_classes = ('OperationError',)
 | 
			
		||||
    deref_classes = ('DeReference',)
 | 
			
		||||
 | 
			
		||||
    if cls_name == 'BaseDocument':
 | 
			
		||||
@@ -43,14 +42,11 @@ def _import_class(cls_name):
 | 
			
		||||
    elif cls_name in field_classes:
 | 
			
		||||
        from mongoengine import fields as module
 | 
			
		||||
        import_classes = field_classes
 | 
			
		||||
    elif cls_name in queryset_classes:
 | 
			
		||||
        from mongoengine import queryset as module
 | 
			
		||||
        import_classes = queryset_classes
 | 
			
		||||
    elif cls_name in deref_classes:
 | 
			
		||||
        from mongoengine import dereference as module
 | 
			
		||||
        import_classes = deref_classes
 | 
			
		||||
    else:
 | 
			
		||||
        raise ValueError('No import set for: ' % cls_name)
 | 
			
		||||
        raise ValueError('No import set for: %s' % cls_name)
 | 
			
		||||
 | 
			
		||||
    for cls in import_classes:
 | 
			
		||||
        _class_registry_cache[cls] = getattr(module, cls)
 | 
			
		||||
 
 | 
			
		||||
@@ -152,12 +152,10 @@ class URLField(StringField):
 | 
			
		||||
        scheme = value.split('://')[0].lower()
 | 
			
		||||
        if scheme not in self.schemes:
 | 
			
		||||
            self.error(u'Invalid scheme {} in URL: {}'.format(scheme, value))
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        # Then check full URL
 | 
			
		||||
        if not self.url_regex.match(value):
 | 
			
		||||
            self.error(u'Invalid URL: {}'.format(value))
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class EmailField(StringField):
 | 
			
		||||
@@ -259,10 +257,10 @@ class EmailField(StringField):
 | 
			
		||||
            try:
 | 
			
		||||
                domain_part = domain_part.encode('idna').decode('ascii')
 | 
			
		||||
            except UnicodeError:
 | 
			
		||||
                self.error(self.error_msg % value)
 | 
			
		||||
                self.error("%s %s" % (self.error_msg % value, "(domain failed IDN encoding)"))
 | 
			
		||||
            else:
 | 
			
		||||
                if not self.validate_domain_part(domain_part):
 | 
			
		||||
                    self.error(self.error_msg % value)
 | 
			
		||||
                    self.error("%s %s" % (self.error_msg % value, "(domain validation failed)"))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class IntField(BaseField):
 | 
			
		||||
 
 | 
			
		||||
@@ -197,7 +197,7 @@ class BaseQuerySet(object):
 | 
			
		||||
                only_fields=self.only_fields
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        raise AttributeError('Provide a slice or an integer index')
 | 
			
		||||
        raise TypeError('Provide a slice or an integer index')
 | 
			
		||||
 | 
			
		||||
    def __iter__(self):
 | 
			
		||||
        raise NotImplementedError
 | 
			
		||||
 
 | 
			
		||||
@@ -88,18 +88,10 @@ def query(_doc_cls=None, **kwargs):
 | 
			
		||||
            singular_ops = [None, 'ne', 'gt', 'gte', 'lt', 'lte', 'not']
 | 
			
		||||
            singular_ops += STRING_OPERATORS
 | 
			
		||||
            if op in singular_ops:
 | 
			
		||||
                if isinstance(field, six.string_types):
 | 
			
		||||
                    if (op in STRING_OPERATORS and
 | 
			
		||||
                            isinstance(value, six.string_types)):
 | 
			
		||||
                        StringField = _import_class('StringField')
 | 
			
		||||
                        value = StringField.prepare_query_value(op, value)
 | 
			
		||||
                    else:
 | 
			
		||||
                        value = field
 | 
			
		||||
                else:
 | 
			
		||||
                    value = field.prepare_query_value(op, value)
 | 
			
		||||
                value = field.prepare_query_value(op, value)
 | 
			
		||||
 | 
			
		||||
                    if isinstance(field, CachedReferenceField) and value:
 | 
			
		||||
                        value = value['_id']
 | 
			
		||||
                if isinstance(field, CachedReferenceField) and value:
 | 
			
		||||
                    value = value['_id']
 | 
			
		||||
 | 
			
		||||
            elif op in ('in', 'nin', 'all', 'near') and not isinstance(value, dict):
 | 
			
		||||
                # Raise an error if the in/nin/all/near param is not iterable.
 | 
			
		||||
@@ -308,10 +300,6 @@ def update(_doc_cls=None, **update):
 | 
			
		||||
 | 
			
		||||
        key = '.'.join(parts)
 | 
			
		||||
 | 
			
		||||
        if not op:
 | 
			
		||||
            raise InvalidQueryError('Updates must supply an operation '
 | 
			
		||||
                                    'eg: set__FIELD=value')
 | 
			
		||||
 | 
			
		||||
        if 'pull' in op and '.' in key:
 | 
			
		||||
            # Dot operators don't work on pull operations
 | 
			
		||||
            # unless they point to a list field
 | 
			
		||||
 
 | 
			
		||||
@@ -593,8 +593,9 @@ class IndexesTest(unittest.TestCase):
 | 
			
		||||
        # Two posts with the same slug is not allowed
 | 
			
		||||
        post2 = BlogPost(title='test2', slug='test')
 | 
			
		||||
        self.assertRaises(NotUniqueError, post2.save)
 | 
			
		||||
        self.assertRaises(NotUniqueError, BlogPost.objects.insert, post2)
 | 
			
		||||
 | 
			
		||||
        # Ensure backwards compatibilty for errors
 | 
			
		||||
        # Ensure backwards compatibility for errors
 | 
			
		||||
        self.assertRaises(OperationError, post2.save)
 | 
			
		||||
 | 
			
		||||
    @requires_mongodb_gte_34
 | 
			
		||||
@@ -826,6 +827,19 @@ class IndexesTest(unittest.TestCase):
 | 
			
		||||
        self.assertEqual(3600,
 | 
			
		||||
                         info['created_1']['expireAfterSeconds'])
 | 
			
		||||
 | 
			
		||||
    def test_index_drop_dups_silently_ignored(self):
 | 
			
		||||
        class Customer(Document):
 | 
			
		||||
            cust_id = IntField(unique=True, required=True)
 | 
			
		||||
            meta = {
 | 
			
		||||
                'indexes': ['cust_id'],
 | 
			
		||||
                'index_drop_dups': True,
 | 
			
		||||
                'allow_inheritance': False,
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        Customer.drop_collection()
 | 
			
		||||
        Customer.objects.first()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def test_unique_and_indexes(self):
 | 
			
		||||
        """Ensure that 'unique' constraints aren't overridden by
 | 
			
		||||
        meta.indexes.
 | 
			
		||||
@@ -842,11 +856,16 @@ class IndexesTest(unittest.TestCase):
 | 
			
		||||
        cust.save()
 | 
			
		||||
 | 
			
		||||
        cust_dupe = Customer(cust_id=1)
 | 
			
		||||
        try:
 | 
			
		||||
        with self.assertRaises(NotUniqueError):
 | 
			
		||||
            cust_dupe.save()
 | 
			
		||||
            raise AssertionError("We saved a dupe!")
 | 
			
		||||
        except NotUniqueError:
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
        cust = Customer(cust_id=2)
 | 
			
		||||
        cust.save()
 | 
			
		||||
 | 
			
		||||
        # duplicate key on update
 | 
			
		||||
        with self.assertRaises(NotUniqueError):
 | 
			
		||||
            cust.cust_id = 1
 | 
			
		||||
            cust.save()
 | 
			
		||||
 | 
			
		||||
    def test_primary_save_duplicate_update_existing_object(self):
 | 
			
		||||
        """If you set a field as primary, then unexpected behaviour can occur.
 | 
			
		||||
 
 | 
			
		||||
@@ -420,6 +420,12 @@ class InstanceTest(MongoDBTestCase):
 | 
			
		||||
        person.save()
 | 
			
		||||
        person.to_dbref()
 | 
			
		||||
 | 
			
		||||
    def test_key_like_attribute_access(self):
 | 
			
		||||
        person = self.Person(age=30)
 | 
			
		||||
        self.assertEqual(person['age'], 30)
 | 
			
		||||
        with self.assertRaises(KeyError):
 | 
			
		||||
            person['unknown_attr']
 | 
			
		||||
 | 
			
		||||
    def test_save_abstract_document(self):
 | 
			
		||||
        """Saving an abstract document should fail."""
 | 
			
		||||
        class Doc(Document):
 | 
			
		||||
 
 | 
			
		||||
@@ -40,6 +40,11 @@ class GeoFieldTest(unittest.TestCase):
 | 
			
		||||
            expected = "Both values (%s) in point must be float or int" % repr(coord)
 | 
			
		||||
            self._test_for_expected_error(Location, coord, expected)
 | 
			
		||||
 | 
			
		||||
        invalid_coords = [21, 4, 'a']
 | 
			
		||||
        for coord in invalid_coords:
 | 
			
		||||
            expected = "GeoPointField can only accept tuples or lists of (x, y)"
 | 
			
		||||
            self._test_for_expected_error(Location, coord, expected)
 | 
			
		||||
 | 
			
		||||
    def test_point_validation(self):
 | 
			
		||||
        class Location(Document):
 | 
			
		||||
            loc = PointField()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										0
									
								
								tests/test_common.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/test_common.py
									
									
									
									
									
										Normal file
									
								
							
		Reference in New Issue
	
	Block a user