diff --git a/splinter/abc/__init__.py b/splinter/abc/__init__.py new file mode 100644 index 000000000..889439339 --- /dev/null +++ b/splinter/abc/__init__.py @@ -0,0 +1,3 @@ +from cookie_manager import CookieManagerAPI + +__all__ = ["CookieManagerAPI"] diff --git a/splinter/cookie_manager.py b/splinter/abc/cookie_manager.py similarity index 80% rename from splinter/cookie_manager.py rename to splinter/abc/cookie_manager.py index a2ed6bd0f..ea80ab803 100644 --- a/splinter/cookie_manager.py +++ b/splinter/abc/cookie_manager.py @@ -1,18 +1,22 @@ # Copyright 2012 splinter authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. +from abc import ABC, abstractmethod -class CookieManagerAPI: - """An API that specifies how a splinter driver deals with cookies. +class CookieManagerAPI(ABC): + """Specification for how a Splinter driver deals with cookies. - You can add cookies using the :meth:`add ` method, - and remove one or all cookies using - the :meth:`delete ` method. + Add cookies using the :meth:`add ` method, + and remove cookies using + the :meth:`delete ` and + :meth:`delete `methods. A CookieManager acts like a ``dict``, so you can access the value of a cookie through the [] operator, passing the cookie identifier: + Examples: + >>> cookie_manager.add({'name': 'Tony'}) >>> assert cookie_manager['name'] == 'Tony' """ @@ -20,6 +24,7 @@ class CookieManagerAPI: def __init__(self, driver) -> None: self.driver = driver + @abstractmethod def add(self, cookie, **kwargs) -> None: """Add a cookie. @@ -35,6 +40,7 @@ def add(self, cookie, **kwargs) -> None: """ raise NotImplementedError + @abstractmethod def delete(self, *cookies: str) -> None: """Delete one or more cookies. @@ -51,10 +57,12 @@ def delete(self, *cookies: str) -> None: """ raise NotImplementedError + @abstractmethod def delete_all(self) -> None: """Delete all cookies.""" raise NotImplementedError + @abstractmethod def all(self, verbose: bool = False): # NOQA: A003 """Get all of the cookies. @@ -74,8 +82,14 @@ def all(self, verbose: bool = False): # NOQA: A003 """ raise NotImplementedError + @abstractmethod + def __contains__(self, key) -> bool: + raise NotImplementedError + + @abstractmethod def __getitem__(self, item): raise NotImplementedError + @abstractmethod def __eq__(self, other_object) -> bool: raise NotImplementedError diff --git a/splinter/driver/djangoclient.py b/splinter/driver/djangoclient.py index 4eafd56b7..7da956176 100644 --- a/splinter/driver/djangoclient.py +++ b/splinter/driver/djangoclient.py @@ -6,7 +6,7 @@ from .lxmldriver import LxmlDriver from splinter.config import Config -from splinter.cookie_manager import CookieManagerAPI +from splinter.abc import CookieManagerAPI from splinter.request_handler.status_code import StatusCode diff --git a/splinter/driver/flaskclient.py b/splinter/driver/flaskclient.py index 0eb988f8f..e19f62359 100644 --- a/splinter/driver/flaskclient.py +++ b/splinter/driver/flaskclient.py @@ -9,7 +9,7 @@ from .lxmldriver import LxmlDriver from splinter.config import Config -from splinter.cookie_manager import CookieManagerAPI +from splinter.abc import CookieManagerAPI from splinter.request_handler.status_code import StatusCode diff --git a/splinter/driver/webdriver/cookie_manager.py b/splinter/driver/webdriver/cookie_manager.py index 1bed7cbd3..3baac5418 100644 --- a/splinter/driver/webdriver/cookie_manager.py +++ b/splinter/driver/webdriver/cookie_manager.py @@ -3,7 +3,7 @@ # license that can be found in the LICENSE file. from urllib.parse import urlparse -from splinter.cookie_manager import CookieManagerAPI +from splinter.abc import CookieManagerAPI class CookieManager(CookieManagerAPI): diff --git a/splinter/driver/zopetestbrowser.py b/splinter/driver/zopetestbrowser.py index f19c9b420..a29b31746 100644 --- a/splinter/driver/zopetestbrowser.py +++ b/splinter/driver/zopetestbrowser.py @@ -13,7 +13,7 @@ from zope.testbrowser.browser import ListControl from splinter.config import Config -from splinter.cookie_manager import CookieManagerAPI +from splinter.abc import CookieManagerAPI from splinter.driver import DriverAPI from splinter.driver import ElementAPI from splinter.driver.element_present import ElementPresentMixIn