autoformat with updated black

This commit is contained in:
Bastien Gerard 2020-12-08 23:10:07 +01:00
parent ee6ef1ff4b
commit c00a378776
33 changed files with 189 additions and 349 deletions

View File

@ -1,7 +1,7 @@
fail_fast: false
repos:
- repo: https://github.com/ambv/black
rev: 19.10b0
rev: 20.8b1
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8

View File

@ -244,8 +244,7 @@ class BaseDocument:
return iter(self._fields_ordered)
def __getitem__(self, name):
"""Dictionary-style field access, return a field's value if present.
"""
"""Dictionary-style field access, return a field's value if present."""
try:
if name in self._fields_ordered:
return getattr(self, name)
@ -254,8 +253,7 @@ class BaseDocument:
raise KeyError(name)
def __setitem__(self, name, value):
"""Dictionary-style field access, set a field's value.
"""
"""Dictionary-style field access, set a field's value."""
# Ensure that the field exists before settings its value
if not self._dynamic and name not in self._fields:
raise KeyError(name)
@ -617,8 +615,7 @@ class BaseDocument:
)
def _get_changed_fields(self):
"""Return a list of all fields that have explicitly been changed.
"""
"""Return a list of all fields that have explicitly been changed."""
EmbeddedDocument = _import_class("EmbeddedDocument")
ReferenceField = _import_class("ReferenceField")
GenericReferenceField = _import_class("GenericReferenceField")
@ -750,8 +747,7 @@ class BaseDocument:
@classmethod
def _from_son(cls, son, _auto_dereference=True, created=False):
"""Create an instance of a Document (subclass) from a PyMongo SON (dict)
"""
"""Create an instance of a Document (subclass) from a PyMongo SON (dict)"""
if son and not isinstance(son, dict):
raise ValueError(
"The source SON object needs to be of type 'dict' but a '%s' was found"
@ -800,7 +796,8 @@ class BaseDocument:
["Field '{}' - {}".format(k, v) for k, v in errors_dict.items()]
)
msg = "Invalid data to create a `{}` instance.\n{}".format(
cls._class_name, errors,
cls._class_name,
errors,
)
raise InvalidDocumentError(msg)
@ -1165,8 +1162,7 @@ class BaseDocument:
@classmethod
def _translate_field_name(cls, field, sep="."):
"""Translate a field attribute name to a database field name.
"""
"""Translate a field attribute name to a database field name."""
parts = field.split(sep)
parts = [f.db_field for f in cls._lookup_field(parts)]
return ".".join(parts)

View File

@ -117,8 +117,7 @@ class BaseField:
BaseField.creation_counter += 1
def __get__(self, instance, owner):
"""Descriptor for retrieving a value from a field in a document.
"""
"""Descriptor for retrieving a value from a field in a document."""
if instance is None:
# Document class being used rather than a document object
return self

View File

