1548 Commits

Author SHA1 Message Date
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
Bastien Gérard
0ac59c67ea
Merge pull request #2068 from bagerard/fix_connection_auth_same_host
Fix connection issue when using different authentication in different dbs
2019-06-07 21:08:26 +02:00
Stefan Wojcik
8e8c74c621 Drop the unused mongodb_version attribute in IndexesTest 2019-06-07 12:35:38 +02:00
Stefan Wojcik
f996f3df74 Cleaner test_hint 2019-06-07 12:34:32 +02:00
Bastien Gérard
15f4d4fee6 fix tests for diff mongo vers 2019-06-05 21:51:21 +02:00
Bastien Gérard
b407c0e6c6 add test for shard key routing (ported from https://github.com/closeio/mongoengine/commit/43f35f5) 2019-06-04 23:17:10 +02:00
Bastien Gérard
27ea01ee05 refactored datetime to_mongo, separating parsing from str + added test 2019-06-04 23:16:26 +02:00
Bastien Gérard
7ed5829b2c Add test on datetime field - parse datetime as str 2019-06-04 23:16:26 +02:00
Bastien Gérard
84c42ed58c Add tests 2019-06-04 22:35:42 +02:00
Bastien Gérard
962997ed16 fix flaky test due to signal receiver garbage collection 2019-06-01 11:13:28 +02:00
Bastien Gérard
9ae8fe7c2d Improve perf of Doc.save by preventing a full to_mongo() call just to get the created variable 2019-06-01 11:13:28 +02:00
Bastien Gérard
1907133f99
Merge pull request #2050 from bagerard/change_custom_field_validation_raise
custom field validator is now expected to raise a ValidationError
2019-06-01 10:45:43 +02:00
Stefan Wójcik
4334955e39
Update the test matrix to reflect what's supported in 2019 (#2066)
Previously, we were running the test suite for several combinations of MongoDB,
Python, and PyMongo:
- PyPy, MongoDB v2.6, PyMongo v3.x (which really means v3.6.1 at the moment)
- Python v2.7, MongoDB v2.6, PyMongo v3.x
- Python v3.5, MongoDB v2.6, PyMongo v3.x
- Python v3.6, MongoDB v2.6, PyMongo v3.x
- Python v2.7, MongoDB v3.0, PyMongo v3.5.0
- Python v3.6, MongoDB v3.0, PyMongo v3.5.0
- Python v3.5, MongoDB v3.2, PyMongo v3.x
- Python v3.6, MongoDB v3.2, PyMongo v3.x
- Python v3.6, MongoDB v3.4, PyMongo v3.x
- Python v3.6, MongoDB v3.6, PyMongo v3.x

There were a couple issues with this setup:
1. MongoDB v2.6 – v3.2 have reached their End of Life already (v2.6 almost 3
   years ago!). See the "MongoDB Server" section on
   https://www.mongodb.com/support-policy.
2. We were only testing two recent-ish PyMongo versions (v3.5.0 & v3.6.1).
   We were not testing the oldest actively supported MongoDB/PyMongo/Python
   setup.

This PR updates the test matrix so that these problems are solved. For the
sake of simplicity, it does not yet attempt to cover MongoDB v4.0:
- PyPy, MongoDB v3.4, PyMongo v3.x (aka v3.6.1 at the moment)
- Python v2.7, MongoDB v3.4, PyMongo v3.x
- Python v3.5, MongoDB v3.4, PyMongo v3.x
- Python v3.6, MongoDB v3.4, PyMongo v3.x
- Python v2.7, MongoDB v3.4, PyMongo v3.4
- Python v3.6, MongoDB v3.6, PyMongo v3.x
2019-05-31 11:01:15 +02:00
Bastien Gérard
7d0687ec73 custom field validator is now expected to raise a ValidationError (drop support for returning True/False) 2019-05-28 09:26:07 +02:00
Bastien Gérard
6e1c132ee8 Improve minor things in the tests 2019-05-26 22:17:58 +02:00
Bastien Gérard
6a843cc8b2 Merge branch 'master' of github.com:MongoEngine/mongoengine into remove_pymongo2_support_dead_code 2019-05-23 21:06:15 +02:00
erdenezul
9a55caed75
Merge pull request #2056 from bagerard/support_mongo36
Add support for MongoDB 3.6 and Python3.7 in travis
2019-05-18 17:06:48 +02:00
Bastien Gérard
2e01eb87db Add support for MongoDB 3.6 and Python3.7 in travis 2019-05-18 14:29:42 +02:00
erdenezul
597b962ad5
Merge pull request #2055 from bagerard/improve_test_cov
Improve test cov
2019-05-18 12:40:20 +02:00
Agustin Barto
6b9d71554e Add integration tests 2019-05-17 17:23:52 -03:00
Bastien Gérard
bb1089e03d Improve coverage in fields test 2019-05-17 22:16:08 +02:00
Bastien Gérard
c82f0c937d more work on coverage 2019-05-17 22:04:28 +02:00
Bastien Gérard
00d2fd685a more test cov 2019-05-17 22:04:28 +02:00
Bastien Gérard
f28e1b8c90 improve coverage of lazy ref field 2019-05-17 22:04:28 +02:00
Agustin Barto
2b17985a11 Uncomment tests. 2019-05-17 13:55:00 -03:00
Agustin Barto
b392e3102e Add support to transform. Add pull tests for and . 2019-05-17 13:41:02 -03:00
Bastien Gérard
cf38ef70cb Remove more code related to supporting pymongo2 2019-05-15 22:23:35 +02:00
Bastien Gérard
ac64ade10f remove dead code (related to pymongo2) + minor cleaning 2019-05-15 21:54:47 +02:00
Bastien Gérard
f7b7d0f79e Improve tests for querying list(embedded) when using inheritance 2019-05-03 21:59:48 +02:00
Bastien Gérard
d98f36ceff Add test for querying on fields of list(EmbeddedDocument) (with inheritance on the EmbededDoc) 2019-05-02 00:08:16 +02:00