1527 Commits

Author SHA1 Message Date
Bastien Gérard
799cdafae6 remove references to nose 2019-10-31 23:02:28 +01:00
Bastien Gérard
bc0c55e49a improve tests health (flake8 warnings) 2019-10-31 23:01:27 +01:00
Bastien Gérard
c61c6a8525 fix == None assertions 2019-10-31 22:59:49 +01:00
Bastien Gérard
3e764d068c fix remaining assertRaises 2019-10-31 22:59:49 +01:00
Bastien Gérard
ac25f4b98b ran unittest2pytest 2019-10-31 22:59:49 +01:00
Bastien Gérard
37ca79e9c5 fix black formatting 2019-10-31 22:39:53 +01:00
Bastien Gérard
bbfa978861 switch test runner from nose to pytest 2019-10-31 20:39:49 +01:00
Bastien Gérard
54ca7bf09f fix associated test to avoid discrepencies btw py2 and py3 2019-10-28 23:33:37 +01:00
Bastien Gérard
8bf5370b6c Improve error message from InvalidDocumentError whenever an embedded document has a bad shape (e.g due to migration) 2019-10-28 22:05:13 +01:00
Bastien Gérard
ecefa05e03
Merge pull request #2174 from bagerard/upgrade_latest_pymongo_travis
add latest pymongo 3.9 as part of the CI
2019-10-28 21:22:00 +01:00
Bastien Gérard
5bcc679194 fix 2 pymongo deprecation warnings 2019-10-10 22:55:44 +02:00
Bastien Gérard
e3cd553f82 add latest pymongo 3.9 as part of the CI 2019-10-04 21:46:47 +02:00
Bastien Gérard
933cb1d5c7
Merge pull request #2144 from 0a69911a/master
Implement collation for queryset
2019-09-11 23:27:25 +02:00
Bastien Gérard
7d94af0e31 add test coverage for no_cursor_timeout to support recent fix 2019-09-11 21:53:30 +02:00
Bastien Gérard
693195f70b fix test_pickable that was brought back to life recently 2019-08-31 22:28:31 +03:00
Bastien Gérard
2267b7e7d7 rename remaining files for pytest migration 2019-08-30 16:27:56 +03:00
otrofimov
47c67ecc99 Merge branch 'master' of https://github.com/MongoEngine/mongoengine 2019-08-29 11:48:07 +03:00
Bastien Gérard
ddececbfea rename all test files so that they are prefixed by test_{orginal_filename}.py 2019-08-28 16:01:44 +03:00
otrofimov
71a6f3d1a4 test_collation:
Added test with `pymongo.collation.Collation` object
Readable list of BlogPost names for test
2019-08-21 18:26:10 +03:00
otrofimov
fbb3bf869c compatibility with black 2019-08-08 15:56:20 +03:00
otrofimov
b887ea9623 Implement collation for queryset 2019-08-08 11:55:45 +03:00
Bastien Gérard
c68e3e1238 Add test case for list update by negative index 2019-07-24 21:37:16 +02:00
Bastien Gérard
0d01365751
Merge pull request #2131 from NMFR/master
Set default database when using mongomock.
2019-07-22 11:56:56 +02:00
Nuno Rodrigues
05a22d5a54 Extract test to its own method 2019-07-22 08:42:17 +00:00
Nuno Rodrigues
2424ece0c5 Fix a linting error 2019-07-16 13:40:46 +00:00
Nuno Rodrigues
2d02551d0a Add test 2019-07-15 17:54:46 +01:00
Stefan Wójcik
ac416aeeb3
Improve BaseDocument.from_json tests and documentation (#2127) 2019-07-15 12:15:55 +02:00
Stefan Wójcik
aa76ccdd25
Fix Document._object_key (#2125)
Previous implementation of `Document._object_key` was *pretending* to work on
MongoEngine-level fields (e.g. using "pk" instead of "_id" and separating
nested field parts by "__" instead of "."), but then it was also attempting to
transform field names from the `shard_key` into DB-level fields.

This, expectedly, didn't really work well. Most of the test cases added in this
commit were failing prior to the code fixes.
2019-07-09 12:08:26 +02:00
Stefan Wójcik
50555ec73e
Better management of the automatic "_cls" field (#2112)
* Rename BaseQuerySet._initial_query to BaseQuerySet._cls_query

This new name more accurately reflects the purpose of the dict. It is either
empty for documents that don't use inheritance or it contains a `{"_cls": ...}`
shape query. There was nothing "initial" about it per se.

* Drop read_preference as a kwarg on BaseQuerySet.__call__/filter

It was a poor design choice to offer two different ways to do the same thing:
1. `SomeDoc.objects(foo=bar, bar=baz).read_preference(...)`
2. `SomeDoc.objects(foo=bar, bar=baz, read_preference=...)`

Option 1 is good because it's immediately obvious which part defines the query
to be used and which part defines the read preference.

Option 2 is bad because you don't immediately know whether `read_preference`
is a query kwarg or a reserved keyword with some special behavior. If you
wanted to be particularly cruel, you could even write
`SomeDoc.objects(foo=bar, read_preference=..., bar=baz)`.

THIS IS A BREAKING CHANGE. From now on you have to use the
`BaseQuerySet.read_preference(...)` method.

* Add a BaseQuerySet.clear_cls_query method + get rid of the class_check kwarg

This is similar to what the previous commit did to read preference except that
in this case we were still missing a `BaseQuerySet` method for clearing the
`_cls` query.

Now, instead of the undocumented, untested, and confusing interface:
    `ParentDoc.objects(foo=bar, bar=baz, class_check=False)`
We do:
    `ParentDoc.objects(foo=bar, bar=baz).clear_cls_query()`
2019-07-03 11:07:55 +02:00
Bastien Gérard
d37a30e083 improve doc (based on review) 2019-06-30 20:46:40 +02:00
Stefan Wójcik
9170eea784
Rename MongoEngineConnectionError to ConnectionFailure (#2111)
I originally changed the exception name from `ConnectionError` to
`MongoEngineConnectionError` in
b02904ee75,
inspired by landscape.io's package health report, which argued that
`ConnectionError` is already a built-in exception in Python 3 (which it is:
https://docs.python.org/3/library/exceptions.html#ConnectionError).

I do agree that we shouldn't override built-in exceptions. [0] That said, it’s
silly to add a "MongoEngine" prefix to any class within the `mongoengine`
module (and *especially* to *just one* exception class out of many). I've
decided to do what PyMongo does (
8855a510a8/pymongo/errors.py (L59))
and call this exception `ConnectionFailure`.

Note that this is a breaking change and people will need to rename
`MongoEngineConnectionError`s in their code to `ConnectionFailure`. Moreover,
if they use PyMongo's `ConnectionFailure` for anything, they'll need to take
    extra care to avoid conflicts, e.g. by using:
```
from mongoengine import ConnectionFailure as MongoEngineConnectionFailure
```

[0] Note that some popular packages still overwrite `ConnectionError`, e.g.
4983a9bde3/requests/exceptions.py (L32)
or
0be4d29206/redis/exceptions.py (L8)
2019-06-30 09:23:32 +02:00
Stefan Wójcik
609f50d261
Fix the duplicate ListField max_length test (#2110)
This is a follow-up after #2107.

Not sure what happened here, but in
87194856ec
I committed a copy-paste of the same test instead of a test validating the
max_length behavior along with a "set" operator.
2019-06-27 16:45:31 +02:00
Stefan Wójcik
82f0eb1cbc
Add a max_length param to the ListField (#2107)
This is similar to the `max_length` param of a `StringField`.

Sometimes you don't want your lists to be able to grow indefinitely.
2019-06-27 15:07:02 +02:00
Stefan Wójcik
b47669403b
Format the codebase using Black (#2109)
This commit:
1. Formats all of our existing code using `black`.
2. Adds a note about using `black` to `CONTRIBUTING.rst`.
3. Runs `black --check` as part of CI (failing builds that aren't properly formatted).
2019-06-27 13:05:54 +02:00
Stefan Wojcik
91899acfe5 Clarify unack'd write concern not returning the deleted count [ci skip] 2019-06-26 15:14:43 +02:00
Stefan Wójcik
ffedd33101
Drop support for positional arguments when instantiating a document (#2103)
For example, if you had the following class:
```
class Person(Document):
    name = StringField()
    age = IntField()
```

You could instantiate an object of such class by doing one of the following:
1. `new_person = Person('Tom', 30)`
2. `new_person = Person('Tom', age=30)`
3. `new_person = Person(name='Tom', age=30)`

From now on, only option (3) is allowed.

Supporting positional arguments may sound like a reasonable idea in this
heavily simplified example, but in real life it's almost never what you want
(especially if you use inheritance in your document definitions) and it may
lead to ugly bugs. We should not rely on the *order* of fields to match a given
value to a given name.

This also helps us simplify the code e.g. by dropping the confusing (and
undocumented) `BaseDocument._auto_id_field` attribute.
2019-06-26 11:31:11 +02:00
Stefan Wojcik
e57d834a0d Fix automated tests for py3 2019-06-25 12:41:59 +02:00
Stefan Wojcik
f45552f8f8 Drop support for positional arguments when instantiating a document
For example, if you had the following class:
```
class Person(Document):
    name = StringField()
    age = IntField()
```

You could instantiate an object of such class by doing one of the following:
1. `new_person = Person('Tom', 30)`
2. `new_person = Person('Tom', age=30)`
3. `new_person = Person(name='Tom', age=30)`

From now on, only option (3) is allowed.

Supporting positional arguments may sound like a reasonable idea in this
heavily simplified example, but in real life it's almost never what you want
(especially if you use inheritance in your document definitions) and it may
lead to ugly bugs. We should not rely on the *order* of fields to match a given
value to a given name.

This also helps us simplify the code e.g. by dropping the confusing (and
undocumented) `BaseDocument._auto_id_field` attribute.
2019-06-24 15:44:35 +02:00
Bastien Gérard
8f57279dc7 remove pymongo deprecated methods: find_and_modify & remove 2019-06-19 23:04:23 +02:00
Bastien Gérard
2abcf4764d minor fixes based on review of #2082 2019-06-18 22:15:53 +02:00
Stefan Wójcik
bb0b1e88ef
Split up custom PK field tests (#2095)
This more closely aligns with the rule that a single tests should test one
thing and one thing only. Previous code tested like 4 different things in a
single test and was hard to follow.
2019-06-18 15:43:46 +02:00
Bastien Gérard
5a2e268160 Add test case to prevent regression 2019-06-17 22:19:41 +02:00
Bastien Gérard
6e8ea50c19 "added another aggregation test"
This reverts commit 4c31193b82ca665fe27b1ddce3cbacbb2b7fcd32.
2019-06-14 21:04:02 +02:00
Bastien Gérard
4c31193b82 Revert "added another aggregation test"
This reverts commit d7285d43dd2be65a0b5b0a60292ba085788e86c7.
2019-06-13 20:53:56 +02:00
Bastien Gérard
d7285d43dd added another aggregation test 2019-06-12 23:54:20 +02:00
Stefan Wojcik
996618a495 Fix wording of an exception message in QuerySet.insert 2019-06-12 08:29:59 +02:00
erdenezul
1f02d5fbbd
Merge pull request #1570 from erdenezul/remove_save_embedded
EmbeddedDocument should not have save method #1552
2019-06-11 16:15:53 +02:00
Stefan Wojcik
f131b18cbe Make test_update_shard_key_routing more resilient 2019-06-11 15:50:22 +02:00
Erdenezul Batmunkh
7ad6f036e7 Remove test 2019-06-11 13:16:33 +02:00
Erdenezul Batmunkh
1d29b824a8 Remove save method from test 2019-06-11 12:52:29 +02:00