From aace71d458338f0e1d7b8ed04170aa1b825e5f8a Mon Sep 17 00:00:00 2001 From: Artemiy Rodionov Date: Mon, 1 Apr 2019 13:24:01 +0300 Subject: [PATCH] Create file with exceptions for elements --- shopelectro/selenium/elements/__init__.py | 3 ++- shopelectro/selenium/elements/cart.py | 20 ++++++++++++++------ shopelectro/selenium/elements/exceptions.py | 4 ++++ shopelectro/selenium/elements/product.py | 8 +------- shopelectro/tests/tests_selenium.py | 3 --- 5 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 shopelectro/selenium/elements/exceptions.py diff --git a/shopelectro/selenium/elements/__init__.py b/shopelectro/selenium/elements/__init__.py index 5f87088f..1fa8b756 100644 --- a/shopelectro/selenium/elements/__init__.py +++ b/shopelectro/selenium/elements/__init__.py @@ -1,3 +1,4 @@ -from .input import Input from .button import Button +from .exceptions import Unavailable +from .input import Input from .product import CatalogProduct, CartPosition diff --git a/shopelectro/selenium/elements/cart.py b/shopelectro/selenium/elements/cart.py index d84f5858..435ced73 100644 --- a/shopelectro/selenium/elements/cart.py +++ b/shopelectro/selenium/elements/cart.py @@ -1,14 +1,22 @@ +from shopelectro.selenium.elements import Unavailable + +# @todo #799:120m Reuse shopelectro.selenium.elements.cart.Cart for selenium tests. + + class Cart: """"Represent the cart at the site.""" def __init__(self, driver: SiteDriver): self.driver = driver - def positions(self): - pass + def positions(self): + raise Unavailable('to get positions.') + + def clear(self): + raise Unavailable('to get positions.') - def clear(self): - pass + def total(self): + raise Unavailable('to get positions.') - def total(self): - pass + def is_empty(self): + raise Unavailable('to get positions.') diff --git a/shopelectro/selenium/elements/exceptions.py b/shopelectro/selenium/elements/exceptions.py new file mode 100644 index 00000000..a87ed009 --- /dev/null +++ b/shopelectro/selenium/elements/exceptions.py @@ -0,0 +1,4 @@ +class Unavailable(NotImplementedError): + + def __init__(self, msg, *args, **kwargs): + super().__init__(f'The element doesn\'t provide ability to {msg}', *args, **kwargs) diff --git a/shopelectro/selenium/elements/product.py b/shopelectro/selenium/elements/product.py index 3acc257f..954983e8 100644 --- a/shopelectro/selenium/elements/product.py +++ b/shopelectro/selenium/elements/product.py @@ -1,18 +1,12 @@ import abc -from shopelectro.selenium.elements import Button +from shopelectro.selenium.elements import Button, Unavailable from shopelectro.selenium.driver import SiteDriver from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC -class Unavailable(NotImplementedError): - - def __init__(self, msg, *args, **kwargs): - super().__init__(f'The element doesn\'t provide ability to {msg}', *args, **kwargs) - - class Product(abc.ABC): """"Represent a product at the site.""" diff --git a/shopelectro/tests/tests_selenium.py b/shopelectro/tests/tests_selenium.py index 979a6cb6..fd995e4d 100644 --- a/shopelectro/tests/tests_selenium.py +++ b/shopelectro/tests/tests_selenium.py @@ -21,9 +21,6 @@ from pages.models import FlatPage, CustomPage from pages.urls import reverse_custom_page -# @todo #783:60m Create Cart class for tests. -# The class should replace batch of methods from this file. - def add_to_cart(browser): browser.get(Product.objects.first().url)