@ -184,8 +184,7 @@ class query_counter:
"""
def __init__(self, alias=DEFAULT_CONNECTION_NAME):
"""Construct the query_counter
"""
"""Construct the query_counter"""
self.db = get_db(alias=alias)
self.initial_profiling_level = None
self._ctx_query_counter = 0 # number of queries issued by the context

View File

@ -157,8 +157,7 @@ class DeReference:
return reference_map
def _fetch_objects(self, doc_type=None):
"""Fetch all references and convert to their document objects
"""
"""Fetch all references and convert to their document objects"""
object_map = {}
for collection, dbrefs in self.reference_map.items():

View File

@ -14,8 +14,7 @@ IS_PYMONGO_GTE_37 = PYMONGO_VERSION >= _PYMONGO_37
def count_documents(
collection, filter, skip=None, limit=None, hint=None, collation=None
):
"""Pymongo>3.7 deprecates count in favour of count_documents
"""
"""Pymongo>3.7 deprecates count in favour of count_documents"""
if limit == 0:
return 0 # Pymongo raises an OperationFailure if called with limit=0

View File

@ -189,7 +189,8 @@ class BaseQuerySet:
if queryset._scalar:
return queryset._get_scalar(
queryset._document._from_son(
queryset._cursor[key], _auto_dereference=self._auto_dereference,
queryset._cursor[key],
_auto_dereference=self._auto_dereference,
)
)
@ -197,7 +198,8 @@ class BaseQuerySet:
return queryset._cursor[key]
return queryset._document._from_son(
queryset._cursor[key], _auto_dereference=self._auto_dereference,
queryset._cursor[key],
_auto_dereference=self._auto_dereference,
)
raise TypeError("Provide a slice or an integer index")
@ -738,7 +740,8 @@ class BaseQuerySet:
else:
for doc in docs:
doc_map[doc["_id"]] = self._document._from_son(
doc, _auto_dereference=self._auto_dereference,
doc,
_auto_dereference=self._auto_dereference,
)
return doc_map
@ -1556,8 +1559,7 @@ class BaseQuerySet:
# Iterator helpers
def __next__(self):
"""Wrap the result in a :class:`~mongoengine.Document` object.
"""
"""Wrap the result in a :class:`~mongoengine.Document` object."""
if self._none or self._empty:
raise StopIteration
@ -1567,7 +1569,8 @@ class BaseQuerySet:
return raw_doc
doc = self._document._from_son(
raw_doc, _auto_dereference=self._auto_dereference,
raw_doc,
_auto_dereference=self._auto_dereference,
)
if self._scalar:

View File

@ -13,17 +13,14 @@ def warn_empty_is_deprecated():
class QNodeVisitor:
"""Base visitor class for visiting Q-object nodes in a query tree.
"""
"""Base visitor class for visiting Q-object nodes in a query tree."""
def visit_combination(self, combination):
"""Called by QCombination objects.
"""
"""Called by QCombination objects."""
return combination
def visit_query(self, query):
"""Called by (New)Q objects.
"""
"""Called by (New)Q objects."""
return query
@ -49,8 +46,7 @@ class SimplificationVisitor(QNodeVisitor):
return combination
def _query_conjunction(self, queries):
"""Merges query dicts - effectively &ing them together.
"""
"""Merges query dicts - effectively &ing them together."""
query_ops = set()
combined_query = {}
for query in queries:

View File

@ -26,16 +26,14 @@ class TestClassMethods(unittest.TestCase):
self.db.drop_collection(collection)
def test_definition(self):
"""Ensure that document may be defined using fields.
"""
"""Ensure that document may be defined using fields."""
assert ["_cls", "age", "id", "name"] == sorted(self.Person._fields.keys())
assert ["IntField", "ObjectIdField", "StringField", "StringField"] == sorted(
[x.__class__.__name__ for x in self.Person._fields.values()]
)
def test_get_db(self):
"""Ensure that get_db returns the expected db.
"""
"""Ensure that get_db returns the expected db."""
db = self.Person._get_db()
assert self.db == db
@ -47,15 +45,13 @@ class TestClassMethods(unittest.TestCase):
assert collection_name == self.Person._get_collection_name()
def test_get_collection(self):
"""Ensure that get_collection returns the expected collection.
"""
"""Ensure that get_collection returns the expected collection."""
collection_name = "person"
collection = self.Person._get_collection()
assert self.db[collection_name] == collection
def test_drop_collection(self):
"""Ensure that the collection may be dropped from the database.
"""
"""Ensure that the collection may be dropped from the database."""
collection_name = "person"
self.Person(name="Test").save()
assert collection_name in list_collection_names(self.db)
@ -260,8 +256,7 @@ class TestClassMethods(unittest.TestCase):
assert Vaccine._meta["delete_rules"][(Cat, "vaccine_made")] == PULL
def test_collection_naming(self):
"""Ensure that a collection with a specified name may be used.
"""
"""Ensure that a collection with a specified name may be used."""
class DefaultNamingTest(Document):
pass
@ -316,8 +311,7 @@ class TestClassMethods(unittest.TestCase):
assert "basedocument" == MyDocument._get_collection_name()
def test_custom_collection_name_operations(self):
"""Ensure that a collection with a specified name is used as expected.
"""
"""Ensure that a collection with a specified name is used as expected."""
collection_name = "personCollTest"
class Person(Document):
@ -337,8 +331,7 @@ class TestClassMethods(unittest.TestCase):
assert collection_name not in list_collection_names(self.db)
def test_collection_name_and_primary(self):
"""Ensure that a collection with a specified name may be used.
"""
"""Ensure that a collection with a specified name may be used."""
class Person(Document):
name = StringField(primary_key=True)

View File

@ -643,7 +643,10 @@ class TestDelta(MongoDBTestCase):
doc.save()
doc = doc.reload(10)
assert doc._delta() == ({}, {},)
assert doc._delta() == (
{},
{},
)
del doc.embedded_field.list_field[2].list_field
assert doc._delta() == (
{},

View File

@ -171,8 +171,7 @@ class TestIndexes(unittest.TestCase):
assert MyDoc._meta["index_specs"] == [{"fields": [("keywords", 1)]}]
def test_embedded_document_index_meta(self):
"""Ensure that embedded document indexes are created explicitly
"""
"""Ensure that embedded document indexes are created explicitly"""
class Rank(EmbeddedDocument):
title = StringField(required=True)
@ -194,8 +193,7 @@ class TestIndexes(unittest.TestCase):
assert [("rank.title", 1)] in info
def test_explicit_geo2d_index(self):
"""Ensure that geo2d indexes work when created via meta[indexes]
"""
"""Ensure that geo2d indexes work when created via meta[indexes]"""
class Place(Document):
location = DictField()
@ -209,8 +207,7 @@ class TestIndexes(unittest.TestCase):
assert [("location.point", "2d")] in info
def test_explicit_geo2d_index_embedded(self):
"""Ensure that geo2d indexes work when created via meta[indexes]
"""
"""Ensure that geo2d indexes work when created via meta[indexes]"""
class EmbeddedLocation(EmbeddedDocument):
location = DictField()
@ -229,8 +226,7 @@ class TestIndexes(unittest.TestCase):
assert [("current.location.point", "2d")] in info
def test_explicit_geosphere_index(self):
"""Ensure that geosphere indexes work when created via meta[indexes]
"""
"""Ensure that geosphere indexes work when created via meta[indexes]"""
class Place(Document):
location = DictField()
@ -246,8 +242,7 @@ class TestIndexes(unittest.TestCase):
assert [("location.point", "2dsphere")] in info
def test_explicit_geohaystack_index(self):
"""Ensure that geohaystack indexes work when created via meta[indexes]
"""
"""Ensure that geohaystack indexes work when created via meta[indexes]"""
pytest.skip(
"GeoHaystack index creation is not supported for now"
"from meta, as it requires a bucketSize parameter."
@ -268,8 +263,7 @@ class TestIndexes(unittest.TestCase):
assert [("location.point", "geoHaystack")] in info
def test_create_geohaystack_index(self):
"""Ensure that geohaystack indexes can be created
"""
"""Ensure that geohaystack indexes can be created"""
class Place(Document):
location = DictField()
@ -364,8 +358,7 @@ class TestIndexes(unittest.TestCase):
assert sorted(info.keys()) == ["_cls_1_user_guid_1", "_id_"]
def test_embedded_document_index(self):
"""Tests settings an index on an embedded document
"""
"""Tests settings an index on an embedded document"""
class Date(EmbeddedDocument):
year = IntField(db_field="yr")
@ -382,8 +375,7 @@ class TestIndexes(unittest.TestCase):
assert sorted(info.keys()) == ["_id_", "date.yr_-1"]
def test_list_embedded_document_index(self):
"""Ensure list embedded documents can be indexed
"""
"""Ensure list embedded documents can be indexed"""
class Tag(EmbeddedDocument):
name = StringField(db_field="tag")
@ -419,8 +411,7 @@ class TestIndexes(unittest.TestCase):
assert sorted(info.keys()) == ["_cls_1", "_id_"]
def test_covered_index(self):
"""Ensure that covered indexes can be used
"""
"""Ensure that covered indexes can be used"""
class Test(Document):
a = IntField()
@ -558,8 +549,7 @@ class TestIndexes(unittest.TestCase):
assert [x.name for x in query_result] == sorted(names)
def test_unique(self):
"""Ensure that uniqueness constraints are applied to fields.
"""
"""Ensure that uniqueness constraints are applied to fields."""
class BlogPost(Document):
title = StringField()
@ -607,8 +597,7 @@ class TestIndexes(unittest.TestCase):
)
def test_unique_with(self):
"""Ensure that unique_with constraints are applied to fields.
"""
"""Ensure that unique_with constraints are applied to fields."""
class Date(EmbeddedDocument):
year = IntField(db_field="yr")
@ -633,8 +622,7 @@ class TestIndexes(unittest.TestCase):
post3.save()
def test_unique_embedded_document(self):
"""Ensure that uniqueness constraints are applied to fields on embedded documents.
"""
"""Ensure that uniqueness constraints are applied to fields on embedded documents."""
class SubDocument(EmbeddedDocument):
year = IntField(db_field="yr")

View File

@ -45,8 +45,7 @@ class TestInheritance(MongoDBTestCase):
test_doc.delete()
def test_superclasses(self):
"""Ensure that the correct list of superclasses is assembled.
"""
"""Ensure that the correct list of superclasses is assembled."""
class Animal(Document):
meta = {"allow_inheritance": True}
@ -216,8 +215,7 @@ class TestInheritance(MongoDBTestCase):
assert Pike._subclasses == ("Animal.Fish.Pike",)
def test_inheritance_meta_data(self):
"""Ensure that document may inherit fields from a superclass document.
"""
"""Ensure that document may inherit fields from a superclass document."""
class Person(Document):
name = StringField()
@ -234,8 +232,7 @@ class TestInheritance(MongoDBTestCase):
assert Employee._get_collection_name() == Person._get_collection_name()
def test_inheritance_to_mongo_keys(self):
"""Ensure that document may inherit fields from a superclass document.
"""
"""Ensure that document may inherit fields from a superclass document."""
class Person(Document):
name = StringField()
@ -289,8 +286,7 @@ class TestInheritance(MongoDBTestCase):
)
def test_polymorphic_queries(self):
"""Ensure that the correct subclasses are returned from a query
"""
"""Ensure that the correct subclasses are returned from a query"""
class Animal(Document):
meta = {"allow_inheritance": True}
@ -347,8 +343,7 @@ class TestInheritance(MongoDBTestCase):
assert "_cls" not in obj
def test_cant_turn_off_inheritance_on_subclass(self):
"""Ensure if inheritance is on in a subclass you cant turn it off.
"""
"""Ensure if inheritance is on in a subclass you cant turn it off."""
class Animal(Document):
name = StringField()
@ -498,8 +493,7 @@ class TestInheritance(MongoDBTestCase):
assert "_cls" in doc.to_mongo()
def test_document_inheritance(self):
"""Ensure mutliple inheritance of abstract documents
"""
"""Ensure mutliple inheritance of abstract documents"""
class DateCreatedDocument(Document):
meta = {"allow_inheritance": True, "abstract": True}

View File

@ -160,8 +160,7 @@ class TestDocumentInstance(MongoDBTestCase):
Log.objects
def test_repr(self):
"""Ensure that unicode representation works
"""
"""Ensure that unicode representation works"""
class Article(Document):
title = StringField()
@ -1553,8 +1552,7 @@ class TestDocumentInstance(MongoDBTestCase):
assert site.page.log_message == "Error: Dummy message"
def test_update_list_field(self):
"""Test update on `ListField` with $pull + $in.
"""
"""Test update on `ListField` with $pull + $in."""
class Doc(Document):
foo = ListField(StringField())
@ -2816,15 +2814,13 @@ class TestDocumentInstance(MongoDBTestCase):
register_connection("testdb-2", "mongoenginetest2")
class A(Document):
"""Uses default db_alias
"""
"""Uses default db_alias"""
name = StringField()
meta = {"allow_inheritance": True}
class B(A):
"""Uses testdb-2 db_alias
"""
"""Uses testdb-2 db_alias"""
meta = {"db_alias": "testdb-2"}
@ -3612,8 +3608,7 @@ class TestDocumentInstance(MongoDBTestCase):
assert u_from_db.height is None
def test_not_saved_eq(self):
"""Ensure we can compare documents not saved.
"""
"""Ensure we can compare documents not saved."""
class Person(Document):
pass

View File

@ -9,8 +9,7 @@ from tests.utils import MongoDBTestCase
class TestValidatorError(MongoDBTestCase):
def test_to_dict(self):
"""Ensure a ValidationError handles error to_dict correctly.
"""
"""Ensure a ValidationError handles error to_dict correctly."""
error = ValidationError("root")
assert error.to_dict() == {}
@ -90,8 +89,7 @@ class TestValidatorError(MongoDBTestCase):
p.validate()
def test_embedded_document_validation(self):
"""Ensure that embedded documents may be validated.
"""
"""Ensure that embedded documents may be validated."""
class Comment(EmbeddedDocument):
date = DateTimeField()

View File

@ -13,8 +13,7 @@ BIN_VALUE = "\xa9\xf3\x8d(\xd7\x03\x84\xb4k[\x0f\xe3\xa2\x19\x85p[J\xa3\xd2>\xde
class TestBinaryField(MongoDBTestCase):
def test_binary_fields(self):
"""Ensure that binary fields can be stored and retrieved.
"""
"""Ensure that binary fields can be stored and retrieved."""
class Attachment(Document):
content_type = StringField()
@ -33,8 +32,7 @@ class TestBinaryField(MongoDBTestCase):
assert BLOB == bytes(attachment_1.blob)
def test_validation_succeeds(self):
"""Ensure that valid values can be assigned to binary fields.
"""
"""Ensure that valid values can be assigned to binary fields."""
class AttachmentRequired(Document):
blob = BinaryField(required=True)

View File

@ -8,8 +8,7 @@ from tests.utils import MongoDBTestCase
class TestDecimalField(MongoDBTestCase):
def test_validation(self):
"""Ensure that invalid values cannot be assigned to decimal fields.
"""
"""Ensure that invalid values cannot be assigned to decimal fields."""
class Person(Document):
height = DecimalField(min_value=Decimal("0.1"), max_value=Decimal("3.5"))

View File

@ -544,8 +544,7 @@ class TestField(MongoDBTestCase):
post.validate()
def test_sorted_list_sorting(self):
"""Ensure that a sorted list field properly sorts values.
"""
"""Ensure that a sorted list field properly sorts values."""
class Comment(EmbeddedDocument):
order = IntField()
@ -661,8 +660,7 @@ class TestField(MongoDBTestCase):
)
def test_list_field_manipulative_operators(self):
"""Ensure that ListField works with standard list operators that manipulate the list.
"""
"""Ensure that ListField works with standard list operators that manipulate the list."""
class BlogPost(Document):
ref = StringField()
@ -1372,8 +1370,7 @@ class TestField(MongoDBTestCase):
assert bar.generic_ref == {"_ref": expected, "_cls": "Foo"}
def test_list_item_dereference(self):
"""Ensure that DBRef items in ListFields are dereferenced.
"""
"""Ensure that DBRef items in ListFields are dereferenced."""
class User(Document):
name = StringField()
@ -1398,8 +1395,7 @@ class TestField(MongoDBTestCase):
assert group_obj.members[1].name == user2.name
def test_recursive_reference(self):
"""Ensure that ReferenceFields can reference their own documents.
"""
"""Ensure that ReferenceFields can reference their own documents."""
class Employee(Document):
name = StringField()
@ -1426,8 +1422,7 @@ class TestField(MongoDBTestCase):
assert peter.friends == friends
def test_recursive_embedding(self):
"""Ensure that EmbeddedDocumentFields can contain their own documents.
"""
"""Ensure that EmbeddedDocumentFields can contain their own documents."""
class TreeNode(EmbeddedDocument):
name = StringField()
@ -1503,8 +1498,7 @@ class TestField(MongoDBTestCase):
AbstractDoc.drop_collection()
def test_reference_class_with_abstract_parent(self):
"""Ensure that a class with an abstract parent can be referenced.
"""
"""Ensure that a class with an abstract parent can be referenced."""
class Sibling(Document):
name = StringField()
@ -1574,8 +1568,7 @@ class TestField(MongoDBTestCase):
brother.save()
def test_generic_reference(self):
"""Ensure that a GenericReferenceField properly dereferences items.
"""
"""Ensure that a GenericReferenceField properly dereferences items."""
class Link(Document):
title = StringField()
@ -1614,8 +1607,7 @@ class TestField(MongoDBTestCase):
assert isinstance(bm.bookmark_object, Link)
def test_generic_reference_list(self):
"""Ensure that a ListField properly dereferences generic references.
"""
"""Ensure that a ListField properly dereferences generic references."""
class Link(Document):
title = StringField()
@ -1718,8 +1710,7 @@ class TestField(MongoDBTestCase):
assert bm.bookmark_object == post_1
def test_generic_reference_string_choices(self):
"""Ensure that a GenericReferenceField can handle choices as strings
"""
"""Ensure that a GenericReferenceField can handle choices as strings"""
class Link(Document):
title = StringField()
@ -1811,8 +1802,7 @@ class TestField(MongoDBTestCase):
assert user.bookmarks == [post_1]
def test_generic_reference_list_item_modification(self):
"""Ensure that modifications of related documents (through generic reference) don't influence on querying
"""
"""Ensure that modifications of related documents (through generic reference) don't influence on querying"""
class Post(Document):
title = StringField()
@ -1900,8 +1890,7 @@ class TestField(MongoDBTestCase):
assert doc == doc2
def test_choices_allow_using_sets_as_choices(self):
"""Ensure that sets can be used when setting choices
"""
"""Ensure that sets can be used when setting choices"""
class Shirt(Document):
size = StringField(choices={"M", "L"})
@ -1920,8 +1909,7 @@ class TestField(MongoDBTestCase):
shirt.validate()
def test_choices_validation_accept_possible_value(self):
"""Ensure that value is in a container of allowed values.
"""
"""Ensure that value is in a container of allowed values."""
class Shirt(Document):
size = StringField(choices=("S", "M"))
@ -1930,8 +1918,7 @@ class TestField(MongoDBTestCase):
shirt.validate()
def test_choices_validation_reject_unknown_value(self):
"""Ensure that unallowed value are rejected upon validation
"""
"""Ensure that unallowed value are rejected upon validation"""
class Shirt(Document):
size = StringField(choices=("S", "M"))
@ -1989,8 +1976,7 @@ class TestField(MongoDBTestCase):
shirt1.validate()
def test_simple_choices_validation(self):
"""Ensure that value is in a container of allowed values.
"""
"""Ensure that value is in a container of allowed values."""
class Shirt(Document):
size = StringField(max_length=3, choices=("S", "M", "L", "XL", "XXL"))
@ -2039,8 +2025,7 @@ class TestField(MongoDBTestCase):
shirt.validate()
def test_simple_choices_validation_invalid_value(self):
"""Ensure that error messages are correct.
"""
"""Ensure that error messages are correct."""
SIZES = ("S", "M", "L", "XL", "XXL")
COLORS = (("R", "Red"), ("B", "Blue"))
SIZE_MESSAGE = u"Value must be one of ('S', 'M', 'L', 'XL', 'XXL')"

