-
Notifications
You must be signed in to change notification settings - Fork 41
Added integration tests for studio views; Code clean-up; #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,10 +121,15 @@ def check_url(self, data, suffix=''): # pylint: disable=unused-argument,no-self | |
| """ | ||
| Checks that the given document url is accessible, and therefore assumed to be valid | ||
| """ | ||
| test_url = data['url'] | ||
| try: | ||
| test_url = data['url'] | ||
| url_response = requests.head(test_url) | ||
| # Catch wide range of errors | ||
| except KeyError as ex: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catch KeyError exception, means url wasn't provided There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, but I would put the two lines in two different try/except blocks, since you're catching different exceptions for each. This way you don't risk to inadvertently catch a |
||
| LOG.debug("URL not provided - %s", unicode(ex)) | ||
| return { | ||
| 'status_code': 400, | ||
| } | ||
| # Catch wide range of request exceptions | ||
| except requests.exceptions.RequestException as ex: | ||
| LOG.debug("Unable to connect to %s - %s", test_url, unicode(ex)) | ||
| return { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| """ Base classes for integration tests """ | ||
| from xblockutils.base_test import SeleniumBaseTest | ||
|
|
||
|
|
||
| class GoogleCalendarBaseTest(SeleniumBaseTest): # pylint: disable=too-many-ancestors, too-few-public-methods | ||
| """ Base class for Google Calendar integration tests """ | ||
| module_name = __name__ | ||
| default_css_selector = 'div.google-calendar-xblock-wrapper' | ||
|
|
||
|
|
||
| class GoogleDocumentBaseTest(SeleniumBaseTest): # pylint: disable=too-many-ancestors, too-few-public-methods | ||
| """ Base class for Google Document integration tests """ | ||
| module_name = __name__ | ||
| default_css_selector = 'div.google-docs-xblock-wrapper' |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| """ | ||
| Contains a list of lists that will be used as the DDT arguments for the studio test. | ||
| """ | ||
| CALENDAR_SCENARIOS = [ | ||
| [ | ||
| 'Calendar', | ||
| ], | ||
| ] | ||
|
|
||
| DOCUMENT_SCENARIOS = [ | ||
| [ | ||
| 'Document', | ||
| ], | ||
| ] | ||
|
|
||
| IMAGE_SCENARIOS = [ | ||
| [ | ||
| 'Image', | ||
| ], | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """ Runs tests for publish event functionality """ | ||
| from .base_test import GoogleCalendarBaseTest, GoogleDocumentBaseTest | ||
|
|
||
|
|
||
| class GoogleCalendarPublishTestCase(GoogleCalendarBaseTest): # pylint: disable=too-few-public-methods, too-many-ancestors | ||
| """ | ||
| Tests for Google Calendar event publishing functionality. | ||
| """ | ||
|
|
||
| def test_calendar_publish_event(self): | ||
| """ Tests whether the publish event for calendar was triggered """ | ||
| calendar = self.go_to_page('Calendar') | ||
| load_event_complete = calendar.find_element_by_css_selector('.load_event_complete') | ||
| self.assertEqual( | ||
| load_event_complete.get_attribute('value'), | ||
| "I've published the event that indicates that the load has completed" | ||
| ) | ||
|
|
||
|
|
||
| class GoogleDocumentPublishTestCase(GoogleDocumentBaseTest): # pylint: disable=too-many-ancestors | ||
| """ | ||
| Tests for Google Document event publishing functionality. | ||
| """ | ||
|
|
||
| def test_document_publish_event(self): | ||
| """ Tests whether the publish event for document was triggered """ | ||
| document = self.go_to_page('Document') | ||
| load_event_complete = document.find_element_by_css_selector('.load_event_complete') | ||
| self.assertEqual( | ||
| load_event_complete.get_attribute('value'), | ||
| "I've published the event that indicates that the load has completed" | ||
| ) | ||
|
|
||
| def test_image_publish_event(self): | ||
| """ Tests whether the publish event for image was triggered """ | ||
| image = self.go_to_page('Image') | ||
| load_event_complete = image.find_element_by_css_selector('.load_event_complete') | ||
| self.assertEqual( | ||
| load_event_complete.get_attribute('value'), | ||
| "I've published the event that indicates that the load has completed" | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| """ Runs tests for the studio views """ | ||
|
|
||
| from ddt import ddt, unpack, data | ||
| from .base_test import GoogleCalendarBaseTest, GoogleDocumentBaseTest | ||
| from .studio_scenarios import CALENDAR_SCENARIOS, DOCUMENT_SCENARIOS, IMAGE_SCENARIOS | ||
|
|
||
| DEFAULT_CALENDAR_SRC = ( | ||
| 'https://www.google.com/calendar/embed?' | ||
| 'mode=Month&' | ||
| 'src=edx.org_lom804qe3ttspplj1bgeu1l3ak@group.calendar.google.com&' | ||
| 'showCalendars=0' | ||
| ) | ||
|
|
||
| DEFAULT_DOCUMENT_SRC = ( | ||
| 'https://docs.google.com/presentation/d/1x2ZuzqHsMoh1epK8VsGAlanSo7r9z55ualwQlj-ofBQ/embed?' | ||
| 'start=true&loop=true&delayms=10000' | ||
| ) | ||
|
|
||
| TEST_IMAGE_SRC = 'https://docs.google.com/drawings/d/1lmmxboBM5c_0WCTjhAxBdkpqQb3T8VSwtuG0TRR1ODQ/pub?w=960&h=720' | ||
|
|
||
|
|
||
| @ddt # pylint: disable=too-many-ancestors | ||
| class GoogleCalendarStudioTest(GoogleCalendarBaseTest): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @antoviaque Thanks for providing an example of studio testing. Here are integration tests which include studio views. |
||
| """ | ||
| Tests for Google Calendar studio view. | ||
| """ | ||
| default_css_selector = '#calendar-settings-tab' | ||
|
|
||
| def studio_save(self): | ||
| """ Save changes made in studio for Google Calendar """ | ||
| self.browser.find_element_by_css_selector('#calendar-submit-options').click() | ||
|
|
||
| @data(*CALENDAR_SCENARIOS) # pylint: disable=star-args | ||
| @unpack | ||
| def test_save_calendar(self, page_name): | ||
| """ | ||
| Verify that option changes in Google Calendar studio view | ||
| are appropriately saved and visible immediately after | ||
| """ | ||
| self.go_to_page(page_name, view_name='studio_view') | ||
| # Expecting every input value to be valid | ||
| self.assertTrue(self.browser.find_element_by_css_selector('.validation_alert.covered')) | ||
| display_name_input = self.browser.find_element_by_css_selector('#edit_display_name') | ||
| # Change display name | ||
| display_name_input.clear() | ||
| display_name_input.send_keys('My Meetings') | ||
| calendar_id_input = self.browser.find_element_by_css_selector('#edit_calendar_id') | ||
| # Change calendar ID | ||
| calendar_id_input.clear() | ||
| calendar_id_input.send_keys('a') | ||
| self.wait_until_exists('#edit_calendar_id.error') | ||
| # Expects validation error due to calendar ID being invalid | ||
| self.assertTrue(self.browser.find_element_by_css_selector('.validation_alert:not(covered)')) | ||
| # Check to see that calendar ID input element is marked as invalid | ||
| self.assertTrue(self.browser.find_element_by_css_selector('#edit_calendar_id.error')) | ||
| # Save button should be disabled | ||
| self.assertTrue(self.browser.find_element_by_css_selector('#calendar-submit-options.disabled')) | ||
| clean_calendar_id_button = self.browser.find_element_by_css_selector('button.clear-calendar-id') | ||
| # Reset calendar ID value to default one | ||
| clean_calendar_id_button.click() | ||
| # Expecting every input value to be valid again | ||
| self.assertTrue(self.browser.find_element_by_css_selector('.validation_alert.covered')) | ||
|
|
||
| self.studio_save() | ||
| self.go_to_page(page_name, css_selector='div.google-calendar-xblock-wrapper') | ||
| calendar_iframe = self.browser.find_element_by_css_selector('iframe') | ||
| # Expecting that default calendar is the one loaded in the IFrame | ||
| self.assertEqual(calendar_iframe.get_attribute("src"), DEFAULT_CALENDAR_SRC) | ||
| # Expecting that the new display name is the title of the IFrame | ||
| self.assertEqual(calendar_iframe.get_attribute("title"), 'My Meetings') | ||
|
|
||
|
|
||
| @ddt # pylint: disable=too-many-ancestors | ||
| class GoogleDocumentStudioTest(GoogleDocumentBaseTest): | ||
| """ | ||
| Tests for Google Document studio view. | ||
| """ | ||
| default_css_selector = '#document-settings-tab' | ||
|
|
||
| def studio_save(self): | ||
| """ Save changes made in studio for Google Document """ | ||
| self.browser.find_element_by_css_selector('#document-submit-options').click() | ||
|
|
||
| @data(*DOCUMENT_SCENARIOS) # pylint: disable=star-args | ||
| @unpack | ||
| def test_save_document(self, page_name): | ||
| """ | ||
| Verify that option changes in Google Document studio view | ||
| are appropriately saved and visible immediately after | ||
| """ | ||
| self.go_to_page(page_name, view_name='studio_view') | ||
| # Expecting every input value to be valid | ||
| self.assertTrue(self.browser.find_element_by_css_selector('.validation_alert.covered')) | ||
| display_name_input = self.browser.find_element_by_css_selector('#edit_display_name') | ||
| # Change display name | ||
| display_name_input.clear() | ||
| display_name_input.send_keys('My Document') | ||
| # Expecting list item that contains input element for alternative text to be hidden | ||
| self.assertTrue(self.browser.find_element_by_css_selector('li#alt_text_item.covered')) | ||
|
|
||
| self.studio_save() | ||
| self.go_to_page(page_name, css_selector='div.google-docs-xblock-wrapper') | ||
| document_iframe = self.browser.find_element_by_css_selector('iframe') | ||
| # Expecting that default calendar is the one loaded in the IFrame | ||
| self.assertEqual(document_iframe.get_attribute("src"), DEFAULT_DOCUMENT_SRC) | ||
| # Expecting that the new display name is the title of the IFrame | ||
| self.assertEqual(document_iframe.get_attribute("title"), 'My Document') | ||
|
|
||
| @data(*IMAGE_SCENARIOS) # pylint: disable=star-args | ||
| @unpack | ||
| def test_save_image(self, page_name): | ||
| """ | ||
| Verify that option changes in Google Image studio view | ||
| are appropriately saved and visible immediately after | ||
| """ | ||
| self.go_to_page(page_name, view_name='studio_view') | ||
| # Expecting every input value to be valid | ||
| self.assertTrue(self.browser.find_element_by_css_selector('.validation_alert.covered')) | ||
| display_name_input = self.browser.find_element_by_css_selector('#edit_display_name') | ||
| # Change display name | ||
| display_name_input.clear() | ||
| display_name_input.send_keys('My Image') | ||
| # Expecting list item that contains input element for alternative text to be shown | ||
| self.assertTrue(self.browser.find_element_by_css_selector('li#alt_text_item:not(covered)')) | ||
| alt_text_input = self.browser.find_element_by_css_selector('#edit_alt_text') | ||
| # Add alternative text for image | ||
| alt_text_input.send_keys('Alternative text for my image') | ||
|
|
||
| self.studio_save() | ||
| self.go_to_page(page_name, css_selector='div.google-docs-xblock-wrapper') | ||
| image_iframe = self.browser.find_element_by_css_selector('img') | ||
| # Expecting that default calendar is the one loaded in the IFrame | ||
| self.assertEqual(image_iframe.get_attribute("src"), TEST_IMAGE_SRC) | ||
| # Expecting that the new display name is the title of the IFrame | ||
| self.assertEqual(image_iframe.get_attribute("alt"), 'Alternative text for my image') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1 @@ | ||
| <vertical_demo> | ||
| <google-calendar/> | ||
| </vertical_demo> | ||
| <google-calendar/> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1 @@ | ||
| <vertical_demo> | ||
| <google-document/> | ||
| </vertical_demo> | ||
| <google-document/> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1 @@ | ||
| <vertical_demo> | ||
| <google-document embed_code="<img src='https://docs.google.com/drawings/d/1lmmxboBM5c_0WCTjhAxBdkpqQb3T8VSwtuG0TRR1ODQ/pub?w=960&h=720'>"/> | ||
| </vertical_demo> | ||
| <google-document embed_code="<img src='https://docs.google.com/drawings/d/1lmmxboBM5c_0WCTjhAxBdkpqQb3T8VSwtuG0TRR1ODQ/pub?w=960&h=720'>"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added uninstall line like suggested