"""
End to end tests for Studio Home page
"""
import os

from unittest import skipIf
from bok_choy.web_app_test import WebAppTest
from edxapp_acceptance.pages.studio.overview import CourseOutlinePage

from regression.pages.lms.lms_courseware import CoursewarePageExtended
from regression.pages.studio import STUDIO_BASE_URL, STUDIO_STAGE_BASE_URL
from regression.pages.studio.studio_home import DashboardPageExtended
from regression.pages.studio.terms_of_service import TermsOfService
from regression.pages.studio.privacy_policy import PrivacyPolicy
from regression.tests.helpers.utils import (
    get_course_info, get_course_display_name
)

from regression.tests.helpers.api_clients import (
    StudioLoginApi,
    LmsLoginApi
)


class StudioHomeTest(WebAppTest):
    """
    Test for navigating to the Studio Home page
    """

    DEMO_COURSE_USER = os.environ.get('USER_LOGIN_EMAIL')
    DEMO_COURSE_PASSWORD = os.environ.get('USER_LOGIN_PASSWORD')

    def setUp(self):
        """
        Initialize the page object
        """
        super(StudioHomeTest, self).setUp()

        login_api = StudioLoginApi()
        login_api.authenticate(self.browser)

        self.studio_home_page = DashboardPageExtended(self.browser)

        self.course_info = get_course_info()

        self.studio_course_outline = CourseOutlinePage(
            self.browser, self.course_info['org'], self.course_info['number'],
            self.course_info['run'])

    def test_studio_course_select(self):
        """
        Verifies that user can select a course and navigate to its course
        outline page
        """
        self.studio_home_page.visit()
        self.studio_home_page.select_course(get_course_display_name())
        self.studio_course_outline.wait_for_page()


class StudioLmsTest(WebAppTest):
    """
    Tests that require lms verification with studio
    """

    DEMO_COURSE_USER = os.environ.get('USER_LOGIN_EMAIL')
    DEMO_COURSE_PASSWORD = os.environ.get('USER_LOGIN_PASSWORD')

    def setUp(self):
        """
        Initialize the page object
        """
        super(StudioLmsTest, self).setUp()

        studio_login = StudioLoginApi()
        studio_login.authenticate(self.browser)

        lms_login = LmsLoginApi()
        lms_login.authenticate(self.browser)

        self.studio_home_page = DashboardPageExtended(self.browser)

        self.course_info = get_course_info()

        self.studio_course_outline = CourseOutlinePage(
            self.browser, self.course_info['org'], self.course_info['number'],
            self.course_info['run'])

    def test_view_live_from_dashboard(self):
        """
        Verifies that user can view live course from studio dashboard
        """
        self.studio_home_page.visit()
        self.studio_home_page.click_view_live_button()
        courseware_page = CoursewarePageExtended(
            self.browser, get_course_info())
        courseware_page.wait_for_page()


class StudioFooterTest(WebAppTest):
    """
    Tests for Studio Footer
    """

    DEMO_COURSE_USER = os.environ.get('USER_LOGIN_EMAIL')
    DEMO_COURSE_PASSWORD = os.environ.get('USER_LOGIN_PASSWORD')

    def setUp(self):
        """
        Initialize the page object
        """
        super(StudioFooterTest, self).setUp()

        studio_login = StudioLoginApi()
        studio_login.authenticate(self.browser)

        self.terms_of_service = TermsOfService(self.browser)
        self.privacy_policy = PrivacyPolicy(self.browser)
        self.studio_home_page = DashboardPageExtended(self.browser)
        self.course_info = get_course_info()
        self.studio_course_outline = CourseOutlinePage(
            self.browser, self.course_info['org'], self.course_info['number'],
            self.course_info['run'])

        self.studio_home_page.visit()

    @skipIf(
        STUDIO_BASE_URL != STUDIO_STAGE_BASE_URL,
        "No link on sandbox"
    )  # LT-62
    def test_studio_footer_links(self):
        """
        Verifies that user can click and navigate to studio footer links
        Terms of Service
        Privacy Policy
        """
        self.studio_home_page.click_terms_of_service()
        self.terms_of_service.wait_for_page()
        self.studio_home_page.visit()
        self.studio_home_page.click_privacy_policy()
        self.privacy_policy.wait_for_page()

@@ -198,79 +198,8 @@
 ge%0A%0A
-from regression.pages.lms.lms_courseware import CoursewarePageExtended%0A
 from
@@ -269,16 +269,16 @@
 ASE_URL%0A
+
 from reg
@@ -614,22 +614,16 @@
  import 
-(%0A    
 StudioLo
@@ -632,27 +632,8 @@
 nApi
-,%0A    LmsLoginApi%0A)
 %0A%0A%0Ac
@@ -1615,24 +1615,24 @@
 lay_name())%0A
+
         self
@@ -1676,1184 +1676,8 @@
 )%0A%0A%0A
-class StudioLmsTest(WebAppTest):%0A    %22%22%22%0A    Tests that require lms verification with studio%0A    %22%22%22%0A%0A    DEMO_COURSE_USER = os.environ.get('USER_LOGIN_EMAIL')%0A    DEMO_COURSE_PASSWORD = os.environ.get('USER_LOGIN_PASSWORD')%0A%0A    def setUp(self):%0A        %22%22%22%0A        Initialize the page object%0A        %22%22%22%0A        super(StudioLmsTest, self).setUp()%0A%0A        studio_login = StudioLoginApi()%0A        studio_login.authenticate(self.browser)%0A%0A        lms_login = LmsLoginApi()%0A        lms_login.authenticate(self.browser)%0A%0A        self.studio_home_page = DashboardPageExtended(self.browser)%0A%0A        self.course_info = get_course_info()%0A%0A        self.studio_course_outline = CourseOutlinePage(%0A            self.browser, self.course_info%5B'org'%5D, self.course_info%5B'number'%5D,%0A            self.course_info%5B'run'%5D)%0A%0A    def test_view_live_from_dashboard(self):%0A        %22%22%22%0A        Verifies that user can view live course from studio dashboard%0A        %22%22%22%0A        self.studio_home_page.visit()%0A        self.studio_home_page.click_view_live_button()%0A        courseware_page = CoursewarePageExtended(%0A            self.browser, get_course_info())%0A        courseware_page.wait_for_page()%0A%0A%0A
 clas

Remove flaky studio test.