|
1 | 1 | # Tests for the anymail/utils.py module |
2 | 2 | # (not to be confused with utilities for testing found in in tests/utils.py) |
3 | 3 | import base64 |
| 4 | +import copy |
| 5 | +import pickle |
4 | 6 | from email.mime.image import MIMEImage |
5 | 7 | from unittest import skipIf |
6 | 8 |
|
|
24 | 26 | parse_address_list, parse_single_address, EmailAddress, |
25 | 27 | Attachment, |
26 | 28 | is_lazy, force_non_lazy, force_non_lazy_dict, force_non_lazy_list, |
27 | | - update_deep, |
| 29 | + update_deep, UNSET, |
28 | 30 | get_request_uri, get_request_basic_auth, parse_rfc2822date, querydict_getfirst, |
29 | 31 | CaseInsensitiveCasePreservingDict) |
30 | 32 |
|
@@ -441,3 +443,30 @@ def test_get_item(self): |
441 | 443 |
|
442 | 444 | # The base CaseInsensitiveDict functionality is well-tested in Requests, |
443 | 445 | # so we don't repeat it here. |
| 446 | + |
| 447 | + |
| 448 | +class UnsetValueTests(SimpleTestCase): |
| 449 | + """Tests for the UNSET sentinel value""" |
| 450 | + |
| 451 | + def test_not_other_values(self): |
| 452 | + self.assertIsNot(UNSET, None) |
| 453 | + self.assertIsNot(UNSET, False) |
| 454 | + self.assertNotEqual(UNSET, 0) |
| 455 | + self.assertNotEqual(UNSET, "") |
| 456 | + |
| 457 | + def test_unset_survives_pickle(self): |
| 458 | + # Required for using AnymailMessage with django-mailer |
| 459 | + pickled = pickle.dumps(UNSET) |
| 460 | + self.assertIs(pickle.loads(pickled), UNSET) |
| 461 | + |
| 462 | + def test_unset_survives_copy(self): |
| 463 | + self.assertIs(copy.copy(UNSET), UNSET) |
| 464 | + self.assertIs(copy.deepcopy(UNSET), UNSET) |
| 465 | + |
| 466 | + def test_unset_has_useful_repr(self): |
| 467 | + # (something better than '<object object at ...>') |
| 468 | + self.assertIn("UNSET", repr(UNSET)) |
| 469 | + |
| 470 | + def test_equality(self): |
| 471 | + # `is UNSET` is preferred to `== UNSET`, but both should work |
| 472 | + self.assertEqual(UNSET, UNSET) |
0 commit comments