View File

@ -48,8 +48,7 @@ class TestFileField(MongoDBTestCase):
DemoFile.objects.create()
def test_file_fields(self):
"""Ensure that file fields can be written to and their data retrieved
"""
"""Ensure that file fields can be written to and their data retrieved"""
class PutFile(Document):
the_file = FileField()
@ -91,8 +90,7 @@ class TestFileField(MongoDBTestCase):
result.the_file.delete()
def test_file_fields_stream(self):
"""Ensure that file fields can be written to and their data retrieved
"""
"""Ensure that file fields can be written to and their data retrieved"""
class StreamFile(Document):
the_file = FileField()
@ -228,8 +226,7 @@ class TestFileField(MongoDBTestCase):
assert ["doc_b", "doc_e"] == grid_fs.list()
def test_file_uniqueness(self):
"""Ensure that each instance of a FileField is unique
"""
"""Ensure that each instance of a FileField is unique"""
class TestFile(Document):
name = StringField()
@ -285,8 +282,7 @@ class TestFileField(MongoDBTestCase):
assert test_file.the_file.get().length == 4971
def test_file_boolean(self):
"""Ensure that a boolean test of a FileField indicates its presence
"""
"""Ensure that a boolean test of a FileField indicates its presence"""
class TestFile(Document):
the_file = FileField()

