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)
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_)
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_)
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_)
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_)
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_)
def test_ctor__pairlist__all_absent(self): dict_ = __unit__.AbsentDict(self.DICT_WITH_ALL_ABSENT.items()) self.assertEquals({}, dict_)
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_)
def test_ctor__pairlist__empty(self): self.assertEquals({}, __unit__.AbsentDict([]))
def test_ctor__dict__all_absent(self): self.assertEquals({}, __unit__.AbsentDict(self.DICT_WITH_ALL_ABSENT))
def test_ctor__dict__all_present(self): dict_ = __unit__.AbsentDict(self.DICT_WITH_ALL_PRESENT) self.assertEquals(self.DICT_WITH_ALL_PRESENT, dict_)
def test_ctor__dict__empty(self): self.assertEquals({}, __unit__.AbsentDict({}))
def test_ctor__some_object(self): with self.assertRaises(TypeError): __unit__.AbsentDict(object())
def test_ctor__none(self): with self.assertRaises(TypeError): __unit__.AbsentDict(None)
def test_ctor__no_args(self): dict_ = __unit__.AbsentDict() self._assertIsMapping(dict_) self.assertEmpty(dict_)