fix == None assertions

This commit is contained in:
Bastien Gérard
2019-08-31 22:51:13 +03:00
parent 3e764d068c
commit c61c6a8525
10 changed files with 70 additions and 70 deletions

View File

@@ -154,10 +154,10 @@ class TestOnlyExcludeAll(unittest.TestCase):
obj = self.Person.objects.only("name").get()
assert obj.name == person.name
assert obj.age == None
assert obj.age is None
obj = self.Person.objects.only("age").get()
assert obj.name == None
assert obj.name is None
assert obj.age == person.age
obj = self.Person.objects.only("name", "age").get()
@@ -166,7 +166,7 @@ class TestOnlyExcludeAll(unittest.TestCase):
obj = self.Person.objects.only(*("id", "name")).get()
assert obj.name == person.name
assert obj.age == None
assert obj.age is None
# Check polymorphism still works
class Employee(self.Person):
@@ -181,7 +181,7 @@ class TestOnlyExcludeAll(unittest.TestCase):
# Check field names are looked up properly
obj = Employee.objects(id=employee.id).only("salary").get()
assert obj.salary == employee.salary
assert obj.name == None
assert obj.name is None
def test_only_with_subfields(self):
class User(EmbeddedDocument):
@@ -215,8 +215,8 @@ class TestOnlyExcludeAll(unittest.TestCase):
post.save()
obj = BlogPost.objects.only("author.name").get()
assert obj.content == None
assert obj.author.email == None
assert obj.content is None
assert obj.author.email is None
assert obj.author.name == "Test User"
assert obj.comments == []
@@ -225,15 +225,15 @@ class TestOnlyExcludeAll(unittest.TestCase):
obj = BlogPost.objects.only("content", "comments.title").get()
assert obj.content == "Had a good coffee today..."
assert obj.author == None
assert obj.author is None
assert obj.comments[0].title == "I aggree"
assert obj.comments[1].title == "Coffee"
assert obj.comments[0].text == None
assert obj.comments[1].text == None
assert obj.comments[0].text is None
assert obj.comments[1].text is None
obj = BlogPost.objects.only("comments").get()
assert obj.content == None
assert obj.author == None
assert obj.content is None
assert obj.author is None
assert obj.comments[0].title == "I aggree"
assert obj.comments[1].title == "Coffee"
assert obj.comments[0].text == "Great post!"
@@ -266,10 +266,10 @@ class TestOnlyExcludeAll(unittest.TestCase):
post.save()
obj = BlogPost.objects.exclude("author", "comments.text").get()
assert obj.author == None
assert obj.author is None
assert obj.content == "Had a good coffee today..."
assert obj.comments[0].title == "I aggree"
assert obj.comments[0].text == None
assert obj.comments[0].text is None
BlogPost.drop_collection()
@@ -304,15 +304,15 @@ class TestOnlyExcludeAll(unittest.TestCase):
assert obj.sender == "me"
assert obj.to == "you"
assert obj.subject == "From Russia with Love"
assert obj.body == None
assert obj.content_type == None
assert obj.body is None
assert obj.content_type is None
obj = Email.objects.only("sender", "to").exclude("body", "sender").get()
assert obj.sender == None
assert obj.sender is None
assert obj.to == "you"
assert obj.subject == None
assert obj.body == None
assert obj.content_type == None
assert obj.subject is None
assert obj.body is None
assert obj.content_type is None
obj = (
Email.objects.exclude("attachments.content")
@@ -321,12 +321,12 @@ class TestOnlyExcludeAll(unittest.TestCase):
.get()
)
assert obj.attachments[0].name == "file1.doc"
assert obj.attachments[0].content == None
assert obj.sender == None
assert obj.attachments[0].content is None
assert obj.sender is None
assert obj.to == "you"
assert obj.subject == None
assert obj.body == None
assert obj.content_type == None
assert obj.subject is None
assert obj.body is None
assert obj.content_type is None
Email.drop_collection()
@@ -456,7 +456,7 @@ class TestOnlyExcludeAll(unittest.TestCase):
User(username="mongodb", password="secret").save()
user = Base.objects().exclude("password", "wibble").first()
assert user.password == None
assert user.password is None
with pytest.raises(LookUpError):
Base.objects.exclude("made_up")

View File

@@ -35,13 +35,13 @@ class TestFindAndModify(unittest.TestCase):
def test_modify_not_existing(self):
Doc(id=0, value=0).save()
assert Doc.objects(id=1).modify(set__value=-1) == None
assert Doc.objects(id=1).modify(set__value=-1) is None
self.assertDbEqual([{"_id": 0, "value": 0}])
def test_modify_with_upsert(self):
Doc(id=0, value=0).save()
old_doc = Doc.objects(id=1).modify(set__value=1, upsert=True)
assert old_doc == None
assert old_doc is None
self.assertDbEqual([{"_id": 0, "value": 0}, {"_id": 1, "value": 1}])
def test_modify_with_upsert_existing(self):
@@ -68,7 +68,7 @@ class TestFindAndModify(unittest.TestCase):
def test_find_and_modify_with_remove_not_existing(self):
Doc(id=0, value=0).save()
assert Doc.objects(id=1).modify(remove=True) == None
assert Doc.objects(id=1).modify(remove=True) is None
self.assertDbEqual([{"_id": 0, "value": 0}])
def test_modify_with_order_by(self):