View File

@ -19,8 +19,7 @@ class TestFloatField(MongoDBTestCase):
assert 1 == TestDocument.objects(float_fld__ne=1).count()
def test_validation(self):
"""Ensure that invalid values cannot be assigned to float fields.
"""
"""Ensure that invalid values cannot be assigned to float fields."""
class Person(Document):
height = FloatField(min_value=0.1, max_value=3.5)

View File

@ -290,8 +290,7 @@ class TestGeoField(MongoDBTestCase):
Location(loc=[[[[1, 2], [3, 4], [5, 6], [1, 2]]]]).validate()
def test_indexes_geopoint(self):
"""Ensure that indexes are created automatically for GeoPointFields.
"""
"""Ensure that indexes are created automatically for GeoPointFields."""
class Event(Document):
title = StringField()
@ -317,8 +316,7 @@ class TestGeoField(MongoDBTestCase):
assert geo_indicies == [{"fields": [("venue.location", "2d")]}]
def test_indexes_2dsphere(self):
"""Ensure that indexes are created automatically for GeoPointFields.
"""
"""Ensure that indexes are created automatically for GeoPointFields."""
class Event(Document):
title = StringField()
@ -332,8 +330,7 @@ class TestGeoField(MongoDBTestCase):
assert {"fields": [("point", "2dsphere")]} in geo_indicies
def test_indexes_2dsphere_embedded(self):
"""Ensure that indexes are created automatically for GeoPointFields.
"""
"""Ensure that indexes are created automatically for GeoPointFields."""
class Venue(EmbeddedDocument):
name = StringField()

View File

@ -7,8 +7,7 @@ from tests.utils import MongoDBTestCase
class TestIntField(MongoDBTestCase):
def test_int_validation(self):
"""Ensure that invalid values cannot be assigned to int fields.
"""
"""Ensure that invalid values cannot be assigned to int fields."""
class Person(Document):
age = IntField(min_value=0, max_value=110)

View File

@ -25,8 +25,7 @@ class TestLongField(MongoDBTestCase):
assert isinstance(doc.some_long, int)
def test_long_validation(self):
"""Ensure that invalid values cannot be assigned to long fields.
"""
"""Ensure that invalid values cannot be assigned to long fields."""
class TestDocument(Document):
value = LongField(min_value=0, max_value=110)

View File

@ -107,8 +107,7 @@ class TestReferenceField(MongoDBTestCase):
assert p.parent == p1
def test_undefined_reference(self):
"""Ensure that ReferenceFields may reference undefined Documents.
"""
"""Ensure that ReferenceFields may reference undefined Documents."""
class Product(Document):
name = StringField()

View File

@ -38,8 +38,7 @@ class TestURLField(MongoDBTestCase):
)
def test_url_scheme_validation(self):
"""Ensure that URLFields validate urls with specific schemes properly.
"""
"""Ensure that URLFields validate urls with specific schemes properly."""
class Link(Document):
url = URLField()

View File

@ -17,8 +17,7 @@ class TestUUIDField(MongoDBTestCase):
assert get_as_pymongo(person) == {"_id": person.id, "api_key": str(uid)}
def test_field_string(self):
"""Test UUID fields storing as String
"""
"""Test UUID fields storing as String"""
Person.drop_collection()
uu = uuid.uuid4()

View File

@ -148,8 +148,7 @@ class TestOnlyExcludeAll(unittest.TestCase):
assert qs._loaded_fields.as_dict() == {"c": {"$slice": 2}, "a": 1}
def test_only(self):
"""Ensure that QuerySet.only only returns the requested fields.
"""
"""Ensure that QuerySet.only only returns the requested fields."""
person = self.Person(name="test", age=25)
person.save()
@ -365,8 +364,7 @@ class TestOnlyExcludeAll(unittest.TestCase):
Email.drop_collection()
def test_slicing_fields(self):
"""Ensure that query slicing an array works.
"""
"""Ensure that query slicing an array works."""
class Numbers(Document):
n = ListField(IntField())
@ -401,8 +399,7 @@ class TestOnlyExcludeAll(unittest.TestCase):
assert numbers.n == [-5, -4, -3, -2, -1]
def test_slicing_nested_fields(self):
"""Ensure that query slicing an embedded array works.
"""
"""Ensure that query slicing an embedded array works."""
class EmbeddedNumber(EmbeddedDocument):
n = ListField(IntField())

View File

