def test_expires_invalid_int(self): """Test case where an invalid type is passed for expires.""" morsel = Morsel() morsel['expires'] = 100 with pytest.raises(TypeError): morsel_to_cookie(morsel)
def test_expires_invalid_int(self): """Test case where an invalid type is passed for expires.""" morsel = Morsel() morsel["expires"] = 100 with pytest.raises(TypeError): morsel_to_cookie(morsel)
def test_expires_invalid_str(self): """Test case where an invalid string is input.""" morsel = Morsel() morsel["expires"] = "woops" with pytest.raises(ValueError): morsel_to_cookie(morsel)
def test_max_age_invalid_str(self): """Test case where a invalid max age is passed.""" morsel = Morsel() morsel["max-age"] = "woops" with pytest.raises(TypeError): morsel_to_cookie(morsel)
def test_expires_invalid_str(self): """Test case where an invalid string is input.""" morsel = Morsel() morsel['expires'] = 'woops' with pytest.raises(ValueError): morsel_to_cookie(morsel)
def test_max_age_invalid_str(self): """Test case where a invalid max age is passed.""" morsel = Morsel() morsel['max-age'] = 'woops' with pytest.raises(TypeError): morsel_to_cookie(morsel)
def test_expires_valid_str(self): """Test case where we convert expires from string time.""" morsel = Morsel() morsel['expires'] = 'Thu, 01-Jan-1970 00:00:01 GMT' cookie = morsel_to_cookie(morsel) assert cookie.expires == 1
def requests_1_sde(one_input): try: ipt_data = str(one_input) except UnicodeDecodeError: sys.exit(0) C = SimpleCookie(ipt_data) for morsel in C.values(): cookie = morsel_to_cookie(morsel) print(cookie) ipt_data2 = "{}={}; path=/; domain=.test.com".format(ipt_data, ipt_data) C = SimpleCookie(ipt_data2) for morsel in C.values(): cookie = morsel_to_cookie(morsel) print(cookie)
def test_expires_none(self): """Test case where expires is None.""" morsel = Morsel() morsel['expires'] = None cookie = morsel_to_cookie(morsel) assert cookie.expires is None
def test_max_age_valid_int(self): """Test case where a valid max age in seconds is passed.""" morsel = Morsel() morsel['max-age'] = 60 cookie = morsel_to_cookie(morsel) assert isinstance(cookie.expires, int)
def test_max_age_valid_int(self): """Test case where a valid max age in seconds is passed.""" morsel = Morsel() morsel["max-age"] = 60 cookie = morsel_to_cookie(morsel) assert isinstance(cookie.expires, int)
def test_expires_none(self): """Test case where expires is None.""" morsel = Morsel() morsel["expires"] = None cookie = morsel_to_cookie(morsel) assert cookie.expires is None
def test_expires_valid_str(self): """Test case where we convert expires from string time.""" morsel = Morsel() morsel["expires"] = "Thu, 01-Jan-1970 00:00:01 GMT" cookie = morsel_to_cookie(morsel) assert cookie.expires == 1
def proceed(self): script = self.doc.xpath('//script/text()')[0] cookieStr = re.match('.*document\.cookie = "([^"]+)".*', script, re.DOTALL).group(1) morsel = Cookie.Cookie(cookieStr).values()[0] self.browser.session.cookies.set_cookie(morsel_to_cookie(morsel)) form = self.get_form() return form.submit()
def test_app_secure_cookies(): cookies_view.set_secure_cookie('test', '内容测试') cookies_view.set_secure_cookie('test2', {'value': '内容测试'}) cookies_view.finish(RETCODE.SUCCESS) cookies_jar = CookieJar() for k, v in cookies_view.response.cookies.items(): cookies_jar.set_cookie(morsel_to_cookie(v)) cookies_view.request.cookies = dict_from_cookiejar(cookies_jar) assert cookies_view.get_secure_cookie('test') == '内容测试' assert cookies_view.get_secure_cookie('test2') == {'value': '内容测试'}
def test_expires_invalid_int(self, value, exception): """Test case where an invalid type is passed for expires.""" morsel = Morsel() morsel['expires'] = value with pytest.raises(exception): morsel_to_cookie(morsel)