Beispiel #1
0
    def verified_seat_payment_with_credit_card(self, selenium, addresses):
        """
        Validates users can add a verified seat to the cart and checkout with a credit card.

        Arguments:
            addresses (tuple): Addresses to test.

        This test requires 'disable_repeat_order_check' waffle switch turned off on stage, to run.

        """
        LmsHelpers.login(selenium)

        # Get the course run we want to purchase
        course_run = self.get_verified_course_run()
        verified_seat = self.get_verified_seat(course_run)

        for address in addresses:
            self.add_item_to_basket(selenium, verified_seat['sku'])
            self.checkout_with_credit_card(selenium, address)
            self.assert_browser_on_receipt_page(selenium)

            course_run_key = course_run['key']
            self.assert_user_enrolled_in_course_run(LMS_USERNAME,
                                                    course_run_key)
            assert self.refund_orders_for_course_run(course_run_key)
Beispiel #2
0
def test_login_redirection(selenium):
    """ If the login process is initiated at the E-Commerce Service, a successful login should return the user to
    the service. """
    # Visit LMS once to perform basic authentication
    selenium.get(LmsHelpers.build_url(''))

    selenium.get(EcommerceHelpers.build_url('dashboard'))
    LmsHelpers.submit_login_form(selenium)
    EcommerceHelpers.assert_on_dashboard(selenium)
Beispiel #3
0
    def verified_seat_payment_with_credit_card(self, selenium, addresses):
        """
        Validates users can add a verified seat to the cart and checkout with a credit card.

        Arguments:
            addresses (tuple): Addresses to test.

        This test requires 'disable_repeat_order_check' waffle switch turned off on stage, to run.

        """
        LmsHelpers.login(selenium)
        discovery_client = DiscoveryApi()

        # REV-2189: The course runs we get back may not exist in ecommerce, or may not be able to be added to the
        # basket (ex: upgrade time expired). We can't easily make that determination here, so we try this in a loop
        # until we find one that works. This quick fix is made in the hope that this whole system is deprecated in the
        # near future.
        course_runs = discovery_client.get_course_runs('verified')

        assert len(course_runs) > 0

        # Use this to make sure that the tests actually ran and that we didn't accidentally skip it due to
        # not finding a valid seat.
        test_run_successfully = False

        # Check up to 10 course runs to find a good one
        for potential_course_run in course_runs[:10]:
            course_run = discovery_client.get_course_run(potential_course_run['key'])
            verified_seat = self.get_verified_seat(course_run)
            try:
                for address in addresses:
                    # This is the line that will throw the TimeoutException if the sku isn't valid
                    # for this test.
                    self.add_item_to_basket(selenium, verified_seat['sku'])
                    log.warning("%s, was added to the basket.", verified_seat['sku'])
                    self.checkout_with_credit_card(selenium, address)
                    self.assert_browser_on_receipt_page(selenium)

                    course_run_key = course_run['key']
                    self.assert_user_enrolled_in_course_run(LMS_USERNAME, course_run_key)
                    assert self.refund_orders_for_course_run(course_run_key)

                test_run_successfully = True

                # We finished a test, stop trying course runs
                break
            except TimeoutException as exc:
                # We only want to continue on this particular error from add_item_to_basket.
                if "No product is available" in exc.msg:
                    log.warning("Failed to get a valid course run for SKU %s, continuing. ", verified_seat['sku'])
                else:  # TODO: Remove else clause after investigation (REV-2493)
                    log.warning("Failed to add basket line for SKU %s, continuing", verified_seat['sku'])
                    log.warning("exc.msg was: %s", exc.msg)
                continue

        assert test_run_successfully, "Unable to find a valid course run to test!"
Beispiel #4
0
def test_login_and_logout(selenium):
    """ Authenticating with the identity provider (LMS) should authenticate users for the E-Commerce Service.  """

    LmsHelpers.login(selenium)

    # Visit the Otto dashboard to trigger an OpenID Connect login
    EcommerceHelpers.visit_dashboard(selenium)

    # Logging out of Otto should redirect the user to the LMS logout page, which redirects
    # to the marketing site (if available) or the LMS homepage.
    EcommerceHelpers.logout(selenium)
    assert selenium.current_url.strip('/') in [MARKETING_URL_ROOT, LMS_URL_ROOT]
Beispiel #5
0
def test_login_redirection(selenium):
    """ If the login process is initiated at the E-Commerce Service, a successful login should return the user to
    the service. """
    # Visit LMS login with next query param once to perform basic authentication
    selenium.get(
        LmsHelpers.build_url(
            'login?next={}&skip_authn_mfe=true'.format(EcommerceHelpers.build_url('dashboard'))
        )
    )

    LmsHelpers.submit_login_form(selenium)
    EcommerceHelpers.assert_on_dashboard(selenium)
Beispiel #6
0
    def test_verified_seat_payment_with_paypal(self, selenium):
        """ Validates users can add a verified seat to the cart and checkout with PayPal. """
        LmsHelpers.login(selenium)

        # Get the course run we want to purchase
        course_run = self.get_verified_course_run()
        verified_seat = self.get_verified_seat(course_run)
        self.add_item_to_basket(selenium, verified_seat['sku'])

        self.checkout_with_paypal(selenium)
        self.assert_browser_on_receipt_page(selenium)
        # TODO In the future we should verify enrollment via the Enrollment API
        self.refund_orders_for_course_run(course_run['key'])
Beispiel #7
0
    def test_verified_seat_payment_with_paypal(self, selenium):
        """ Validates users can add a verified seat to the cart and checkout with PayPal. """
        LmsHelpers.login(selenium)

        # Get the course run we want to purchase
        course_run = self.get_verified_course_run()
        verified_seat = self.get_verified_seat(course_run)
        self.add_item_to_basket(selenium, verified_seat['sku'])
        self.checkout_with_paypal(selenium)
        self.assert_browser_on_receipt_page(selenium)

        course_run_key = course_run['key']
        self.assert_user_enrolled_in_course_run(LMS_USERNAME, course_run_key)
        self.refund_orders_for_course_run(course_run_key)
Beispiel #8
0
def test_provider_logout(selenium):
    """ Logging out of the identity provider should log the user out of the E-Commerce Service. """

    LmsHelpers.login(selenium)

    # Visit the Otto dashboard to trigger an OpenID Connect login
    EcommerceHelpers.visit_dashboard(selenium)

    LmsHelpers.logout(selenium)

    # Now that the user has been logged out, navigating to the dashboard should result in the user being
    # redirected to the identity provider's login page. This indicates the user has been logged out of both systems.
    try:
        EcommerceHelpers.visit_dashboard(selenium)
    except NoSuchElementException:
        pass
    else:
        pytest.fail('Logging out of the identity provider should have also logged out of the E-Commerce Service!')