@ -60,8 +60,7 @@ class TestQueryset(unittest.TestCase):
self.mongodb_version = get_mongodb_version()
def test_initialisation(self):
"""Ensure that a QuerySet is correctly initialised by QuerySetManager.
"""
"""Ensure that a QuerySet is correctly initialised by QuerySetManager."""
assert isinstance(self.Person.objects, QuerySet)
assert (
self.Person.objects._collection.name == self.Person._get_collection_name()
@ -271,8 +270,7 @@ class TestQueryset(unittest.TestCase):
)
def test_find_one(self):
"""Ensure that a query using find_one returns a valid result.
"""
"""Ensure that a query using find_one returns a valid result."""
person1 = self.Person(name="User A", age=20)
person1.save()
person2 = self.Person(name="User B", age=30)
@ -317,8 +315,7 @@ class TestQueryset(unittest.TestCase):
self.Person.objects.get()
def test_get_multiple_match_raises_multipleobjectsreturned(self):
"""Ensure that a query using ``get`` returns at most one result.
"""
"""Ensure that a query using ``get`` returns at most one result."""
assert self.Person.objects().count() == 0
person1 = self.Person(name="User A", age=20)
@ -351,8 +348,7 @@ class TestQueryset(unittest.TestCase):
assert person == person3
def test_find_array_position(self):
"""Ensure that query by array position works.
"""
"""Ensure that query by array position works."""
class Comment(EmbeddedDocument):
name = StringField()
@ -1141,8 +1137,7 @@ class TestQueryset(unittest.TestCase):
assert q == 2
def test_repeated_iteration(self):
"""Ensure that QuerySet rewinds itself one iteration finishes.
"""
"""Ensure that QuerySet rewinds itself one iteration finishes."""
self.Person(name="Person 1").save()
self.Person(name="Person 2").save()
@ -1191,8 +1186,7 @@ class TestQueryset(unittest.TestCase):
assert ".. queryset mid-iteration .." == repr(docs)
def test_regex_query_shortcuts(self):
"""Ensure that contains, startswith, endswith, etc work.
"""
"""Ensure that contains, startswith, endswith, etc work."""
person = self.Person(name="Guido van Rossum")
person.save()
@ -1248,8 +1242,7 @@ class TestQueryset(unittest.TestCase):
assert obj == person
def test_not(self):
"""Ensure that the __not operator works as expected.
"""
"""Ensure that the __not operator works as expected."""
alice = self.Person(name="Alice", age=25)
alice.save()
@ -1260,8 +1253,7 @@ class TestQueryset(unittest.TestCase):
assert obj is None
def test_filter_chaining(self):
"""Ensure filters can be chained together.
"""
"""Ensure filters can be chained together."""
class Blog(Document):
id = StringField(primary_key=True)
@ -1337,8 +1329,7 @@ class TestQueryset(unittest.TestCase):
assert qs[i] == expected[i]
def test_ordering(self):
"""Ensure default ordering is applied and can be overridden.
"""
"""Ensure default ordering is applied and can be overridden."""
class BlogPost(Document):
title = StringField()
@ -1408,8 +1399,7 @@ class TestQueryset(unittest.TestCase):
assert ORDER_BY_KEY not in q.get_ops()[0][CMD_QUERY_KEY]
def test_no_ordering_for_get(self):
""" Ensure that Doc.objects.get doesn't use any ordering.
"""
"""Ensure that Doc.objects.get doesn't use any ordering."""
ORDER_BY_KEY, CMD_QUERY_KEY = get_key_compat(self.mongodb_version)
class BlogPost(Document):
@ -1485,8 +1475,7 @@ class TestQueryset(unittest.TestCase):
assert result.author is None
def test_find_dict_item(self):
"""Ensure that DictField items may be found.
"""
"""Ensure that DictField items may be found."""
class BlogPost(Document):
info = DictField()
@ -1502,8 +1491,7 @@ class TestQueryset(unittest.TestCase):
BlogPost.drop_collection()
def test_exec_js_query(self):
"""Ensure that queries are properly formed for use in exec_js.
"""
"""Ensure that queries are properly formed for use in exec_js."""
class BlogPost(Document):
hits = IntField()
@ -1540,8 +1528,7 @@ class TestQueryset(unittest.TestCase):
BlogPost.drop_collection()
def test_exec_js_field_sub(self):
"""Ensure that field substitutions occur properly in exec_js functions.
"""
"""Ensure that field substitutions occur properly in exec_js functions."""
class Comment(EmbeddedDocument):
content = StringField(db_field="body")
@ -1597,8 +1584,7 @@ class TestQueryset(unittest.TestCase):
BlogPost.drop_collection()
def test_delete(self):
"""Ensure that documents are properly deleted from the database.
"""
"""Ensure that documents are properly deleted from the database."""
self.Person(name="User A", age=20).save()
self.Person(name="User B", age=30).save()
self.Person(name="User C", age=40).save()
@ -1612,8 +1598,7 @@ class TestQueryset(unittest.TestCase):
assert self.Person.objects.count() == 0
def test_reverse_delete_rule_cascade(self):
"""Ensure cascading deletion of referring documents from the database.
"""
"""Ensure cascading deletion of referring documents from the database."""
class BlogPost(Document):
content = StringField()
@ -1745,8 +1730,7 @@ class TestQueryset(unittest.TestCase):
assert 0 == Category.objects.count()
def test_reverse_delete_rule_nullify(self):
"""Ensure nullification of references to deleted documents.
"""
"""Ensure nullification of references to deleted documents."""
class Category(Document):
name = StringField()
@ -1842,8 +1826,7 @@ class TestQueryset(unittest.TestCase):
self.Person.objects.delete()
def test_reverse_delete_rule_pull(self):
"""Ensure pulling of references to deleted documents.
"""
"""Ensure pulling of references to deleted documents."""
class BlogPost(Document):
content = StringField()
@ -1918,8 +1901,7 @@ class TestQueryset(unittest.TestCase):
assert 8 == Log.objects.count()
def test_delete_with_limit_handles_delete_rules(self):
"""Ensure cascading deletion of referring documents from the database.
"""
"""Ensure cascading deletion of referring documents from the database."""
class BlogPost(Document):
content = StringField()
@ -1951,8 +1933,7 @@ class TestQueryset(unittest.TestCase):
assert del_result is None
def test_reference_field_find(self):
"""Ensure cascading deletion of referring documents from the database.
"""
"""Ensure cascading deletion of referring documents from the database."""
class BlogPost(Document):
content = StringField()
@ -1973,8 +1954,7 @@ class TestQueryset(unittest.TestCase):
assert 1 == BlogPost.objects(author__in=["%s" % me.pk]).count()
def test_reference_field_find_dbref(self):
"""Ensure cascading deletion of referring documents from the database.
"""
"""Ensure cascading deletion of referring documents from the database."""
class BlogPost(Document):
content = StringField()
@ -2058,8 +2038,7 @@ class TestQueryset(unittest.TestCase):
BlogPost.objects.update_one(inc__review=0.1) # test with floats
def test_update_listfield_operator(self):
"""Ensure that atomic updates work properly.
"""
"""Ensure that atomic updates work properly."""
class BlogPost(Document):
tags = ListField(StringField())
@ -2107,8 +2086,7 @@ class TestQueryset(unittest.TestCase):
assert "title" not in pymongo_doc
def test_update_push_with_position(self):
"""Ensure that the 'push' update with position works properly.
"""
"""Ensure that the 'push' update with position works properly."""
class BlogPost(Document):
slug = StringField()
@ -2133,8 +2111,7 @@ class TestQueryset(unittest.TestCase):
assert post.tags == ["scala", "mongodb", "python", "java"]
def test_update_push_list_of_list(self):
"""Ensure that the 'push' update operation works in the list of list
"""
"""Ensure that the 'push' update operation works in the list of list"""
class BlogPost(Document):
slug = StringField()
@ -2149,8 +2126,7 @@ class TestQueryset(unittest.TestCase):
assert post.tags == [["value1", 123]]
def test_update_push_and_pull_add_to_set(self):
"""Ensure that the 'pull' update operation works correctly.
"""
"""Ensure that the 'pull' update operation works correctly."""
class BlogPost(Document):
slug = StringField()
@ -2259,8 +2235,7 @@ class TestQueryset(unittest.TestCase):
)
def test_pull_from_nested_embedded_using_in_nin(self):
"""Ensure that the 'pull' update operation works on embedded documents using 'in' and 'nin' operators.
"""
"""Ensure that the 'pull' update operation works on embedded documents using 'in' and 'nin' operators."""
class User(EmbeddedDocument):
name = StringField()
@ -2491,8 +2466,7 @@ class TestQueryset(unittest.TestCase):
assert doc.pk == doc.embedded[0]._instance.pk
def test_order_by(self):
"""Ensure that QuerySets may be ordered.
"""
"""Ensure that QuerySets may be ordered."""
self.Person(name="User B", age=40).save()
self.Person(name="User A", age=20).save()
self.Person(name="User C", age=30).save()
@ -2560,8 +2534,7 @@ class TestQueryset(unittest.TestCase):
self.assertSequence(qs, expected)
def test_order_by_chaining(self):
"""Ensure that an order_by query chains properly and allows .only()
"""
"""Ensure that an order_by query chains properly and allows .only()"""
self.Person(name="User B", age=40).save()
self.Person(name="User A", age=20).save()
self.Person(name="User C", age=30).save()
@ -2635,8 +2608,7 @@ class TestQueryset(unittest.TestCase):
assert op[CMD_QUERY_KEY][COMMENT_KEY] == "looking for an adult"
def test_map_reduce(self):
"""Ensure map/reduce is both mapping and reducing.
"""
"""Ensure map/reduce is both mapping and reducing."""
class BlogPost(Document):
title = StringField()
@ -2988,8 +2960,7 @@ class TestQueryset(unittest.TestCase):
Link.drop_collection()
def test_item_frequencies(self):
"""Ensure that item frequencies are properly generated from lists.
"""
"""Ensure that item frequencies are properly generated from lists."""
class BlogPost(Document):
hits = IntField()
@ -3057,8 +3028,7 @@ class TestQueryset(unittest.TestCase):
BlogPost.drop_collection()
def test_item_frequencies_on_embedded(self):
"""Ensure that item frequencies are properly generated from lists.
"""
"""Ensure that item frequencies are properly generated from lists."""
class Phone(EmbeddedDocument):
number = StringField()
@ -3214,8 +3184,7 @@ class TestQueryset(unittest.TestCase):
assert freqs == {1: 50.0 / 70, 2: 20.0 / 70}
def test_average(self):
"""Ensure that field can be averaged correctly.
"""
"""Ensure that field can be averaged correctly."""
self.Person(name="person", age=0).save()
assert int(self.Person.objects.average("age")) == 0
@ -3255,8 +3224,7 @@ class TestQueryset(unittest.TestCase):
assert self.Person.objects.filter(age__gte=50).average("age") == avg
def test_sum(self):
"""Ensure that field can be summed over correctly.
"""
"""Ensure that field can be summed over correctly."""
ages = [23, 54, 12, 94, 27]
for i, age in enumerate(ages):
self.Person(name="test%s" % i, age=age).save()
@ -3406,8 +3374,7 @@ class TestQueryset(unittest.TestCase):
assert Doc.objects.sum("values") == 1360
def test_distinct(self):
"""Ensure that the QuerySet.distinct method works.
"""
"""Ensure that the QuerySet.distinct method works."""
self.Person(name="Mr Orange", age=20).save()
self.Person(name="Mr White", age=20).save()
self.Person(name="Mr Orange", age=30).save()
@ -3547,8 +3514,7 @@ class TestQueryset(unittest.TestCase):
assert Foo.objects.distinct("bar") == [bar]
def test_distinct_handles_db_field(self):
"""Ensure that distinct resolves field name to db_field as expected.
"""
"""Ensure that distinct resolves field name to db_field as expected."""
class Product(Document):
product_id = IntField(db_field="pid")
@ -3644,8 +3610,7 @@ class TestQueryset(unittest.TestCase):
assert Foo.objects.distinct("bar_lst") == [bar_1, bar_2]
def test_custom_manager(self):
"""Ensure that custom QuerySetManager instances work as expected.
"""
"""Ensure that custom QuerySetManager instances work as expected."""
class BlogPost(Document):
tags = ListField(StringField())
@ -3746,8 +3711,7 @@ class TestQueryset(unittest.TestCase):
assert 1 == Bar.objects.count()
def test_query_value_conversion(self):
"""Ensure that query values are properly converted when necessary.
"""
"""Ensure that query values are properly converted when necessary."""
class BlogPost(Document):
author = ReferenceField(self.Person)
@ -3773,8 +3737,7 @@ class TestQueryset(unittest.TestCase):
BlogPost.drop_collection()
def test_update_value_conversion(self):
"""Ensure that values used in updates are converted before use.
"""
"""Ensure that values used in updates are converted before use."""
class Group(Document):
members = ListField(ReferenceField(self.Person))
@ -3799,8 +3762,7 @@ class TestQueryset(unittest.TestCase):
Group.drop_collection()
def test_bulk(self):
"""Ensure bulk querying by object id returns a proper dict.
"""
"""Ensure bulk querying by object id returns a proper dict."""
class BlogPost(Document):
title = StringField()
@ -3838,8 +3800,7 @@ class TestQueryset(unittest.TestCase):
self.Person.drop_collection()
def test_custom_querysets(self):
"""Ensure that custom QuerySet classes may be used.
"""
"""Ensure that custom QuerySet classes may be used."""
class CustomQuerySet(QuerySet):
def not_empty(self):
@ -3859,8 +3820,7 @@ class TestQueryset(unittest.TestCase):
Post.drop_collection()
def test_custom_querysets_set_manager_directly(self):
"""Ensure that custom QuerySet classes may be used.
"""
"""Ensure that custom QuerySet classes may be used."""
class CustomQuerySet(QuerySet):
def not_empty(self):
@ -3883,8 +3843,7 @@ class TestQueryset(unittest.TestCase):
Post.drop_collection()
def test_custom_querysets_managers_directly(self):
"""Ensure that custom QuerySet classes may be used.
"""
"""Ensure that custom QuerySet classes may be used."""
class CustomQuerySetManager(QuerySetManager):
@staticmethod
@ -3905,8 +3864,7 @@ class TestQueryset(unittest.TestCase):
Post.drop_collection()
def test_custom_querysets_inherited(self):
"""Ensure that custom QuerySet classes may be used.
"""
"""Ensure that custom QuerySet classes may be used."""
class CustomQuerySet(QuerySet):
def not_empty(self):
@ -3928,8 +3886,7 @@ class TestQueryset(unittest.TestCase):
Post.drop_collection()
def test_custom_querysets_inherited_direct(self):
"""Ensure that custom QuerySet classes may be used.
"""
"""Ensure that custom QuerySet classes may be used."""
class CustomQuerySet(QuerySet):
def not_empty(self):
@ -3990,8 +3947,7 @@ class TestQueryset(unittest.TestCase):
assert A.objects(b=[{"c": "c"}]).count() == 0
def test_call_after_limits_set(self):
"""Ensure that re-filtering after slicing works
"""
"""Ensure that re-filtering after slicing works"""
class Post(Document):
title = StringField()
@ -4007,8 +3963,7 @@ class TestQueryset(unittest.TestCase):
Post.drop_collection()
def test_order_then_filter(self):
"""Ensure that ordering still works after filtering.
"""
"""Ensure that ordering still works after filtering."""
class Number(Document):
n = IntField()
@ -4025,8 +3980,7 @@ class TestQueryset(unittest.TestCase):
Number.drop_collection()
def test_clone(self):
"""Ensure that cloning clones complex querysets
"""
"""Ensure that cloning clones complex querysets"""
class Number(Document):
n = IntField()
@ -4055,8 +4009,7 @@ class TestQueryset(unittest.TestCase):
Number.drop_collection()
def test_clone_retains_settings(self):
"""Ensure that cloning retains the read_preference and read_concern
"""
"""Ensure that cloning retains the read_preference and read_concern"""
class Number(Document):
n = IntField()
@ -4081,8 +4034,7 @@ class TestQueryset(unittest.TestCase):
Number.drop_collection()
def test_using(self):
"""Ensure that switching databases for a queryset is possible
"""
"""Ensure that switching databases for a queryset is possible"""
class Number2(Document):
n = IntField()
@ -4134,8 +4086,7 @@ class TestQueryset(unittest.TestCase):
Number.drop_collection()
def test_order_works_with_primary(self):
"""Ensure that order_by and primary work.
"""
"""Ensure that order_by and primary work."""
class Number(Document):
n = IntField(primary_key=True)
@ -4154,8 +4105,7 @@ class TestQueryset(unittest.TestCase):
Number.drop_collection()
def test_ensure_index(self):
"""Ensure that manual creation of indexes works.
"""
"""Ensure that manual creation of indexes works."""
class Comment(Document):
message = StringField()
@ -4171,8 +4121,7 @@ class TestQueryset(unittest.TestCase):
assert ([("_cls", 1), ("message", 1)], False, False) in info
def test_where(self):
"""Ensure that where clauses work.
"""
"""Ensure that where clauses work."""
class IntPair(Document):
fielda = IntField()
@ -4451,8 +4400,7 @@ class TestQueryset(unittest.TestCase):
assert list(val) == [("test", "test value")]
def test_scalar_cursor_behaviour(self):
"""Ensure that a query returns a valid set of results.
"""
"""Ensure that a query returns a valid set of results."""
person1 = self.Person(name="User A", age=20)
person1.save()
person2 = self.Person(name="User B", age=30)
@ -4669,8 +4617,7 @@ class TestQueryset(unittest.TestCase):
assert [b3] == ak
def test_upsert_includes_cls(self):
"""Upserts should include _cls information for inheritable classes
"""
"""Upserts should include _cls information for inheritable classes"""
class Test(Document):
test = StringField()
@ -5366,8 +5313,7 @@ class TestQueryset(unittest.TestCase):
assert obj.__class__ == C
def test_query_generic_embedded_document(self):
"""Ensure that querying sub field on generic_embedded_field works
"""
"""Ensure that querying sub field on generic_embedded_field works"""
class A(EmbeddedDocument):
a_name = StringField()

