def test_purchase_app(self):

        APP_NAME = 'Test Zippy With Me'
        PIN = '1234'
        username = self.testvars['marketplace']['username']
        password = self.testvars['marketplace']['password']

        if self.apps.is_app_installed(APP_NAME):
            self.apps.uninstall(APP_NAME)

        marketplace = Marketplace(self.marionette, self.MARKETPLACE_DEV_NAME)
        marketplace.launch()

        marketplace.login(username, password)

        marketplace.set_region('United States')

        details_page = marketplace.navigate_to_app(APP_NAME)
        payment = details_page.tap_purchase_button()

        payment.create_pin(PIN)
        payment.wait_for_buy_app_section_displayed()
        self.assertIn(APP_NAME, payment.app_name)
        payment.tap_buy_button()

        # Confirm the installation and wait for the app icon to be present
        confirm_install = ConfirmInstall(self.marionette)
        confirm_install.tap_confirm()

        self.assertEqual('%s installed' % APP_NAME, marketplace.install_notification_message)
        marketplace.switch_to_marketplace_frame()
        self.assertEqual('Launch', details_page.install_button_text)
    def test_marketplace_change_region_login(self):

        marketplace = Marketplace(self.marionette, 'Marketplace Dev')
        marketplace.launch()

        # login to marketplace
        settings = marketplace.login(self.user)

        # change region
        settings.select_region(self._REGION)

        # save changes
        settings.tap_save_changes()

        # wait for the changes to be saved
        marketplace.wait_for_notification_message_displayed()
        self.assertEqual(marketplace.notification_message, 'Settings saved')

        # go to home
        marketplace.tap_back()

        # go back to settings
        settings = marketplace.tap_settings()

        # check if the region is same as changed before
        self.assertEqual(settings.region, self._REGION)
    def test_marketplace_feedback_user(self):
        username = self.testvars['marketplace']['username']
        password = self.testvars['marketplace']['password']

        # launch marketplace dev and go to marketplace
        marketplace = Marketplace(self.marionette, self.MARKETPLACE_DEV_NAME)
        marketplace.launch()
        marketplace.login(username, password)

        # go to feedback tab
        marketplace.select_setting_feedback()

        # enter and submit your feedback
        marketplace.enter_feedback(self.test_comment)
        marketplace.submit_feedback()

        # catch the notification
        marketplace.wait_for_notification_message_displayed()
        message_content = marketplace.notification_message

        # verify if the notification is right
        self.assertEqual(message_content, self.feedback_submitted_message)
    def test_add_review(self):
        APP_NAME = 'SoundCloud'
        username = self.testvars['marketplace']['username']
        password = self.testvars['marketplace']['password']

        marketplace = Marketplace(self.marionette, self.MARKETPLACE_DEV_NAME)
        marketplace.launch()
        marketplace.login(username, password)
        details_page = marketplace.navigate_to_app(APP_NAME)

        current_time = str(time.time()).split('.')[0]
        rating = random.randint(1, 5)
        body = 'This is a test %s' % current_time

        review_box = details_page.tap_write_review()
        review_box.write_a_review(rating, body)

        marketplace.wait_for_notification_message_displayed()

        # Check if review was added correctly
        self.assertEqual(marketplace.notification_message, "Your review was posted")
        self.assertEqual(details_page.first_review_rating, rating)
        self.assertEqual(details_page.first_review_body, body)
    def test_create_confirm_pin(self):

        APP_NAME = 'Test Zippy With Me'
        PIN = '1234'
        username = self.testvars['marketplace']['username']
        password = self.testvars['marketplace']['password']

        if self.apps.is_app_installed(APP_NAME):
            self.apps.uninstall(APP_NAME)

        marketplace = Marketplace(self.marionette, self.MARKETPLACE_DEV_NAME)
        marketplace.launch()

        marketplace.login(username, password)

        marketplace.set_region('United States')

        details_page = marketplace.navigate_to_app(APP_NAME)
        payment = details_page.tap_purchase_button()

        payment.create_pin(PIN)
        payment.wait_for_buy_app_section_displayed()
        self.assertIn(APP_NAME, payment.app_name)