rename all test files so that they are prefixed by test_{orginal_filename}.py

This commit is contained in:
Bastien Gérard 2019-08-28 16:01:44 +03:00
parent 99a58d5c91
commit ddececbfea
21 changed files with 90 additions and 155 deletions

View File

@ -1,4 +0,0 @@
from .all_warnings import AllWarnings
from .document import *
from .queryset import *
from .fields import *

View File

@ -1,40 +0,0 @@
"""
This test has been put into a module. This is because it tests warnings that
only get triggered on first hit. This way we can ensure its imported into the
top level and called first by the test suite.
"""
import unittest
import warnings
from mongoengine import *
__all__ = ("AllWarnings",)
class AllWarnings(unittest.TestCase):
def setUp(self):
connect(db="mongoenginetest")
self.warning_list = []
self.showwarning_default = warnings.showwarning
warnings.showwarning = self.append_to_warning_list
def append_to_warning_list(self, message, category, *args):
self.warning_list.append({"message": message, "category": category})
def tearDown(self):
# restore default handling of warnings
warnings.showwarning = self.showwarning_default
def test_document_collection_syntax_warning(self):
class NonAbstractBase(Document):
meta = {"allow_inheritance": True}
class InheritedDocumentFailTest(NonAbstractBase):
meta = {"collection": "fail"}
warning = self.warning_list[0]
self.assertEqual(SyntaxWarning, warning["category"])
self.assertEqual(
"non_abstract_base", InheritedDocumentFailTest._get_collection_name()
)

View File

@ -0,0 +1,37 @@
"""
This test has been put into a module. This is because it tests warnings that
only get triggered on first hit. This way we can ensure its imported into the
top level and called first by the test suite.
"""
import unittest
import warnings
from mongoengine import *
class TestAllWarnings(unittest.TestCase):
def setUp(self):
connect(db="mongoenginetest")
self.warning_list = []
self.showwarning_default = warnings.showwarning
warnings.showwarning = self.append_to_warning_list
def append_to_warning_list(self, message, category, *args):
self.warning_list.append({"message": message, "category": category})
def tearDown(self):
# restore default handling of warnings
warnings.showwarning = self.showwarning_default
def test_document_collection_syntax_warning(self):
class NonAbstractBase(Document):
meta = {"allow_inheritance": True}
class InheritedDocumentFailTest(NonAbstractBase):
meta = {"collection": "fail"}
warning = self.warning_list[0]
self.assertEqual(SyntaxWarning, warning["category"])
self.assertEqual(
"non_abstract_base", InheritedDocumentFailTest._get_collection_name()
)

View File

@ -1,13 +0,0 @@
import unittest
from .class_methods import *
from .delta import *
from .dynamic import *
from .indexes import *
from .inheritance import *
from .instance import *
from .json_serialisation import *
from .validation import *
if __name__ == "__main__":
unittest.main()

View File

@ -2,15 +2,12 @@
import unittest
from mongoengine import *
from mongoengine.pymongo_support import list_collection_names
from mongoengine.queryset import NULLIFY, PULL
from mongoengine.connection import get_db
__all__ = ("ClassMethodsTest",)
from mongoengine.pymongo_support import list_collection_names
from mongoengine.queryset import NULLIFY, PULL
class ClassMethodsTest(unittest.TestCase):
class TestClassMethods(unittest.TestCase):
def setUp(self):
connect(db="mongoenginetest")
self.db = get_db()

View File

@ -7,9 +7,9 @@ from mongoengine.pymongo_support import list_collection_names
from tests.utils import MongoDBTestCase
class DeltaTest(MongoDBTestCase):
class TestDelta(MongoDBTestCase):
def setUp(self):
super(DeltaTest, self).setUp()
super(TestDelta, self).setUp()
class Person(Document):
name = StringField()

View File

@ -179,7 +179,7 @@ class TestDynamicDocument(MongoDBTestCase):
def test_three_level_complex_data_lookups(self):
"""Ensure you can query three level document dynamic fields"""
p = self.Person.objects.create(misc={"hello": {"hello2": "world"}})
self.Person.objects.create(misc={"hello": {"hello2": "world"}})
self.assertEqual(1, self.Person.objects(misc__hello__hello2="world").count())
def test_complex_embedded_document_validation(self):

View File