View File

@ -12,8 +12,7 @@ class TestTransform(unittest.TestCase):
connect(db="mongoenginetest")
def test_transform_query(self):
"""Ensure that the _transform_query function operates correctly.
"""
"""Ensure that the _transform_query function operates correctly."""
assert transform.query(name="test", age=30) == {"name": "test", "age": 30}
assert transform.query(age__lt=30) == {"age": {"$lt": 30}}
assert transform.query(age__gt=20, age__lt=50) == {
@ -88,8 +87,7 @@ class TestTransform(unittest.TestCase):
assert update == {"$set": {"tags": ["mongo", "db"]}}
def test_query_field_name(self):
"""Ensure that the correct field name is used when querying.
"""
"""Ensure that the correct field name is used when querying."""
class Comment(EmbeddedDocument):
content = StringField(db_field="commentContent")

View File

@ -23,8 +23,7 @@ class TestQ(unittest.TestCase):
self.Person = Person
def test_empty_q(self):
"""Ensure that empty Q objects won't hurt.
"""
"""Ensure that empty Q objects won't hurt."""
q1 = Q()
q2 = Q(age__gte=18)
q3 = Q()
@ -58,8 +57,7 @@ class TestQ(unittest.TestCase):
assert Post.objects.filter(Q(created_user=user)).count() == 1
def test_and_combination(self):
"""Ensure that Q-objects correctly AND together.
"""
"""Ensure that Q-objects correctly AND together."""
class TestDoc(Document):
x = IntField()
@ -89,8 +87,7 @@ class TestQ(unittest.TestCase):
assert query.to_query(TestDoc) == mongo_query
def test_or_combination(self):
"""Ensure that Q-objects correctly OR together.
"""
"""Ensure that Q-objects correctly OR together."""
class TestDoc(Document):
x = IntField()
@ -101,8 +98,7 @@ class TestQ(unittest.TestCase):
assert query == {"$or": [{"x": {"$lt": 3}}, {"x": {"$gt": 7}}]}
def test_and_or_combination(self):
"""Ensure that Q-objects handle ANDing ORed components.
"""
"""Ensure that Q-objects handle ANDing ORed components."""
class TestDoc(Document):
x = IntField()
@ -136,8 +132,7 @@ class TestQ(unittest.TestCase):
assert 2 == TestDoc.objects(q1 & q2).count()
def test_or_and_or_combination(self):
"""Ensure that Q-objects handle ORing ANDed ORed components. :)
"""
"""Ensure that Q-objects handle ORing ANDed ORed components. :)"""
class TestDoc(Document):
x = IntField()
@ -208,8 +203,7 @@ class TestQ(unittest.TestCase):
assert test.count() == 3
def test_q(self):
"""Ensure that Q objects may be used to query for documents.
"""
"""Ensure that Q objects may be used to query for documents."""
class BlogPost(Document):
title = StringField()
@ -286,8 +280,7 @@ class TestQ(unittest.TestCase):
self.Person.objects.filter("user1")
def test_q_regex(self):
"""Ensure that Q objects can be queried using regexes.
"""
"""Ensure that Q objects can be queried using regexes."""
person = self.Person(name="Guido van Rossum")
person.save()
@ -320,8 +313,7 @@ class TestQ(unittest.TestCase):
)
def test_q_lists(self):
"""Ensure that Q objects query ListFields correctly.
"""
"""Ensure that Q objects query ListFields correctly."""
class BlogPost(Document):
tags = ListField(StringField())

