From b55dee8f2e668c9b5ad4d67dd38e869242d23f01 Mon Sep 17 00:00:00 2001 From: Saleem Latif Date: Fri, 9 Oct 2015 15:43:27 +0500 Subject: [PATCH] Bok-Choy test added for SOL-1196 to verify no black box around view certificate note in Progress Tab --- common/test/acceptance/tests/helpers.py | 30 ++++ .../tests/lms/test_certificate_web_view.py | 156 +++++++++++++++++- .../db_fixtures/certificates_web_view.json | 29 ++++ 3 files changed, 213 insertions(+), 2 deletions(-) diff --git a/common/test/acceptance/tests/helpers.py b/common/test/acceptance/tests/helpers.py index c89b37cdc2..d2cf2f5488 100644 --- a/common/test/acceptance/tests/helpers.py +++ b/common/test/acceptance/tests/helpers.py @@ -290,6 +290,36 @@ def get_modal_alert(browser): return browser.switch_to.alert +def get_element_padding(page, selector): + """ + Get Padding of the element with given selector, + + :returns a dict object with the following keys. + 1 - padding-top + 2 - padding-right + 3 - padding-bottom + 4 - padding-left + + Example Use: + progress_page.get_element_padding('.wrapper-msg.wrapper-auto-cert') + + """ + js_script = """ + var $element = $('%(selector)s'); + + element_padding = { + 'padding-top': $element.css('padding-top').replace("px", ""), + 'padding-right': $element.css('padding-right').replace("px", ""), + 'padding-bottom': $element.css('padding-bottom').replace("px", ""), + 'padding-left': $element.css('padding-left').replace("px", "") + }; + + return element_padding; + """ % {'selector': selector} + + return page.browser.execute_script(js_script) + + class EventsTestMixin(TestCase): """ Helpers and setup for running tests that evaluate events emitted diff --git a/common/test/acceptance/tests/lms/test_certificate_web_view.py b/common/test/acceptance/tests/lms/test_certificate_web_view.py index a0285116bd..f6f5acb6e7 100644 --- a/common/test/acceptance/tests/lms/test_certificate_web_view.py +++ b/common/test/acceptance/tests/lms/test_certificate_web_view.py @@ -1,12 +1,16 @@ """ Acceptance tests for the certificate web view feature. """ -from ..helpers import UniqueCourseTest, EventsTestMixin +from ..helpers import UniqueCourseTest, EventsTestMixin, load_data_str, get_element_padding from nose.plugins.attrib import attr -from ...fixtures.course import CourseFixture +from ...fixtures.course import CourseFixture, XBlockFixtureDesc, CourseUpdateDesc from ...fixtures.certificates import CertificateConfigFixture from ...pages.lms.auto_auth import AutoAuthPage from ...pages.lms.certificate_page import CertificatePage +from ...pages.lms.course_info import CourseInfoPage +from ...pages.lms.tab_nav import TabNavPage +from ...pages.lms.course_nav import CourseNavPage +from ...pages.lms.progress import ProgressPage @attr('shard_5') @@ -88,3 +92,151 @@ class CertificateWebViewTest(EventsTestMixin, UniqueCourseTest): } ] self.assert_events_match(expected_events, actual_events) + + +@attr('shard_5') +class CertificateProgressPageTest(UniqueCourseTest): + """ + Tests for verifying Certificate info on Progress tab of course page. + """ + + def setUp(self): + super(CertificateProgressPageTest, self).setUp() + + # set same course number as we have in fixture json + self.course_info['number'] = "3355358979513794782079645765720179311111" + + test_certificate_config = { + 'id': 1, + 'name': 'Certificate name', + 'description': 'Certificate description', + 'course_title': 'Course title override', + 'signatories': [], + 'version': 1, + 'is_active': True + } + course_settings = {'certificates': test_certificate_config} + + self.course_fixture = CourseFixture( + self.course_info["org"], + self.course_info["number"], + self.course_info["run"], + self.course_info["display_name"], + settings=course_settings + ) + + self.course_fixture.add_advanced_settings({ + "cert_html_view_enabled": {"value": "true"} + }) + + self.course_fixture.add_update( + CourseUpdateDesc(date='January 29, 2014', content='Test course update1') + ) + + self.course_fixture.add_children( + XBlockFixtureDesc('static_tab', 'Test Static Tab'), + XBlockFixtureDesc('chapter', 'Test Section').add_children( + XBlockFixtureDesc('sequential', 'Test Subsection', grader_type='Final Exam').add_children( + XBlockFixtureDesc('problem', 'Test Problem 1', data=load_data_str('multiple_choice.xml')), + XBlockFixtureDesc('html', 'Test HTML'), + ) + ), + XBlockFixtureDesc('chapter', 'Test Section 2').add_children( + XBlockFixtureDesc('sequential', 'Test Subsection 2', grader_type='Midterm Exam').add_children( + XBlockFixtureDesc('problem', 'Test Problem 2', data=load_data_str('formula_problem.xml')), + ) + ) + ) + + self.course_fixture.install() + self.user_id = "99" # we have created a user with this id in fixture + self.cert_fixture = CertificateConfigFixture(self.course_id, test_certificate_config) + + self.course_info_page = CourseInfoPage(self.browser, self.course_id) + self.progress_page = ProgressPage(self.browser, self.course_id) + self.course_nav = CourseNavPage(self.browser) + self.tab_nav = TabNavPage(self.browser) + + def log_in_as_unique_user(self): + """ + Log in as a valid lms user. + """ + AutoAuthPage( + self.browser, + username="testprogress", + email="progress@example.com", + password="testuser", + course_id=self.course_id + ).visit() + + def test_progress_page_has_view_certificate_button(self): + """ + Scenario: View Certificate option should be present on Course Progress menu if the user is + awarded a certificate. + And their should be no padding around the box containing certificate info. (See SOL-1196 for details on this) + + As a Student + Given there is a course with certificate configuration + And I have passed the course and certificate is generated + When I go on the Progress tab for the course + Then I should see a 'View Certificate' button + And their should be no padding around Certificate info box. + """ + self.cert_fixture.install() + self.log_in_as_unique_user() + + self.complete_course_problems() + + self.course_info_page.visit() + self.tab_nav.go_to_tab('Progress') + + self.assertTrue(self.progress_page.q(css='.auto-cert-message').first.visible) + + actual_padding = get_element_padding(self.progress_page, '.wrapper-msg.wrapper-auto-cert') + actual_padding = [int(padding) for padding in actual_padding.itervalues()] + expected_padding = [0, 0, 0, 0] + + # Verify that their is no padding around the box containing certificate info. + self.assertEqual(actual_padding, expected_padding) + + def complete_course_problems(self): + """ + Complete Course Problems. + + Problems were added in the setUp + """ + self.course_info_page.visit() + self.tab_nav.go_to_tab('Courseware') + + # Navigate to Test Subsection in Test Section Section + self.course_nav.go_to_section('Test Section', 'Test Subsection') + + # Navigate to Test Problem 1 + self.course_nav.go_to_sequential('Test Problem 1') + + # Select correct value for from select menu + self.course_nav.q(css='select option[value="{}"]'.format('blue')).first.click() + + # Select correct radio button for the answer + self.course_nav.q(css='fieldset label:nth-child(3) input').nth(0).click() + + # Select correct radio buttons for the answer + self.course_nav.q(css='fieldset label:nth-child(1) input').nth(1).click() + self.course_nav.q(css='fieldset label:nth-child(3) input').nth(1).click() + + # Submit the answer + self.course_nav.q(css='button.check.Check').click() + self.course_nav.wait_for_ajax() + + # Navigate to the 'Test Subsection 2' of 'Test Section 2' + self.course_nav.go_to_section('Test Section 2', 'Test Subsection 2') + + # Navigate to Test Problem 2 + self.course_nav.go_to_sequential('Test Problem 2') + + # Fill in the answer of the problem + self.course_nav.q(css='input[id^=input_][id$=_2_1]').fill('A*x^2 + sqrt(y)') + + # Submit the answer + self.course_nav.q(css='button.check.Check').click() + self.course_nav.wait_for_ajax() diff --git a/common/test/db_fixtures/certificates_web_view.json b/common/test/db_fixtures/certificates_web_view.json index 4beba8be74..60e7320614 100644 --- a/common/test/db_fixtures/certificates_web_view.json +++ b/common/test/db_fixtures/certificates_web_view.json @@ -8,6 +8,15 @@ "enabled": true } }, + { + "pk": 99, + "model": "certificates.certificategenerationcoursesetting", + "fields": { + "modified": "2015-06-18 11:02:13", + "course_key": "course-v1:test_org+3355358979513794782079645765720179311111+test_run", + "enabled": true + } + }, { "pk": 99, "model": "auth.user", @@ -70,6 +79,26 @@ "mode": "honor" } }, + { + "pk": 2, + "model": "certificates.generatedcertificate", + "fields": { + "user": 99, + "download_url": "http://www.edx.org/certificates/downloand", + "grade": "0.8", + "course_id": "course-v1:test_org+3355358979513794782079645765720179311111+test_run", + "key": "", + "distinction": true, + "status": "downloadable", + "verify_uuid": "52bfac10394d49219385dcd4cc17177e", + "download_uuid": "52bfac10394d49219385dcd4cc17177r", + "name": "testcert", + "created_date": "2015-06-12 11:02:13", + "modified_date": "2015-06-12 11:02:13", + "error_reason": "", + "mode": "honor" + } + }, { "pk": 1, "model": "student.linkedinaddtoprofileconfiguration",