requests.cookies.morsel_to_cookie

Here are the examples of the python api requests.cookies.morsel_to_cookie taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

Example 1

Project: YCM_WIN_X86 Source File: test_requests.py
    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

Example 2

Project: YCM_WIN_X86 Source File: test_requests.py
    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)

Example 3

Project: YCM_WIN_X86 Source File: test_requests.py
    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)

Example 4

Project: YCM_WIN_X86 Source File: test_requests.py
    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

Example 5

Project: YCM_WIN_X86 Source File: test_requests.py
    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)

Example 6

Project: YCM_WIN_X86 Source File: test_requests.py
    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)

Example 7

Project: weboob Source File: pages.py
    def proceed(self):
        script = self.doc.xpath('//script/text()')[0]
        cookieStr = re.match('.*docuement\.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()