예제 #1
0
    def _stub_response(self, url, response_json, status=None):
        if not is_string(response_json):
            response_json = json.dumps(response_json)

        kwargs = dicts.AbsentDict({
            'body': response_json,
            'content_type': self.MIME_TYPE,
            'status': status or dicts.ABSENT,
        })
        responses.add(responses.GET, str(url), **kwargs)
예제 #2
0
 def test_setitem__still_absent(self):
     dict_ = __unit__.AbsentDict(self.DICT_WITH_ONE_ABSENT)
     dict_[self.ABSENT_KEY] = __unit__.ABSENT  # should be no-op
     self.assertNotIn(self.ABSENT_KEY, dict_)
예제 #3
0
 def test_setitem__absent_to_present(self):
     dict_ = __unit__.AbsentDict(self.DICT_WITH_ONE_ABSENT)
     dict_[self.ABSENT_KEY] = 42  # should add the key
     self.assertIn(self.ABSENT_KEY, dict_)
예제 #4
0
 def test_setitem__present_to_absent(self):
     dict_ = __unit__.AbsentDict(self.DICT_WITH_ALL_PRESENT)
     dict_[self.EXISTING_KEY] = __unit__.ABSENT  # should delete the key
     self.assertNotIn(self.EXISTING_KEY, dict_)
예제 #5
0
 def test_setitem__nonexisting_present(self):
     dict_ = __unit__.AbsentDict(self.DICT_WITH_ALL_PRESENT)
     dict_[self.NONEXISTING_KEY] = 42  # should add the key normally
     self.assertIn(self.NONEXISTING_KEY, dict_)
예제 #6
0
 def test_setitem__existing_present(self):
     dict_ = __unit__.AbsentDict(self.DICT_WITH_ALL_PRESENT)
     dict_[self.EXISTING_KEY] = self.EXISTING_VALUE  # should be no-op
     self.assertEquals(self.DICT_WITH_ALL_PRESENT, dict_)
예제 #7
0
 def test_ctor__pairlist__all_absent(self):
     dict_ = __unit__.AbsentDict(self.DICT_WITH_ALL_ABSENT.items())
     self.assertEquals({}, dict_)
예제 #8
0
 def test_ctor__pairlist__one_absent(self):
     dict_ = __unit__.AbsentDict(self.DICT_WITH_ONE_ABSENT.items())
     self.assertEquals(len(self.DICT_WITH_ONE_ABSENT) - 1, len(dict_))
     self.assertNotIn(self.ABSENT_KEY, dict_)
예제 #9
0
 def test_ctor__pairlist__empty(self):
     self.assertEquals({}, __unit__.AbsentDict([]))
예제 #10
0
 def test_ctor__dict__all_absent(self):
     self.assertEquals({}, __unit__.AbsentDict(self.DICT_WITH_ALL_ABSENT))
예제 #11
0
 def test_ctor__dict__all_present(self):
     dict_ = __unit__.AbsentDict(self.DICT_WITH_ALL_PRESENT)
     self.assertEquals(self.DICT_WITH_ALL_PRESENT, dict_)
예제 #12
0
 def test_ctor__dict__empty(self):
     self.assertEquals({}, __unit__.AbsentDict({}))
예제 #13
0
 def test_ctor__some_object(self):
     with self.assertRaises(TypeError):
         __unit__.AbsentDict(object())
예제 #14
0
 def test_ctor__none(self):
     with self.assertRaises(TypeError):
         __unit__.AbsentDict(None)
예제 #15
0
 def test_ctor__no_args(self):
     dict_ = __unit__.AbsentDict()
     self._assertIsMapping(dict_)
     self.assertEmpty(dict_)