View File

@@ -142,7 +142,7 @@ class TestQueryset(unittest.TestCase):
person = self.Person.objects().limit(1).only("name").first()
assert person == user_a
assert person.name == "User A"
assert person.age == None
assert person.age is None
def test_skip(self):
"""Ensure that QuerySet.skip works as expected."""
@@ -166,7 +166,7 @@ class TestQueryset(unittest.TestCase):
person = self.Person.objects().skip(1).only("name").first()
assert person == user_b
assert person.name == "User B"
assert person.age == None
assert person.age is None
def test___getitem___invalid_index(self):
"""Ensure slicing a queryset works as expected."""
@@ -444,7 +444,7 @@ class TestQueryset(unittest.TestCase):
assert result == 2
result = self.Person.objects.update(set__name="Ross", write_concern={"w": 0})
assert result == None
assert result is None
result = self.Person.objects.update_one(
set__name="Test User", write_concern={"w": 1}
@@ -453,7 +453,7 @@ class TestQueryset(unittest.TestCase):
result = self.Person.objects.update_one(
set__name="Test User", write_concern={"w": 0}
)
assert result == None
assert result is None
def test_update_update_has_a_value(self):
"""Test to ensure that update is passed a value to update to"""
@@ -1148,7 +1148,7 @@ class TestQueryset(unittest.TestCase):
obj = self.Person.objects(name__contains="van").first()
assert obj == person
obj = self.Person.objects(name__contains="Van").first()
assert obj == None
assert obj is None
# Test icontains
obj = self.Person.objects(name__icontains="Van").first()
@@ -1158,7 +1158,7 @@ class TestQueryset(unittest.TestCase):
obj = self.Person.objects(name__startswith="Guido").first()
assert obj == person
obj = self.Person.objects(name__startswith="guido").first()
assert obj == None
assert obj is None
# Test istartswith
obj = self.Person.objects(name__istartswith="guido").first()
@@ -1168,7 +1168,7 @@ class TestQueryset(unittest.TestCase):
obj = self.Person.objects(name__endswith="Rossum").first()
assert obj == person
obj = self.Person.objects(name__endswith="rossuM").first()
assert obj == None
assert obj is None
# Test iendswith
obj = self.Person.objects(name__iendswith="rossuM").first()
@@ -1178,15 +1178,15 @@ class TestQueryset(unittest.TestCase):
obj = self.Person.objects(name__exact="Guido van Rossum").first()
assert obj == person
obj = self.Person.objects(name__exact="Guido van rossum").first()
assert obj == None
assert obj is None
obj = self.Person.objects(name__exact="Guido van Rossu").first()
assert obj == None
assert obj is None
# Test iexact
obj = self.Person.objects(name__iexact="gUIDO VAN rOSSUM").first()
assert obj == person
obj = self.Person.objects(name__iexact="gUIDO VAN rOSSU").first()
assert obj == None
assert obj is None
# Test unsafe expressions
person = self.Person(name="Guido van Rossum [.'Geek']")
@@ -1205,7 +1205,7 @@ class TestQueryset(unittest.TestCase):
assert obj == alice
obj = self.Person.objects(name__not__iexact="alice").first()
assert obj == None
assert obj is None
def test_filter_chaining(self):
"""Ensure filters can be chained together.
@@ -1430,7 +1430,7 @@ class TestQueryset(unittest.TestCase):
BlogPost.objects.create(content="Anonymous post...")
result = BlogPost.objects.get(author=None)
assert result.author == None
assert result.author is None
def test_find_dict_item(self):
"""Ensure that DictField items may be found.
@@ -2050,7 +2050,7 @@ class TestQueryset(unittest.TestCase):
assert post.title != None
BlogPost.objects.update_one(unset__title=1)
post.reload()
assert post.title == None
assert post.title is None
pymongo_doc = BlogPost.objects.as_pymongo().first()
assert "title" not in pymongo_doc
@@ -4041,7 +4041,7 @@ class TestQueryset(unittest.TestCase):
assert post.comment == comment
Post.objects.update(unset__comment=1)
post.reload()
assert post.comment == None
assert post.comment is None
Comment.drop_collection()
Post.drop_collection()

View File

@@ -294,7 +294,7 @@ class TestQ(unittest.TestCase):
obj = self.Person.objects(Q(name=re.compile("^Gui"))).first()
assert obj == person
obj = self.Person.objects(Q(name=re.compile("^gui"))).first()
assert obj == None
assert obj is None
obj = self.Person.objects(Q(name=re.compile("^gui", re.I))).first()
assert obj == person
@@ -303,7 +303,7 @@ class TestQ(unittest.TestCase):
assert obj == person
obj = self.Person.objects(Q(name__not=re.compile("^Gui"))).first()
assert obj == None
assert obj is None
def test_q_repr(self):
assert repr(Q()) == "Q(**{})"