@ -4,16 +4,13 @@ from datetime import datetime
from nose.plugins.skip import SkipTest
from pymongo.errors import OperationFailure
import pymongo
from six import iteritems
from mongoengine import *
from mongoengine.connection import get_db
__all__ = ("IndexesTest",)
class IndexesTest(unittest.TestCase):
class TestIndexes(unittest.TestCase):
def setUp(self):
self.connection = connect(db="mongoenginetest")
self.db = get_db()

View File

@ -15,13 +15,11 @@ from mongoengine import (
StringField,
)
from mongoengine.pymongo_support import list_collection_names
from tests.utils import MongoDBTestCase
from tests.fixtures import Base
__all__ = ("InheritanceTest",)
from tests.utils import MongoDBTestCase
class InheritanceTest(MongoDBTestCase):
class TestInheritance(MongoDBTestCase):
def tearDown(self):
for collection in list_collection_names(self.db):
self.db.drop_collection(collection)
@ -401,7 +399,7 @@ class InheritanceTest(MongoDBTestCase):
class Animal(FinalDocument):
name = StringField()
with self.assertRaises(ValueError) as cm:
with self.assertRaises(ValueError):
class Mammal(Animal):
pass

View File

@ -39,10 +39,8 @@ from tests.utils import MongoDBTestCase, get_as_pymongo
TEST_IMAGE_PATH = os.path.join(os.path.dirname(__file__), "../fields/mongoengine.png")
__all__ = ("InstanceTest",)
class InstanceTest(MongoDBTestCase):
class TestInstance(MongoDBTestCase):
def setUp(self):
class Job(EmbeddedDocument):
name = StringField()

View File

