Esempio n. 1
0
def test_edit_address_by_index(conf, index=2):
    record = AddressBook(first_name="edited_firstname",
                         last_name="edited_lastname",
                         company="edited_company",
                         address_1="edited_address1",
                         address_2="edited_address2",
                         city="edited_city",
                         post_code="e_postcode",
                         country="Ukraine",
                         region_state="Ternopil's'ka Oblast'")
    while conf.address_book.records_count() < index + 1:
        conf.address_book.create(record)
    with pytest.allure.step(
            "Select an address book entry to edit by index %d." % index):
        conf.address_book.edit_record_by_index(record, index)
    with pytest.allure.step(
            "Take information from edited address record from Add Address form."
    ):
        info_from_edited_address = conf.address_book.get_content_info_from_form(
            record)
    with pytest.allure.step(
            "Take information about edited address on Address Book page."):
        updated_info_from_address_list = conf.address_book.get_content_info_by_index(
            index)
    with pytest.allure.step(
            "Retrieving info about successfully updated address."):
        assert conf.address_book.get_alert_message(
        ) == 'Your address has been successfully updated'
    with pytest.allure.step("Compare info about edited address."):
        assert info_from_edited_address == updated_info_from_address_list
Esempio n. 2
0
def test_delete_address_by_index(conf, index=1):
    while conf.address_book.records_count() < index + 1:
        conf.address_book.create(
            AddressBook(first_name="firstname1",
                        last_name="lastname_1",
                        address_1="address1_2",
                        address_2="address2_3",
                        city="city",
                        post_code="postcode",
                        region_state="L'vivs'ka Oblast'",
                        country="Ukraine"))
    with pytest.allure.step(
            "Take the number of address book records on the page."):
        previous_address_list = len(
            conf.address_book.get_content_info_from_list())
    with pytest.allure.step("Delete address book record by index %d." % index):
        conf.address_book.delete_record_by_index(index)
    with pytest.allure.step(
            "Take len of address list after deleting the record"):
        updated_address_list = len(
            conf.address_book.get_content_info_from_list())
    with pytest.allure.step(
            "Compare the length of the list before and after deleting the record"
    ):
        assert previous_address_list - 1 == updated_address_list
Esempio n. 3
0
    def get_address_by_id(user: AddressBook) -> AddressBook:
        """
        Receives address_id data from the AddressBook object,
        on their basis searches for records in the oc_address table
        and returns them as an AddressBook object.

        :param user: object AddressBook with address_id.
        :return: object AddressBook with data from oc_address table.
        """
        session = session_factory()
        logging.info("Query address entry from oc_address table.")
        query = session.query(Address)
        address = query.filter(Address.address_id == user.address_id).first()
        zone = session.query(
            Zone.name).filter(Zone.zone_id == address.zone_id).first()
        country = session.query(Country.name).filter(
            Country.country_id == address.country_id).first()
        session.close()
        return AddressBook(address_id=address.address_id,
                           first_name=address.firstname,
                           last_name=address.lastname,
                           company=address.company,
                           address_1=address.address_1,
                           address_2=address.address_2,
                           city=address.city,
                           country=country[0],
                           region_state=zone[0])
Esempio n. 4
0
def test_add_new_address(conf):
    record = AddressBook(first_name="firstname1",
                         last_name="lastname",
                         address_1="address1",
                         address_2="address2",
                         city="city",
                         post_code="postcode",
                         region_state="L'vivs'ka Oblast'",
                         country="Ukraine")
    with pytest.allure.step(
            "Collect address book list from Address Book page."):
        previous_address_list = conf.address_book.get_content_info_from_list()
    with pytest.allure.step("Create new address book record."):
        conf.address_book.create(record)
    with pytest.allure.step(
            "Collect address book list from Address Book page with new record."
    ):
        updated_address_list = conf.address_book.get_content_info_from_list()
    with pytest.allure.step("Take information from new address record."):
        info_from_new_address = conf.address_book.get_content_info_from_form(
            record)
    with pytest.allure.step("Append info from new record into old list."):
        previous_address_list.append(info_from_new_address)
    with pytest.allure.step(
            "Retrieving info about successfully added address."):
        assert conf.address_book.get_alert_message_text(
        ) == 'Your address has been successfully added'
    with pytest.allure.step("Compare old and new lists."):
        assert sorted(previous_address_list,
                      key=attrgetter('content')) == sorted(
                          updated_address_list, key=attrgetter('content'))
    def get_content_info_by_index(self, index):
        """
        Get text from address record  by index in table on the Address Book page,
        filter and convert it into object.

        :return: object.
        """
        self.open_address_book_page()
        info = self.get_content_list()[index].text
        content = re.sub(r'\s', '', info)
        return AddressBook(content=content)