View File

@ -194,14 +194,12 @@ class ConnectionTest(unittest.TestCase):
assert len(mongoengine.connection._connections) == 3
def test_connect_with_invalid_db_name(self):
"""Ensure that connect() method fails fast if db name is invalid
"""
"""Ensure that connect() method fails fast if db name is invalid"""
with pytest.raises(InvalidName):
connect("mongomock://localhost")
def test_connect_with_db_name_external(self):
"""Ensure that connect() works if db name is $external
"""
"""Ensure that connect() works if db name is $external"""
"""Ensure that the connect() method works properly."""
connect("$external")
@ -217,16 +215,14 @@ class ConnectionTest(unittest.TestCase):
assert isinstance(conn, pymongo.mongo_client.MongoClient)
def test_connect_with_invalid_db_name_type(self):
"""Ensure that connect() method fails fast if db name has invalid type
"""
"""Ensure that connect() method fails fast if db name has invalid type"""
with pytest.raises(TypeError):
non_string_db_name = ["e. g. list instead of a string"]
connect(non_string_db_name)
@require_mongomock
def test_connect_in_mocking(self):
"""Ensure that the connect() method works properly in mocking.
"""
"""Ensure that the connect() method works properly in mocking."""
connect("mongoenginetest", host="mongomock://localhost")
conn = get_connection()
assert isinstance(conn, mongomock.MongoClient)
@ -270,8 +266,7 @@ class ConnectionTest(unittest.TestCase):
@require_mongomock
def test_default_database_with_mocking(self):
"""Ensure that the default database is correctly set when using mongomock.
"""
"""Ensure that the default database is correctly set when using mongomock."""
disconnect_all()
class SomeDocument(Document):
@ -452,8 +447,7 @@ class ConnectionTest(unittest.TestCase):
disconnect_all()
def test_sharing_connections(self):
"""Ensure that connections are shared when the connection settings are exactly the same
"""
"""Ensure that connections are shared when the connection settings are exactly the same"""
connect("mongoenginetests", alias="testdb1")
expected_connection = get_connection("testdb1")
@ -564,8 +558,7 @@ class ConnectionTest(unittest.TestCase):
authd_conn.admin.system.users.delete_many({})
def test_register_connection(self):
"""Ensure that connections with different aliases may be registered.
"""
"""Ensure that connections with different aliases may be registered."""
register_connection("testdb", "mongoenginetest2")
with pytest.raises(ConnectionFailure):
@ -578,8 +571,7 @@ class ConnectionTest(unittest.TestCase):
assert db.name == "mongoenginetest2"
def test_register_connection_defaults(self):
"""Ensure that defaults are used when the host and port are None.
"""
"""Ensure that defaults are used when the host and port are None."""
register_connection("testdb", "mongoenginetest", host=None, port=None)
conn = get_connection("testdb")