@ -1,21 +1,14 @@
import unittest
import uuid
from nose.plugins.skip import SkipTest
from datetime import datetime
from bson import ObjectId
import pymongo
from mongoengine import *
__all__ = ("TestJson",)
from tests.utils import MongoDBTestCase
class TestJson(unittest.TestCase):
def setUp(self):
connect(db="mongoenginetest")
class TestJson(MongoDBTestCase):
def test_json_names(self):
"""
Going to test reported issue:

View File

@ -3,14 +3,10 @@ import unittest
from datetime import datetime
from mongoengine import *
__all__ = ("ValidatorErrorTest",)
from tests.utils import MongoDBTestCase
class ValidatorErrorTest(unittest.TestCase):
def setUp(self):
connect(db="mongoenginetest")
class TestValidatorError(MongoDBTestCase):
def test_to_dict(self):
"""Ensure a ValidationError handles error to_dict correctly.
"""

View File

@ -1,3 +0,0 @@
from .fields import *
from .file_tests import *
from .geo import *

View File

@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
import uuid
from bson import Binary
from nose.plugins.skip import SkipTest
import six
from bson import Binary
from mongoengine import *
from tests.utils import MongoDBTestCase
@ -77,8 +76,6 @@ class TestBinaryField(MongoDBTestCase):
self.assertEqual(0, Attachment.objects.count())
def test_primary_filter_by_binary_pk_as_str(self):
raise SkipTest("Querying by id as string is not currently supported")
class Attachment(Document):
id = BinaryField(primary_key=True)

View File

@ -2,39 +2,38 @@
import datetime
import unittest
from bson import DBRef, ObjectId, SON
from nose.plugins.skip import SkipTest
from bson import DBRef, ObjectId, SON
from mongoengine import (
Document,
StringField,
IntField,
DateTimeField,
DateField,
ValidationError,
BooleanField,
ComplexDateTimeField,
FloatField,
ListField,
ReferenceField,
DateField,
DateTimeField,
DictField,
Document,
DoesNotExist,
DynamicDocument,
DynamicField,
EmbeddedDocument,
EmbeddedDocumentField,
GenericReferenceField,
DoesNotExist,
NotRegistered,
OperationError,
DynamicField,
FieldDoesNotExist,
EmbeddedDocumentListField,
MultipleObjectsReturned,
NotUniqueError,
BooleanField,
ObjectIdField,
SortedListField,
FieldDoesNotExist,
FloatField,
GenericLazyReferenceField,
GenericReferenceField,
IntField,
LazyReferenceField,
DynamicDocument,
ListField,
MultipleObjectsReturned,
NotRegistered,
NotUniqueError,
ObjectIdField,
OperationError,
ReferenceField,
SortedListField,
StringField,
ValidationError,
)
from mongoengine.base import BaseField, EmbeddedDocumentList, _document_registry
from mongoengine.errors import DeprecatedError
@ -42,7 +41,7 @@ from mongoengine.errors import DeprecatedError
from tests.utils import MongoDBTestCase
class FieldTest(MongoDBTestCase):
class TestField(MongoDBTestCase):
def test_default_values_nothing_set(self):
"""Ensure that default field values are used when creating
a document.
@ -343,7 +342,7 @@ class FieldTest(MongoDBTestCase):
doc.save()
# Unset all the fields
obj = HandleNoneFields._get_collection().update(
HandleNoneFields._get_collection().update(
{"_id": doc.id},
{"$unset": {"str_fld": 1, "int_fld": 1, "flt_fld": 1, "comp_dt_fld": 1}},
)
@ -416,13 +415,13 @@ class FieldTest(MongoDBTestCase):
# name starting with $
with self.assertRaises(ValueError):
class User(Document):
class UserX1(Document):
name = StringField(db_field="$name")
# name containing a null character
with self.assertRaises(ValueError):
class User(Document):
class UserX2(Document):
name = StringField(db_field="name\0")
def test_list_validation(self):
@ -2267,7 +2266,7 @@ class FieldTest(MongoDBTestCase):
Doc(bar="test")
class EmbeddedDocumentListFieldTestCase(MongoDBTestCase):
class TestEmbeddedDocumentListField(MongoDBTestCase):
def setUp(self):
"""
Create two BlogPost entries in the database, each with
@ -2320,7 +2319,7 @@ class EmbeddedDocumentListFieldTestCase(MongoDBTestCase):
# Test with a Document
post = self.BlogPost(comments=Title(content="garbage"))
with self.assertRaises(ValidationError) as e:
with self.assertRaises(ValidationError):
post.validate()
self.assertIn("'comments'", str(ctx_err.exception))
self.assertIn(

View File

@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
import copy
import os
import unittest
import tempfile
import unittest
import gridfs
from nose.plugins.skip import SkipTest
import six
from nose.plugins.skip import SkipTest
from mongoengine import *
from mongoengine.connection import get_db
from mongoengine.python_support import StringIO
@ -35,7 +35,7 @@ def get_file(path):
return bytes_io
class FileTest(MongoDBTestCase):
class TestFileField(MongoDBTestCase):
def tearDown(self):
self.db.drop_collection("fs.files")
self.db.drop_collection("fs.chunks")

View File

@ -2,16 +2,10 @@
import unittest
from mongoengine import *
from mongoengine.connection import get_db
__all__ = ("GeoFieldTest",)
from tests.utils import MongoDBTestCase
class GeoFieldTest(unittest.TestCase):
def setUp(self):
connect(db="mongoenginetest")
self.db = get_db()
class TestGeoField(MongoDBTestCase):
def _test_for_expected_error(self, Cls, loc, expected):
try:
Cls(loc=loc).validate()

View File

@ -1,6 +0,0 @@
from .transform import *
from .field_list import *
from .queryset import *
from .visitor import *
from .geo import *
from .modify import *

View File

@ -3,10 +3,8 @@ import unittest
from mongoengine import *
from mongoengine.queryset import QueryFieldList
__all__ = ("QueryFieldListTest", "OnlyExcludeAllTest")
class QueryFieldListTest(unittest.TestCase):
class TestQueryFieldList(unittest.TestCase):
def test_empty(self):
q = QueryFieldList()
self.assertFalse(q)
@ -66,7 +64,7 @@ class QueryFieldListTest(unittest.TestCase):
self.assertEqual(q.as_dict(), {"a": {"$slice": 5}})
class OnlyExcludeAllTest(unittest.TestCase):
class TestOnlyExcludeAll(unittest.TestCase):
def setUp(self):
connect(db="mongoenginetest")

View File

@ -6,10 +6,7 @@ from mongoengine import *
from tests.utils import MongoDBTestCase
__all__ = ("GeoQueriesTest",)
class GeoQueriesTest(MongoDBTestCase):
class TestGeoQueries(MongoDBTestCase):
def _create_event_data(self, point_field_class=GeoPointField):
"""Create some sample data re-used in many of the tests below."""

View File

@ -41,7 +41,7 @@ def get_key_compat(mongo_ver):
return ORDER_BY_KEY, CMD_QUERY_KEY
class QuerySetTest(unittest.TestCase):
class TestQueryset(unittest.TestCase):
def setUp(self):
connect(db="mongoenginetest")
connect(db="mongoenginetest2", alias="test2")