Esempio n. 6
0
    def get_content_info_by_index(self, index: int) -> AddressBook:
        """
        Get text from address record  by index in table on the Address Book page,
        filter and convert it into object.

        :return: AddressBook object.
        """
        logging.info(f"Convert data from {index} entry to AddressBook object.")
        info = self.driver.find_elements(
            *AddressBookLocators.CONTENT_LIST)[index].text
        content = re.sub(r'\s', '', info)
        return AddressBook(content=content)
Esempio n. 7
0
def test_check_error_messages_in_form(conf):
    conf.address_book.create(
        AddressBook(address_1="ad", city="c", post_code="p"))
    (firstname_error, lastname_error, address1_error, city_error,
     postcode_error,
     region_error) = conf.address_book.get_form_error_messages()
    assert firstname_error == "First Name must be between 1 and 32 characters!"
    assert lastname_error == "Last Name must be between 1 and 32 characters!"
    assert address1_error == "Address must be between 3 and 128 characters!"
    assert city_error == "City must be between 2 and 128 characters!"
    assert postcode_error == "Postcode must be between 2 and 10 characters!"
    assert region_error == "Please select a region / state!"
    def get_content_info_from_list(self):
        """
        Get text of each individual address record in table on the Address Book page,
        filter and convert it into object, append them to list and return it.

        :return: list of objects.
        """
        self.open_address_book_page()
        address_list = []
        for line in self.get_content_list():
            content = re.sub(r'\s', '', line.text)
            address_list.append(AddressBook(content=content))
        return address_list
Esempio n. 9
0
    def get_content_info_by_index(self, index: int) -> AddressBook:
        """
        Get text from address record  by index in table on the Address Book page,
        filter and convert it into object.

        :return: object.
        """
        driver = self.conf.driver
        self.open_address_book_page()
        info = driver.find_elements_by_xpath(
            '//*[@id="content"]//table/tbody//td[1]')[index].text
        content = re.sub(r'\s', '', info)
        return AddressBook(content=content)
    def get_content_info_from_form(self, address_obj):
        """
        Get text from object, filter and convert it into another object.

        :param address_obj: object that we used to create/edit Add Address form.
        :return: object with filtered text.
        """
        self.open_address_book_page()
        info_from_object = []
        for attr in address_obj.__dict__.items():
            if attr[1] is not None:
                info_from_object.append(attr[1])
        content = re.sub(r'\s', '', "".join(info_from_object))
        return AddressBook(content=content)
Esempio n. 11
0
    def get_content_info_from_form(address_obj: AddressBook) -> AddressBook:
        """
        Get text from AddressBook object, filter and convert it into another AddressBook object.

        :param address_obj: object that we used to create/edit Add Address form.
        :return: AddressBook object with filtered text.
        """
        logging.info("Get text from AddressBook object,"
                     "filter and convert it into another AddressBook object.")
        info_from_object = []
        for attr in address_obj.__dict__.items():
            if attr[1] is not None:
                info_from_object.append(attr[1])
        content = re.sub(r'\s', '', "".join(info_from_object))
        return AddressBook(content=content)
Esempio n. 12
0
    def get_content_info_from_list(self) -> List[AddressBook]:
        """
        Get text of each individual address record in table on the Address Book page,
        filter and convert it into object, append them to list and return it.

        :return: list of objects.
        """
        driver = self.conf.driver
        self.open_address_book_page()
        address_list = []
        for line in driver.find_elements_by_xpath(
                '//*[@id="content"]//table/tbody//td[1]'):
            content = re.sub(r'\s', '', line.text)
            address_list.append(AddressBook(content=content))
        return address_list
Esempio n. 13
0
    def get_content_info_from_list(self) -> List[AddressBook]:
        """
        Get text of each individual address record in table on the Address Book page,
        filter and convert it into object, append them to list and return it.

        :return: list of AddressBook objects.
        """
        logging.info(
            "Get list of AddressBook objects with all address entries on page."
        )
        address_list = []
        for line in self.driver.find_elements(
                *AddressBookLocators.CONTENT_LIST):
            content = re.sub(r'\s', '', line.text)
            address_list.append(AddressBook(content=content))
        return address_list