def test_system_activity_entry_is_correctly_truncated(self):
     with session.begin():
         system = data_setup.create_system()
     b = self.browser
     b.get(get_server_base() + 'view/%s' % system.fqdn)
     b.find_element_by_link_text('Contact Owner').click()
     b.find_element_by_xpath('//button[.//text()=\'Report Problem\']').click()
     b.find_element_by_name('problem.description').send_keys(u'a' + u'\u044f' * 100)
     b.find_element_by_xpath('//input[@value=\'Report\']').click()
     # Wait for our success box
     SeleniumTestCase.wait_and_try(lambda: b.find_element_by_xpath('//div/span[text()=\'Success\']'))
 def test_reporter_and_system_cc_list_are_cced(self):
     with session.begin():
         interested_party_email = data_setup.unique_name(u'*****@*****.**')
         system = data_setup.create_system()
         system.cc = [interested_party_email]
     b = self.browser
     b.get(get_server_base() + 'view/%s' % system.fqdn)
     b.find_element_by_link_text('Contact Owner').click()
     b.find_element_by_xpath('//button[.//text()=\'Report Problem\']').click()
     b.find_element_by_name('problem.description').send_keys('I broke it')
     b.find_element_by_xpath('//input[@value=\'Report\']').click()
     SeleniumTestCase.wait_and_try(lambda: b.find_element_by_xpath('//div/span[text()=\'Success\']'))
     self.assertEqual(len(self.mail_capture.captured_mails), 1)
     sender, rcpts, raw_msg = self.mail_capture.captured_mails[0]
     self.assertEqual(rcpts, [system.owner.email_address,
             self.problem_reporter.email_address, interested_party_email])
     msg = email.message_from_string(raw_msg)
     self.assertEqual(msg['Cc'], '%s, %s' % (self.problem_reporter.email_address,
             interested_party_email))
    def test_report_problem_via_job_and_recipe(self):
        with session.begin():
            owner = data_setup.create_user()
            job = data_setup.create_completed_job(owner=owner)
        # Completing a job creates an email which we don't need
        self.mail_capture.captured_mails[:] = []
        b = self.browser
        b.get(get_server_base() + 'jobs/%s' % job.id)
        b.find_element_by_link_text('Report Problem with System').click()
        b.find_element_by_id('problem_description').send_keys('I broke it')
        b.find_element_by_xpath('//input[@value=\'Report\']').click()
        SeleniumTestCase.wait_and_try(lambda: b.find_element_by_xpath('//div/span[text()=\'Success\']'))
        self.assertEqual(len(self.mail_capture.captured_mails), 1)

        self.mail_capture.captured_mails[:] = []
        b.get(get_server_base() + 'recipes/%s' % job.recipesets[0].recipes[0].id)
        b.find_element_by_link_text('Report Problem with System').click()
        b.find_element_by_id('problem_description').send_keys('I broke it')
        b.find_element_by_xpath('//input[@value=\'Report\']').click()
        SeleniumTestCase.wait_and_try(lambda: b.find_element_by_xpath('//div/span[text()=\'Success\']'))
        self.assertEqual(len(self.mail_capture.captured_mails), 1)
    def test_loan_request(self):
        b = self.browser

        # Test can send loan request succesfully
        b.get(get_server_base() + 'view/%s' % self.system.fqdn)
        b.find_element_by_link_text('Contact Owner').click()
        b.find_element_by_xpath('//button[.//text()=\'Request Loan\']').click()
        b.find_element_by_name('loan.message').send_keys('request loan')
        b.find_element_by_xpath('//input[@value=\'Request\']').click()
        # Wait for our success box
        SeleniumTestCase.wait_and_try(lambda: b.find_element_by_xpath('//div/span[text()=\'Success\']'))
        # Check the email was sent
        SeleniumTestCase.wait_and_try(lambda: self.assertEqual(len(self.mail_capture.captured_mails), 1))
        sender, rcpts, raw_msg = self.mail_capture.captured_mails[0]
        payload = 'A Beaker user has requested you loan them the system\n' \
            '%s <%sview/%s>.\n' \
            'Here is a copy of their request:\n' \
            'request loan\n Requested by: %s' \
            % (self.system_fqdn, get_server_base(), self.system_fqdn,
                self.problem_reporter.display_name)
        self._std_check_mail(sender, rcpts, raw_msg, 'loan-request',
            payload, 'Loan request for %s' % self.system.fqdn)
    def test_report_problem(self):
        b = self.browser

        # Test can send problem report succesfully
        b.get(get_server_base() + 'view/%s' % self.system.fqdn)
        b.find_element_by_link_text('Contact Owner').click()
        b.find_element_by_xpath('//button[.//text()=\'Report Problem\']').click()
        b.find_element_by_name('problem.description').send_keys('testing problem')
        b.find_element_by_xpath('//input[@value=\'Report\']').click()
        # Wait for our success box
        SeleniumTestCase.wait_and_try(lambda: b.find_element_by_xpath('//div/span[text()=\'Success\']'))
        # Check the email was sent
        SeleniumTestCase.wait_and_try(lambda: self.assertEqual(len(self.mail_capture.captured_mails), 1))
        sender, rcpts, raw_msg = self.mail_capture.captured_mails[0]
        payload = 'A Beaker user has reported a problem with system \n' \
            '%s <%sview/%s>.\n\n' \
            'Reported by: %s\n\n' \
            'Problem description:\n' \
            'testing problem' \
            % (self.system_fqdn, get_server_base(), self.system_fqdn,
                self.problem_reporter.display_name)
        self._std_check_mail(sender, rcpts, raw_msg, 'system-problem',
            payload, 'Problem reported for %s' % self.system.fqdn)