View File

@ -117,8 +117,7 @@ class TestContextManagers:
assert 1 == Group.objects.count()
def test_no_dereference_context_manager_object_id(self):
"""Ensure that DBRef items in ListFields aren't dereferenced.
"""
"""Ensure that DBRef items in ListFields aren't dereferenced."""
connect("mongoenginetest")
class User(Document):
@ -155,8 +154,7 @@ class TestContextManagers:
assert isinstance(group.generic, User)
def test_no_dereference_context_manager_dbref(self):
"""Ensure that DBRef items in ListFields aren't dereferenced.
"""
"""Ensure that DBRef items in ListFields aren't dereferenced."""
connect("mongoenginetest")
class User(Document):

View File

@ -16,8 +16,7 @@ class FieldTest(unittest.TestCase):
cls.db.drop_database("mongoenginetest")
def test_list_item_dereference(self):
"""Ensure that DBRef items in ListFields are dereferenced.
"""
"""Ensure that DBRef items in ListFields are dereferenced."""
class User(Document):
name = StringField()
@ -75,8 +74,7 @@ class FieldTest(unittest.TestCase):
Group.drop_collection()
def test_list_item_dereference_dref_false(self):
"""Ensure that DBRef items in ListFields are dereferenced.
"""
"""Ensure that DBRef items in ListFields are dereferenced."""
class User(Document):
name = StringField()
@ -132,8 +130,7 @@ class FieldTest(unittest.TestCase):
assert q == 2
def test_list_item_dereference_orphan_dbref(self):
"""Ensure that orphan DBRef items in ListFields are dereferenced.
"""
"""Ensure that orphan DBRef items in ListFields are dereferenced."""
class User(Document):
name = StringField()
@ -176,8 +173,7 @@ class FieldTest(unittest.TestCase):
Group.drop_collection()
def test_list_item_dereference_dref_false_stores_as_type(self):
"""Ensure that DBRef items are stored as their type
"""
"""Ensure that DBRef items are stored as their type"""
class User(Document):
my_id = IntField(primary_key=True)
@ -198,8 +194,7 @@ class FieldTest(unittest.TestCase):
assert group.members == [user]
def test_handle_old_style_references(self):
"""Ensure that DBRef items in ListFields are dereferenced.
"""
"""Ensure that DBRef items in ListFields are dereferenced."""
class User(Document):
name = StringField()
@ -232,8 +227,7 @@ class FieldTest(unittest.TestCase):
assert group.members[-1].name == "String!"
def test_migrate_references(self):
"""Example of migrating ReferenceField storage
"""
"""Example of migrating ReferenceField storage"""
# Create some sample data
class User(Document):
@ -278,8 +272,7 @@ class FieldTest(unittest.TestCase):
assert isinstance(raw_data["members"][0], ObjectId)
def test_recursive_reference(self):
"""Ensure that ReferenceFields can reference their own documents.
"""
"""Ensure that ReferenceFields can reference their own documents."""
class Employee(Document):
name = StringField()
@ -402,8 +395,7 @@ class FieldTest(unittest.TestCase):
assert "[<Person: Mother>, <Person: Daughter>]" == "%s" % Person.objects()
def test_circular_reference_on_self(self):
"""Ensure you can handle circular references
"""
"""Ensure you can handle circular references"""
class Person(Document):
name = StringField()
@ -430,8 +422,7 @@ class FieldTest(unittest.TestCase):
assert "[<Person: Mother>, <Person: Daughter>]" == "%s" % Person.objects()
def test_circular_tree_reference(self):
"""Ensure you can handle circular references with more than one level
"""
"""Ensure you can handle circular references with more than one level"""
class Other(EmbeddedDocument):
name = StringField()
@ -557,8 +548,7 @@ class FieldTest(unittest.TestCase):
assert "User" in m.__class__.__name__
def test_generic_reference_orphan_dbref(self):
"""Ensure that generic orphan DBRef items in ListFields are dereferenced.
"""
"""Ensure that generic orphan DBRef items in ListFields are dereferenced."""
class UserA(Document):
name = StringField()
@ -1168,8 +1158,7 @@ class FieldTest(unittest.TestCase):
assert msg.author.name == "new-name"
def test_list_lookup_not_checked_in_map(self):
"""Ensure we dereference list data correctly
"""
"""Ensure we dereference list data correctly"""
class Comment(Document):
id = IntField(primary_key=True)
@ -1191,8 +1180,7 @@ class FieldTest(unittest.TestCase):
assert 1 == msg.comments[1].id
def test_list_item_dereference_dref_false_save_doesnt_cause_extra_queries(self):
"""Ensure that DBRef items in ListFields are dereferenced.
"""
"""Ensure that DBRef items in ListFields are dereferenced."""
class User(Document):
name = StringField()
@ -1221,8 +1209,7 @@ class FieldTest(unittest.TestCase):
assert q == 2
def test_list_item_dereference_dref_true_save_doesnt_cause_extra_queries(self):
"""Ensure that DBRef items in ListFields are dereferenced.
"""
"""Ensure that DBRef items in ListFields are dereferenced."""
class User(Document):
name = StringField()

View File

@ -22,8 +22,7 @@ class ConnectionTest(unittest.TestCase):
mongoengine.connection._dbs = {}
def test_replicaset_uri_passes_read_preference(self):
"""Requires a replica set called "rs" on port 27017
"""
"""Requires a replica set called "rs" on port 27017"""
try:
conn = mongoengine.connect(
db="mongoenginetest",