class PurchaseTestCase(WStoreSeleniumTestCase): tags = ("selenium", ) def __init__(self, methodName='runTest'): WStoreSeleniumTestCase.__init__(self, methodName=methodName) self.fixtures.extend(['basic_offerings.json', 'oauth_info.json']) def setUp(self): # Start the testing server self._server = TestServer() self._server.set_port(TESTING_PORT) self._server.set_max_request(2) self._server.start() # Load USDL info offering1_info = { 'base_uri': 'http://localhost:8081', 'image_url': '/media/provider__test_offering1__1.0/image.png', 'name': 'test_offering1', 'description': 'test', 'pricing': { 'price_model': 'free' } } _fill_offering_description('21000aba8e05ac2115f022ff', offering1_info, 'provider') WStoreSeleniumTestCase.setUp(self) def tearDown(self): if self._server.call_received() < self._server.max_request: from urllib2 import urlopen self._server.set_max_request(0) try: url = 'http://localhost:' + unicode(TESTING_PORT) urlopen(url) except: pass # Remove bills if needed for p in Purchase.objects.all(): for bill in p.bill: path = os.path.join(settings.BASEDIR, bill[1:]) try: os.remove(path) except: pass WStoreSeleniumTestCase.tearDown(self) def test_remote_purchase_form(self): token = self.oauth2_login() # Make API request to initiate the process opener = urllib2.build_opener() url = self.live_server_url + '/api/contracting/form' data = { 'offering': { 'organization': 'provider', 'name': 'test_offering1', 'version': '1.1' }, 'redirect_uri': 'http://localhost:' + unicode(TESTING_PORT) } headers = { 'content-type': 'application/json; charset=utf-8', 'Authorization': 'Bearer ' + token } request = MethodRequest('POST', url, json.dumps(data), headers) response = opener.open(request) # Redirect browser to the remote purchase form form_url = json.loads(response.read())['url'] self.driver.get(form_url) # Fill purchase form time.sleep(1) self.fill_tax_address({ 'street': 'fake street', 'postal': '12345', 'city': 'fake city', 'country': 'Spain' }) self.driver.find_element_by_css_selector('.modal-footer .btn-basic').click() time.sleep(1) # End the purchase self.driver.find_element_by_class_name('btn-danger').click() # Check redirection time.sleep(1) expected_url = 'http://localhost:' + unicode(TESTING_PORT) + '/' self.assertEquals(self.driver.current_url, expected_url)
class OfferingManagementTestCase(WStoreSeleniumTestCase): tags = ('selenium',) def __init__(self, methodName='runTest'): WStoreSeleniumTestCase.__init__(self, methodName=methodName) self.fixtures.extend(['repositories.json']) def setUp(self): # Start the testing server self._server = TestServer() self._server.set_port(TESTING_PORT) self._server.set_max_request(1) self._server.start() _fill_provider_role('provider') WStoreSeleniumTestCase.setUp(self) def tearDown(self): # If the server is still waiting for a call make a # fake call in order to terminate it if self._server.call_received() < self._server.max_request: from urllib2 import urlopen self._server.set_max_request(0) try: url = 'http://localhost:' + unicode(TESTING_PORT) urlopen(url) except: pass path = os.path.join(settings.BASEDIR, 'media/provider__test_offering__1.0') try: files = os.listdir(path) for f in files: file_path = os.path.join(path, f) os.remove(file_path) os.rmdir(path) except: pass WStoreSeleniumTestCase.tearDown(self) def test_create_offering(self): self.login('provider') self.click_first_nav() self._check_container('offerings-container', []) # Create self.create_offering_menu() self.fill_basic_offering_info({ 'name': 'test_offering', 'version': '1.0', 'notification': None, 'open': False }) self.driver.find_element_by_css_selector('.modal-footer > .btn').click() self.fill_usdl_info({ 'type': 'form', 'description': 'A test offering', 'price': '10', 'legal': { 'title': 'terms and conditions', 'text': 'An example terms and conditions' } }) self.driver.find_element_by_css_selector('.modal-footer > .btn').click() # Next self.driver.find_element_by_css_selector('.modal-footer > .btn').click() # Accept time.sleep(1) self.driver.find_element_by_css_selector('.modal-footer > .btn').click() # Accept time.sleep(1) self.click_second_cat() self._check_container('offerings-container', ['test_offering']) # Update self.open_offering_details('test_offering')
class PurchaseTestCase(WStoreSeleniumTestCase): tags = ("selenium", "selenium-purchase") def __init__(self, methodName='runTest'): WStoreSeleniumTestCase.__init__(self, methodName=methodName) self.fixtures.extend(['basic_offerings.json', 'oauth_info.json']) def setUp(self): # Start the testing server self._server = TestServer() self._server.set_port(TESTING_PORT) self._server.set_max_request(2) self._server.start() _set_offering_organization('21000aba8e05ac2115f022ff', 'provider') WStoreSeleniumTestCase.setUp(self) def tearDown(self): if self._server.call_received() < self._server.max_request: from urllib2 import urlopen self._server.set_max_request(0) try: url = 'http://localhost:' + unicode(TESTING_PORT) urlopen(url) except: pass # Remove bills if needed for p in Purchase.objects.all(): for bill in p.bill: path = os.path.join(settings.BASEDIR, bill[1:]) try: os.remove(path) except: pass WStoreSeleniumTestCase.tearDown(self) def get_modal_wait(self, locator): def not_present_modal(driver): element = False try: self.driver.implicitly_wait(0) driver.find_element_by_id(locator) except NoSuchElementException: element = driver.find_element_by_css_selector('.btn-danger') finally: self.driver.implicitly_wait(5) return element return not_present_modal def test_remote_purchase_form(self): token = self.oauth2_login() # Make API request to initiate the process opener = urllib2.build_opener() url = self.live_server_url + '/api/contracting/form' data = { 'offering': { 'organization': 'provider', 'name': 'test_offering1', 'version': '1.1' }, 'redirect_uri': 'http://localhost:' + unicode(TESTING_PORT) } headers = { 'content-type': 'application/json; charset=utf-8', 'Authorization': 'Bearer ' + token } request = MethodRequest('POST', url, json.dumps(data), headers) response = opener.open(request) # Redirect browser to the remote purchase form form_url = json.loads(response.read())['url'] self.driver.get(form_url) # Fill purchase form self.fill_tax_address({ 'street': 'fake street', 'postal': '12345', 'city': 'fake city', 'country': 'Spain' }) self.driver.find_element_by_css_selector( '.modal-footer .btn-basic').click() # Wait until the purchase modal dissapears element = WebDriverWait(self.driver, 5).until(self.get_modal_wait('postal')) # Close download resources modal WebDriverWait(self.driver, 5).until( EC.element_to_be_clickable( (By.CSS_SELECTOR, '.modal-footer .btn-basic'))).click() # Wait until the dowload modal dissapears element = WebDriverWait(self.driver, 5).until(self.get_modal_wait('message')) # End the purchase element.click() # Check redirection WebDriverWait(self.driver, 5).until( EC.element_to_be_clickable((By.CSS_SELECTOR, "hr"))) expected_url = 'http://localhost:' + unicode(TESTING_PORT) + '/' self.assertEquals(self.driver.current_url, expected_url)
class OfferingManagementTestCase(WStoreSeleniumTestCase): tags = ('selenium', ) def __init__(self, methodName='runTest'): WStoreSeleniumTestCase.__init__(self, methodName=methodName) self.fixtures.extend(['repositories.json']) def setUp(self): # Start the testing server self._server = TestServer() self._server.set_port(TESTING_PORT) self._server.set_max_request(1) self._server.start() _fill_provider_role('provider') WStoreSeleniumTestCase.setUp(self) def tearDown(self): # If the server is still waiting for a call make a # fake call in order to terminate it if self._server.call_received() < self._server.max_request: from urllib2 import urlopen self._server.set_max_request(0) try: url = 'http://localhost:' + unicode(TESTING_PORT) urlopen(url) except: pass path = os.path.join(settings.BASEDIR, 'media/provider__test_offering__1.0') shutil.rmtree(path, ignore_errors=True) WStoreSeleniumTestCase.tearDown(self) def test_create_offering(self): self.login('provider') self.click_first_nav() self._check_container('offerings-container', []) # Create self.create_offering_menu() self.fill_basic_offering_info({ 'name': 'test_offering', 'version': '1.0', 'notification': None, 'open': False }) self.driver.find_element_by_css_selector( '.modal-footer > .btn').click() self.fill_usdl_info({ 'description': 'A test offering', 'abstract': 'test', 'legal': { 'title': 'terms and conditions', 'text': 'An example terms and conditions' } }) self.driver.find_element_by_css_selector( '.modal-footer > input[value=Next]').click() # Next self.driver.find_element_by_css_selector( '.modal-footer > input[value=Next]').click() # Next element = WebDriverWait(self.driver, 5).until( EC.presence_of_element_located( (By.CSS_SELECTOR, ".modal-footer > input[value=Accept]"))) element.click() element = WebDriverWait(self.driver, 5).until( EC.presence_of_element_located( (By.CSS_SELECTOR, ".modal-footer > .btn"))) element.click() time.sleep(1) self.click_second_cat() self._check_container('offerings-container', ['test_offering']) # Update self.open_offering_details('test_offering')
class PurchaseTestCase(WStoreSeleniumTestCase): tags = ("selenium", "selenium-purchase") def __init__(self, methodName='runTest'): WStoreSeleniumTestCase.__init__(self, methodName=methodName) self.fixtures.extend(['basic_offerings.json', 'oauth_info.json']) def setUp(self): # Start the testing server self._server = TestServer() self._server.set_port(TESTING_PORT) self._server.set_max_request(2) self._server.start() _set_offering_organization('21000aba8e05ac2115f022ff', 'provider') WStoreSeleniumTestCase.setUp(self) def tearDown(self): if self._server.call_received() < self._server.max_request: from urllib2 import urlopen self._server.set_max_request(0) try: url = 'http://localhost:' + unicode(TESTING_PORT) urlopen(url) except: pass # Remove bills if needed for p in Purchase.objects.all(): for bill in p.bill: path = os.path.join(settings.BASEDIR, bill[1:]) try: os.remove(path) except: pass WStoreSeleniumTestCase.tearDown(self) def get_modal_wait(self, locator): def not_present_modal(driver): element = False try: self.driver.implicitly_wait(0) driver.find_element_by_id(locator) except NoSuchElementException: element = driver.find_element_by_css_selector('.btn-danger') finally: self.driver.implicitly_wait(5) return element return not_present_modal def test_remote_purchase_form(self): token = self.oauth2_login() # Make API request to initiate the process opener = urllib2.build_opener() url = self.live_server_url + '/api/contracting/form' data = { 'offering': { 'organization': 'provider', 'name': 'test_offering1', 'version': '1.1' }, 'redirect_uri': 'http://localhost:' + unicode(TESTING_PORT) } headers = { 'content-type': 'application/json; charset=utf-8', 'Authorization': 'Bearer ' + token } request = MethodRequest('POST', url, json.dumps(data), headers) response = opener.open(request) # Redirect browser to the remote purchase form form_url = json.loads(response.read())['url'] self.driver.get(form_url) # Select price plan self.select_plan('plan1') self.driver.find_element_by_css_selector('.modal-footer .btn-basic').click() # Accept terms and conditions self.accept_conditions() self.driver.find_element_by_css_selector('.modal-footer .btn-basic').click() # Fill purchase form self.fill_tax_address({ 'street': 'fake street', 'postal': '12345', 'city': 'fake city', 'country': 'Spain' }) self.driver.find_element_by_css_selector('.modal-footer .btn-basic').click() # Wait until the purchase modal dissapears WebDriverWait(self.driver, 5).until(self.get_modal_wait('postal')) # Close download resources modal WebDriverWait(self.driver, 5).until( EC.element_to_be_clickable((By.CSS_SELECTOR, '.modal-footer .btn-basic')) ).click() # Wait until the dowload modal dissapears element = WebDriverWait(self.driver, 5).until(self.get_modal_wait('message')) # End the purchase element.click() # Check redirection WebDriverWait(self.driver, 5).until( EC.element_to_be_clickable((By.CSS_SELECTOR, "hr")) ) expected_url = 'http://localhost:' + unicode(TESTING_PORT) + '/' self.assertEquals(self.driver.current_url, expected_url)
class OfferingManagementTestCase(WStoreSeleniumTestCase): tags = ('selenium',) def __init__(self, methodName='runTest'): WStoreSeleniumTestCase.__init__(self, methodName=methodName) self.fixtures.extend(['repositories.json']) def setUp(self): # Start the testing server self._server = TestServer() self._server.set_port(TESTING_PORT) self._server.set_max_request(1) self._server.start() _fill_provider_role('provider') WStoreSeleniumTestCase.setUp(self) def tearDown(self): # If the server is still waiting for a call make a # fake call in order to terminate it if self._server.call_received() < self._server.max_request: from urllib2 import urlopen self._server.set_max_request(0) try: url = 'http://localhost:' + unicode(TESTING_PORT) urlopen(url) except: pass path = os.path.join(settings.BASEDIR, 'media/provider__test_offering__1.0') shutil.rmtree(path, ignore_errors=True) WStoreSeleniumTestCase.tearDown(self) def test_create_offering(self): self.login('provider') self.click_first_nav() self._check_container('offerings-container', []) # Create self.create_offering_menu() self.fill_basic_offering_info({ 'name': 'test_offering', 'version': '1.0', 'notification': None, 'open': False }) self.driver.find_element_by_css_selector('.modal-footer > .btn').click() self.fill_usdl_info({ 'description': 'A test offering', 'abstract': 'test', 'legal': { 'title': 'terms and conditions', 'text': 'An example terms and conditions' } }) self.driver.find_element_by_css_selector('.modal-footer > input[value=Next]').click() # Next self.driver.find_element_by_css_selector('.modal-footer > input[value=Next]').click() # Next element = WebDriverWait(self.driver, 5).until( EC.presence_of_element_located((By.CSS_SELECTOR, ".modal-footer > input[value=Accept]")) ) element.click() element = WebDriverWait(self.driver, 5).until( EC.presence_of_element_located((By.CSS_SELECTOR, ".modal-footer > .btn")) ) element.click() time.sleep(1) self.click_second_cat() self._check_container('offerings-container', ['test_offering']) # Update self.open_offering_details('test_offering')