def submitQueue(NETID, PASSWORD, SECURITY_QUESTIONS): browser = Browser() # netid page browser.visit("https://puaccess.princeton.edu/psp/hsprod/EMPLOYEE/HRMS/h/?tab=DEFAULT") browser.fill('userid', NETID) browser.find_by_value("Continue").first.click() # password page browser.fill('Bharosa_Password_PadDataField', PASSWORD) browser.evaluate_script("Bharosa_Password_Pad.keyPress('ENTERKEY');") # security question page html = browser.html for key in SECURITY_QUESTIONS.keys(): if key in html: answer = SECURITY_QUESTIONS[key] browser.fill('Bharosa_Challenge_PadDataField', answer) browser.evaluate_script("Bharosa_Challenge_Pad.keyPress('ENTERKEY');") time.sleep(2) # welcome to SCORE browser.find_link_by_text("Student Center").first.click() # student center, start by busting out of the iframe browser.visit("https://puaccess.princeton.edu/psc/hsprod/EMPLOYEE/HRMS/c/SA_LEARNER_SERVICES.SSS_STUDENT_CENTER.GBL?PORTALPARAM_PTCNAV=HC_SSS_STUDENT_CENTER&EOPP.SCNode=HRMS&EOPP.SCPortal=EMPLOYEE&EOPP.SCName=ADMN_SCORE&EOPP.SCLabel=&EOPP.SCPTcname=ADMN_SC_SP_SCORE&FolderPath=PORTAL_ROOT_OBJECT.PORTAL_BASE_DATA.CO_NAVIGATION_COLLECTIONS.ADMN_SCORE.ADMN_S200801281459482840968047&IsFolder=false&PortalActualURL=https%3a%2f%2fpuaccess.princeton.edu%2fpsc%2fhsprod%2fEMPLOYEE%2fHRMS%2fc%2fSA_LEARNER_SERVICES.SSS_STUDENT_CENTER.GBL&PortalContentURL=https%3a%2f%2fpuaccess.princeton.edu%2fpsc%2fhsprod%2fEMPLOYEE%2fHRMS%2fc%2fSA_LEARNER_SERVICES.SSS_STUDENT_CENTER.GBL&PortalContentProvider=HRMS&PortalCRefLabel=Student%20Center&PortalRegistryName=EMPLOYEE&PortalServletURI=https%3a%2f%2fpuaccess.princeton.edu%2fpsp%2fhsprod%2f&PortalURI=https%3a%2f%2fpuaccess.princeton.edu%2fpsc%2fhsprod%2f&PortalHostNode=HRMS&NoCrumbs=yes&PortalKeyStruct=yes") browser.select('DERIVED_SSS_SCL_SSS_MORE_ACADEMICS', "1005") browser.find_by_id("DERIVED_SSS_SCL_SSS_GO_1").first.click() # pick semester browser.choose("SSR_DUMMY_RECV1$sels$0", "1") browser.find_by_id("DERIVED_SSS_SCT_SSR_PB_GO").first.click() # select classes to add... class should already be in queue browser.find_by_id("DERIVED_REGFRM1_LINK_ADD_ENRL$115$").first.click() # confirm classes browser.find_by_id("DERIVED_REGFRM1_SSR_PB_SUBMIT").first.click()
def test_add_name(self): driver =Browser('firefox') #navigate to webpage driver.visit('http://www.ranorex.com/web-testing-examples/vip/') #enter First name driver.find_by_xpath('//*[@id="'"FirstName"'"]').fill('Prasanth') #Enter Last name driver.find_by_xpath('//*[@id="'"LastName"'"]').fill('Patil') #Selecting the category driver.select_id('Category','Music') driver.choose('Gender','male') driver.find_by_xpath('//*[@id="'"Add"'"]').click() #def test_load(self): driver.find_by_xpath('//*[@id="'"Load"'"]').click() #def test_save(self): driver.find_by_xpath('//*[@id="'"Save"'"]').click()
def VisitExpediaforFlights(in_ofile, in_first, in_second, in_third): # Create Browser browser = Browser('chrome', '--incognito') # Visit google browser.visit('http://www.expedia.ca/Flights') time.sleep(10) # Choose multicity triip browser.choose('TripType', 'Multicity') # Fill in the number of adults browser.select('NumAdult', '3') # Fill in the first flight fillflight(browser, 1, 'PEK', 'YVR', str(in_first) + '/08/2015') # Flight 2 fillflight(browser, 2, 'YVR', 'YSJ', str(in_second) + '/08/2015') # Flight 3 fillflight(browser, 3, 'YSJ', 'PEK', str(in_third) + '/08/2015') # Click on Search browser.find_by_id('F-searchButtonExt1').click() time.sleep(10) # Parse the string modulelist = browser.find_by_id('flightModuleList').value.split('SELECT') #iterate over list for moduleiter in modulelist: writetocsv(in_ofile, moduleiter) # Close browser browser.quit()
class SchemaTestCase(LiveServerTestCase): """ A set of tests for testing export schema, import schema and everything related to advanced types (patterns, options, etc.). """ def setUp(self): self.browser = Browser() socket.setdefaulttimeout(30) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') def tearDown(self): logout(self) self.browser.quit() @classmethod def tearDownClass(cls): sleep(10) # It needs some time for close the LiverServerTestCase super(SchemaTestCase, cls).tearDownClass() def test_export_schema(self): create_graph(self) create_schema(self) create_type(self) self.browser.find_by_id('toolsMenu').first.click() cookies = { self.browser.cookies.all()[0]["name"]: self.browser.cookies.all()[0]["value"], self.browser.cookies.all()[1]["name"]: self.browser.cookies.all()[1]["value"] } result = requests.get(self.live_server_url + '/schemas/bobs-graph/export/', cookies=cookies) spin_assert(lambda: self.assertEqual(result.headers['content-type'], 'application/json')) spin_assert(lambda: self.assertEqual( self.browser.status_code.is_success(), True)) f = open('sylva/sylva/tests/files/bobs-graph_schema.json') spin_assert( lambda: self.assertEqual(f.read().split("\n")[0], result.content)) def test_import_schema(self): create_graph(self) create_schema(self) self.browser.find_by_id('schemaImport').first.click() file_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'files/bobs-graph_schema.json') self.browser.attach_file('file', file_path) self.browser.find_by_value('Continue').first.click() spin_assert(lambda: self.assertEqual(self.browser.title, "SylvaDB - Bob's graph")) text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "Name")) def test_new_type(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_xpath( "//div[@class='content2-first']/p/textarea[@name='description']" ).first.fill('The loved type') self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_xpath( "//div[@id='diagramBox_bobs-type']/div[@class='title']" ).first.value spin_assert(lambda: self.assertNotEqual(text.find("Bob's type"), -1)) def test_new_advanced_type(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_name('properties-0-default').first.fill( "Bob's node default name") self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "Name")) def test_new_advanced_type_string_empty(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('String name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Basic']/option[@value='s']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "String name")) # Testing data self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath( "//td[@class='dataActions']/a[@class='dataOption new']" ).first.click() self.browser.find_by_name('String name').first.fill('') self.browser.find_by_value("Save Bob's type").first.click() text = self.browser.find_by_xpath( "//ul[@class='errorlist']/li").first.text spin_assert(lambda: self.assertEqual(text, 'This field is required.')) Graph.objects.get(name="Bob's graph").destroy() def test_new_advanced_type_boolean(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill( 'Boolean name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Basic']/option[@value='b']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "Boolean name")) def test_new_advanced_type_number(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Number name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Basic']/option[@value='n']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "Number name")) def test_new_advanced_type_number_float(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Number name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Basic']/option[@value='n']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "Number name")) # Testing data self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath( "//td[@class='dataActions']/a[@class='dataOption new']" ).first.click() self.browser.find_by_name('Number name').first.fill('1.5') self.browser.find_by_value("Save Bob's type").first.click() text = self.browser.find_by_css('input:invalid').first.value spin_assert(lambda: self.assertEqual(text, '1.5')) Graph.objects.get(name="Bob's graph").destroy() def test_new_advanced_type_number_string(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Number name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Basic']/option[@value='n']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "Number name")) # Testing data self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath( "//td[@class='dataActions']/a[@class='dataOption new']" ).first.click() self.browser.find_by_name('Number name').first.fill('number') self.browser.find_by_value("Save Bob's type").first.click() text = self.browser.find_by_css('input:invalid').first.outer_html spin_assert(lambda: self.assertEqual( text, '<input id="id_Number name" name="Number name" type="number">')) Graph.objects.get(name="Bob's graph").destroy() def test_new_advanced_type_text(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Text name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='x']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "Text name")) def test_new_advanced_type_date(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Date name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='d']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "Date name")) def test_new_advanced_type_time(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Time name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='t']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "Time name")) def test_new_advanced_type_time_string(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Time name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='t']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "Time name")) # Testing data self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath( "//td[@class='dataActions']/a[@class='dataOption new']" ).first.click() self.browser.find_by_name('Time name').first.fill('0123456789') sleep(5) # Wating to the datepicker to open self.browser.find_by_xpath( "//button[@class='ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all']" ).first.click() sleep(5) # Waiting to the datepicker to close self.browser.find_by_value("Save Bob's type").first.click() text = self.browser.find_by_xpath( "//ul[@class='errorlist']/li").first.text spin_assert(lambda: self.assertEqual(text, 'Enter a valid time.')) Graph.objects.get(name="Bob's graph").destroy() def test_new_advanced_type_choices(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill( 'Choices name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='c']" ).first.click() self.browser.find_by_name('properties-0-default').first.fill( 'Bob, Alice') self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "Choices name")) def test_new_advanced_type_float(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('float name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='f']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "float name")) def test_new_advanced_type_collaborator(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill( 'collaborator name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='r']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "collaborator name")) def test_new_advanced_type_auto_now(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill( 'auto now name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Auto']/option[@value='w']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "auto now name")) def test_new_advanced_type_auto_now_add(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill( 'auto now add name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Auto']/option[@value='a']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "auto now add name")) def test_new_advanced_type_auto_increment(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill( 'auto increment name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Auto']/option[@value='i']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "auto increment name")) def test_new_advanced_type_auto_increment_update(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill( 'auto increment update') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Auto']/option[@value='o']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "auto increment update")) def test_new_advanced_type_auto_user(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value spin_assert(lambda: self.assertEqual(text, 'Type')) self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill( 'auto user name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath( "//select[@id='id_properties-0-datatype']/optgroup[@label='Auto']/option[@value='e']" ).first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value spin_assert(lambda: self.assertEqual(text, "auto user name")) def test_schema_allowed_rel_addition(self): create_graph(self) spin_assert(lambda: self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')) create_schema(self) create_type(self) spin_assert(lambda: self.assertEqual(self.browser.title, "SylvaDB - Bob's graph")) self.browser.find_by_id('allowedRelations').first.click() self.browser.select('source', '1') self.browser.find_by_name('name').fill("Bob's rel") self.browser.select('target', '1') self.browser.find_by_id('id_description').fill( "This the allowed relationship for Bob's graph") self.browser.find_by_value('Save Type').first.click() spin_assert(lambda: self.assertEqual(self.browser.title, "SylvaDB - Bob's graph")) text = self.browser.find_by_xpath( "//div[@class='form-row indent']/label").first.value spin_assert(lambda: self.assertNotEqual(text.find("Bob's rel"), -1)) def test_schema_allowed_rel_addition_deletion(self): create_graph(self) spin_assert(lambda: self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')) create_schema(self) create_type(self) spin_assert(lambda: self.assertEqual(self.browser.title, "SylvaDB - Bob's graph")) self.browser.find_by_id('allowedRelations').first.click() self.browser.select('source', '1') self.browser.find_by_name('name').fill("Bob's rel") self.browser.select('target', '1') self.browser.find_by_id('id_description').fill( "This the allowed relationship for Bob's graph") self.browser.find_by_value('Save Type').first.click() spin_assert(lambda: self.assertEqual(self.browser.title, "SylvaDB - Bob's graph")) text = self.browser.find_by_xpath( "//div[@class='form-row indent']/label").first.value spin_assert(lambda: self.assertNotEqual(text.find("Bob's rel"), -1)) self.browser.find_by_xpath( "//div[@class='form-row indent']/div[@class='form-row indent']/a" ).first.click() self.browser.find_by_xpath( "//span[@class='buttonLinkOption buttonLinkRight']/a[@class='delete']" ).first.click() self.browser.choose('confirm', '1') self.browser.find_by_value('Continue').first.click() notExists = self.browser.is_element_not_present_by_xpath( "//div[@class='form-row indent']/label") spin_assert(lambda: self.assertEqual(notExists, True))
class WorkerThread(QThread): def __init__(self, nameOfList, username, password, weeksToReserve, form_data_version, parent=None): QThread.__init__(self, parent) self.username = username self.password = password self.nameOfList = nameOfList self.weeks_to_reserve = weeksToReserve self.form_data_version = form_data_version print form_data_version # self.reserve = Reserve() # QThread.__init__(self) def stop_thread(self): self.quit() def run(self): foods, rests_and_day_numbers_of_week, user_list_version = self.decode_database( self.nameOfList ) # decode database # self.reserve.login(self.username,self.password) # check userlist version if user_list_version != self.form_data_version: print user_list_version self.emit(SIGNAL("showQuestion()")) self.emit(SIGNAL("removeThread(QString)"), self.username) return self.stop_thread() try: self.emit(SIGNAL("log(QString)"), self.username + u": رزرو شروع شد") # print self.username,": reservaion started" self.login(self.username, self.password) # login to website except AttributeError: self.emit( SIGNAL("Error(QString,QString)"), u"خطای ورود", u"نام کاربری یا پسورد شما اشتباه است :" + self.username ) self.emit(SIGNAL("log(QString)"), self.username + ":" + u" رزرو ناموفق- نام کاربری یا پسورد شما اشتباه است") self.emit(SIGNAL("removeThread(QString)"), self.username) return self.stop_thread() except Exception as e: self.emit(SIGNAL("Error(QString,QString)"), u"خطا", u"متاسفانه خطایی رخ داد ") # print e self.emit(SIGNAL("removeThread(QString)"), self.username) return self.stop_thread() this_week_available_days, next_week_available_days = self.collect_available_days() # find the available days if "this" in self.weeks_to_reserve: if this_week_available_days: self.reserve_for_a_week( rests_and_day_numbers_of_week=rests_and_day_numbers_of_week, available_days=this_week_available_days, foods=foods, ) if "next" in self.weeks_to_reserve: if next_week_available_days: self.reserve_for_a_week( rests_and_day_numbers_of_week=rests_and_day_numbers_of_week, available_days=next_week_available_days, foods=foods, ) else: self.emit( SIGNAL("log(QString)"), self.username + ":" + "\n" + u" رزرو برای هفته ی بعد هنوز باز نشده است بعدا امتحان کنید ", ) self.take_screenshot(self.username, self.nameOfList) self.open_screenshot(self.username, self.nameOfList) self.emit(SIGNAL("reservation(QString,QString)"), u"انجام شد", u"رزرو برای " + self.username + u" انجام شد ") self.emit(SIGNAL("removeThread(QString)"), self.username) self.emit(SIGNAL("log(QString)"), u" رزرو برای " + self.username + u" انجام شد ") def reserve_for_a_week(self, rests_and_day_numbers_of_week, available_days, foods): day_mapping = [u"شنبه", u"1شنبه", u"2شنبه", u"3شنبه", u"4شنبه", u"5شنبه", u"جمعه"] meal_mapping = [u"صبحانه", u"ناهار", u"شام"] # reserv for a week for rests_and_day_number_of_each_day in rests_and_day_numbers_of_week: check_credit = self.check_credit() if check_credit != True: self.emit( SIGNAL("log(QString)"), self.username + ":" + "\n" + u" اعتبار شما کافی نیست " + str(check_credit) + "-", ) break meal = 0 selected_day = rests_and_day_number_of_each_day["day"] if str(selected_day) in available_days.keys(): # avilable_days.keys == day number of available days for rest in rests_and_day_number_of_each_day["rests"]: if rest == "": self.emit( SIGNAL("log(QString)"), self.username + ":" + "\n" + u" روز " + day_mapping[selected_day] + u" " + meal_mapping[meal] + u" انتخاب نکرده اید ", ) meal += 1 continue foods_of_meal = foods[meal] try: reserved = self.reserve_this(available_days[str(selected_day)], rest, str(meal), foods_of_meal) if reserved == True: self.emit( SIGNAL("log(QString)"), self.username + ":" + "\n" + u" روز " + day_mapping[selected_day] + u" " + meal_mapping[meal] + u" رزرو شد ", ) except: self.emit( SIGNAL("log(QString)"), self.username + ":" + "\n" + meal_mapping[meal] + u" روز " + day_mapping[selected_day] + u" قبلا رزرو شده یا این وعده سرو نمی شود", ) else: if reserved == False: self.emit( SIGNAL("log(QString)"), self.username + ":" + "\n" + meal_mapping[meal] + u" روز " + day_mapping[selected_day] + u" هیچ یک از انتخاب های شما سرو نمی شود ", ) meal += 1 else: self.emit( SIGNAL("log(QString)"), self.username + ":" + "\n" + u" همه ی وعده های روز " + day_mapping[selected_day] + u" قبلا رزرو شده یا سلف تعطیل است ", ) def decode_database(self, name_of_database): json_file = open("./foodlists/" + name_of_database, "r") json_decoded = json.load(json_file) foods = json_decoded["foods"] # export foods rests_and_day_numbers_of_week = json_decoded["restsOfEachDay"] # export days user_list_version = json_decoded["version"] return (foods, rests_and_day_numbers_of_week, user_list_version) def login(self, username, password): self.browser = Browser("phantomjs") self.browser.driver.set_window_size(800, 371) self.wait_time = 2 self.browser.visit("http://sups.shirazu.ac.ir/sfxweb/Gate/Login.aspx") self.browser.is_element_not_present_by_id("edId", self.wait_time) # wait until see the element self.browser.find_by_id("edId").fill(username) self.browser.find_by_id("edPass").fill(password) self.browser.find_by_id("edWebApp").select(1) self.browser.find_by_id("edEnter").click() self.browser.find_by_css("ul.active:nth-child(3) > li:nth-child(2)").click() def reserve_this(self, selected_date, selected_rest, selected_meal, foods_of_meal): # select restaurant rest = self.browser.find_by_id("edRestaurant") self.browser.select("edRestaurant", selected_rest) # select date self.browser.is_element_not_present_by_id("edDate", self.wait_time) # wait until see the element self.browser.select("edDate", selected_date) # select meal self.browser.is_element_not_present_by_id("edMeal", self.wait_time) # wait until see the element meal = self.browser.find_by_id("edMeal") meal.select(selected_meal) # collect serving foods serving_foods = [] self.browser.is_element_not_present_by_id("Food", self.wait_time) # wait until see the element number_of_foods = len(self.browser.find_by_css("#Food li")) for nth in range(1, number_of_foods + 1): value = self.browser.find_by_css("#Food > li:nth-child(" + str(nth) + ") > input:nth-child(1)").value serving_foods.append(value) # select food and reserv reserved = False for food in foods_of_meal: # select food of that meal if str(food) in serving_foods: self.browser.choose("Food", str(food)) self.browser.find_by_id("btnBuyChip").click() reserved = True break return reserved def date_of_this_friday(self): today = datetime.date.today() week_day_of_today_gre = today.weekday() week_day_of_today_per = week_day_of_today_gre + 2 if week_day_of_today_gre < 5 else week_day_of_today_gre - 5 days_to_friday = datetime.timedelta(days=6 - week_day_of_today_per) this_friday = today + days_to_friday return this_friday def collect_available_days(self): dates = self.collect_available_dates() # find the available dates this_friday = self.date_of_this_friday() next_saturday = this_friday + datetime.timedelta(days=1) this_week_available_days = {} next_week_available_days = {} for date in dates: year = int(date[0:4]) month = int(date[4:6]) day = int(date[6:8]) gre_date = jalali.Persian(year, month, day).gregorian_datetime() weekday = gre_date.weekday() day_number = weekday + 2 if weekday < 5 else weekday - 5 if gre_date > this_friday: next_week_available_days[str(day_number)] = date if gre_date < next_saturday: this_week_available_days[str(day_number)] = date return (this_week_available_days, next_week_available_days) def collect_available_dates(self): rest = self.browser.find_by_id("edRestaurant") self.browser.select("edRestaurant", "8") dates = [] number_of_dates = len(self.browser.find_by_css("#edDate >option")) for nth in range(2, number_of_dates + 1): value = self.browser.find_by_css("#edDate > option:nth-child(" + str(nth) + ")").value dates.append(value) return dates def take_screenshot(self, username, nameOfList): # self.browser.back() # self.browser.find_by_css('ul.active:nth-child(3) > li:nth-child(1)').click() self.browser.driver.save_screenshot("./screenshots/" + username + nameOfList[0:-5] + ".png") def open_screenshot(self, username, nameOfList): filename = os.getcwd() + "/screenshots/" + username + nameOfList[0:-5] + ".png" if sys.platform == "win32": os.startfile(filename) else: opener = "open" if sys.platform == "darwin" else "xdg-open" subprocess.call([opener, filename]) def check_credit(self): string_credit = self.browser.find_by_id("lblCredit") int_credit = int(string_credit.text.replace(",", "")) if int_credit < -1500: return int_credit return True
class DataNodeTestCase(LiveServerTestCase): """ A set of tests to test all interaction related to the creation and deletion of nodes and relationships. Also, we test export the data in two formats: gexf and csv. """ def setUp(self): self.browser = Browser() socket.setdefaulttimeout(30) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') def tearDown(self): logout(self) self.browser.quit() @classmethod def tearDownClass(cls): sleep(10) # It needs some time for close the LiverServerTestCase super(DataNodeTestCase, cls).tearDownClass() def test_data_node_addition(self): create_graph(self) create_schema(self) create_type(self) create_data(self) # Check the node name self.browser.find_by_xpath("//td[@class='dataList']/a[@class='edit']").first.click() text = self.browser.find_by_id('propertiesTitle').first.value spin_assert(lambda: self.assertEqual(text, 'Properties')) self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkRight']/a").first.click() self.browser.choose('confirm', '1') self.browser.find_by_value('Continue').first.click() text = self.browser.find_by_xpath("//div[@class='indent']/div").first.value Graph.objects.get(name="Bob's graph").destroy() spin_assert(lambda: self.assertEqual(text, 'Nodes: 0')) def test_data_node_addition_rel_add_del(self): create_graph(self) create_schema(self) create_type(self) create_node(self, "Bob") create_node(self, "Alice") # We create a allowed relation js_code = "$('a#schema-link')[0].click();" self.browser.execute_script(js_code) self.browser.find_by_id('allowedRelations').first.click() self.browser.select('source', '1') self.browser.find_by_name('name').fill("Bob's rel") self.browser.select('target', '1') self.browser.find_by_id('id_description').fill("This the allowed relationship for Bob's graph") self.browser.find_by_value('Save Type').first.click() spin_assert(lambda: self.assertEqual( self.browser.title, "SylvaDB - Bob's graph")) # We create the link between the nodes self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath("//td[@class='dataActions']/a[@class='dataOption list']").first.click() self.browser.find_by_xpath("//td[@class='dataList']/a[@class='edit']").first.click() self.browser.find_by_xpath("//li[@class='token-input-input-token']/input").first.fill('Alice') self.browser.is_element_present_by_id("id_user_wait", 5) self.browser.find_by_xpath("//div[@class='token-input-dropdown']//li[@class='token-input-dropdown-item2 token-input-selected-dropdown-item']/b").first.click() self.browser.find_by_value("Save Bob's type").first.click() # Delete the relationship self.browser.find_by_xpath("//td[@class='dataList']/a[@class='edit']").first.click() self.browser.find_by_xpath("//span[@class='all-relationships incoming-relationships i_bobs_rel1-relationships']//a[@class='delete-row initial-form floating']").first.click() self.browser.find_by_value("Save Bob's type").first.click() self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() text = self.browser.find_by_xpath("//div[@class='flags-block']/span[@class='graph-relationships']").first.value spin_assert(lambda: self.assertEqual(text, "0 relationships")) Graph.objects.get(name="Bob's graph").destroy() def test_node_type_deletion_keeping_nodes(self): create_graph(self) create_schema(self) create_type(self) # Adding relationship to the type self.browser.find_by_id('allowedRelations').first.click() self.browser.select('source', '1') self.browser.find_by_name('name').fill("Bob's rel") self.browser.select('target', '1') self.browser.find_by_id('id_description').fill( 'The loved relationship') self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_xpath( "//div[@class='form-row indent']/label").first.value spin_assert(lambda: self.assertNotEqual(text.find("Bob's rel"), -1)) # Creating nodes create_node(self, 'Bob') create_node(self, 'Alice') # Creating relationship between nodes self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath("//td[@class='dataActions']/a[@class='dataOption list']").first.click() self.browser.find_by_xpath("//td[@class='dataList']/a[@class='edit']").first.click() self.browser.find_by_xpath("//li[@class='token-input-input-token']/input").first.fill('Alice') self.browser.is_element_present_by_id("id_user_wait", wait_time=5) self.browser.find_by_xpath("//div[@class='token-input-dropdown']//li[@class='token-input-dropdown-item2 token-input-selected-dropdown-item']/b").first.click() self.browser.find_by_value("Save Bob's type").first.click() self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() text = self.browser.find_by_xpath("//div[@class='flags-block']/span[@class='graph-relationships']").first.value spin_assert(lambda: self.assertEqual(text, "1 relationships")) # Deleting type js_code = "$('a#schema-link')[0].click();" self.browser.execute_script(js_code) self.browser.find_by_xpath("//fieldset[@class='module aligned wide model']/h2/a").first.click() self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkRight']/a[@class='delete']").first.click() text = self.browser.find_by_xpath( "//p/label[@for='id_option_0']").first.value spin_assert(lambda: self.assertNotEqual(text.find( "We found some elements of this type"), -1)) # Keeping nodes self.browser.choose('option', 'no') self.browser.find_by_value('Continue').first.click() text = self.browser.find_by_xpath( "//div[@class='body-inside']/p").first.value spin_assert(lambda: self.assertEqual( text, 'There are no types defined yet.')) # Checking self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() text = self.browser.find_by_xpath("//div[@class='flags-block']/span[@class='graph-nodes']").first.value spin_assert(lambda: self.assertEqual(text, "2 nodes")) text = self.browser.find_by_xpath("//div[@class='flags-block']/span[@class='graph-relationships']").first.value spin_assert(lambda: self.assertEqual(text, "1 relationships")) text = self.browser.find_by_xpath( "//div[@class='graph-empty-message']").first.value spin_assert(lambda: self.assertNotEqual( text.find("Your Schema is empty."), -1)) Graph.objects.get(name="Bob's graph").destroy() def test_node_type_deletion_deleting_nodes(self): create_graph(self) create_schema(self) create_type(self) # Adding relationship to the type self.browser.find_by_id('allowedRelations').first.click() self.browser.select('source', '1') self.browser.find_by_name('name').fill("Bob's rel") self.browser.select('target', '1') self.browser.find_by_id('id_description').fill( 'The loved relationship') self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_xpath( "//div[@class='form-row indent']/label").first.value spin_assert(lambda: self.assertNotEqual(text.find("Bob's rel"), -1)) # Creating nodes create_node(self, 'Bob') create_node(self, 'Alice') # Creating relationship between nodes self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath("//td[@class='dataActions']/a[@class='dataOption list']").first.click() self.browser.find_by_xpath("//td[@class='dataList']/a[@class='edit']").first.click() self.browser.find_by_xpath("//li[@class='token-input-input-token']/input").first.fill('Alice') self.browser.is_element_present_by_id("id_user_wait", wait_time=5) self.browser.find_by_xpath("//div[@class='token-input-dropdown']//li[@class='token-input-dropdown-item2 token-input-selected-dropdown-item']/b").first.click() self.browser.find_by_value("Save Bob's type").first.click() self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() text = self.browser.find_by_xpath("//div[@class='flags-block']/span[@class='graph-relationships']").first.value spin_assert(lambda: self.assertEqual(text, "1 relationships")) # Deleting type js_code = "$('a#schema-link')[0].click();" self.browser.execute_script(js_code) self.browser.find_by_xpath("//fieldset[@class='module aligned wide model']/h2/a").first.click() self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkRight']/a[@class='delete']").first.click() text = self.browser.find_by_xpath( "//p/label[@for='id_option_0']").first.value spin_assert(lambda: self.assertNotEqual(text.find( "We found some elements of this type"), -1)) # Deleting nodes self.browser.choose('option', 'de') self.browser.find_by_value('Continue').first.click() text = self.browser.find_by_xpath( "//div[@class='body-inside']/p").first.value spin_assert(lambda: self.assertEqual( text, 'There are no types defined yet.')) # Checking self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() text = self.browser.find_by_xpath("//div[@class='flags-block']/span[@class='graph-nodes']").first.value spin_assert(lambda: self.assertEqual(text, "0 nodes")) text = self.browser.find_by_xpath("//div[@class='flags-block']/span[@class='graph-relationships']").first.value spin_assert(lambda: self.assertEqual(text, "0 relationships")) Graph.objects.get(name="Bob's graph").destroy() def test_data_node_clone(self): create_graph(self) create_schema(self) create_type(self) create_data(self) original_name = self.browser.find_by_xpath("//table[@id='content_table']/tbody/tr/td")[1].value # Clone the node self.browser.find_by_xpath("//table[@id='content_table']/tbody/tr/td/a[@class='edit']").first.click() self.browser.find_by_name('Name').first.fill(original_name + " clone") self.browser.find_by_name("as-new").first.click() # Check that two nodes exist original_name = self.browser.find_by_xpath("//table[@id='content_table']/tbody/tr/td")[1].value clone_name = self.browser.find_by_xpath("//table[@id='content_table']/tbody/tr/td")[4].value spin_assert(lambda: self.assertEqual(original_name, "Bob's node")) spin_assert(lambda: self.assertEqual(clone_name, "Bob's node clone")) Graph.objects.get(name="Bob's graph").destroy() def test_sigma_visualization_in_node_view(self): create_graph(self) create_schema(self) create_type(self) # Adding relationship to the type self.browser.find_by_id('allowedRelations').first.click() self.browser.select('source', '1') self.browser.find_by_name('name').fill("Bob's rel") self.browser.select('target', '1') self.browser.find_by_id('id_description').fill( 'The loved relationship') self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_xpath( "//div[@class='form-row indent']/label").first.value spin_assert(lambda: self.assertNotEqual(text.find("Bob's rel"), -1)) # Creating nodes create_node(self, 'Bob') create_node(self, 'Alice') # Creating relationship between nodes self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath("//td[@class='dataActions']/a[@class='dataOption list']").first.click() self.browser.find_by_xpath("//td[@class='dataList']/a[@class='edit']").first.click() self.browser.find_by_xpath("//li[@class='token-input-input-token']/input").first.fill('Alice') self.browser.is_element_present_by_id("id_user_wait", wait_time=5) self.browser.find_by_xpath("//div[@class='token-input-dropdown']//li[@class='token-input-dropdown-item2 token-input-selected-dropdown-item']/b").first.click() self.browser.find_by_value("Save Bob's type").first.click() # Checking self.browser.find_by_xpath("//table[@id='content_table']/tbody/tr/td/a[@title='View node']/p[text()='Alice']").first.click() self.browser.is_element_present_by_id('wait_for_js', 3) js_code = ''' var instance = sigma.instances(0); sylva.test_node_count = instance.graph.nodes().length; ''' self.browser.execute_script(js_code) text = self.browser.evaluate_script('sylva.test_node_count') spin_assert(lambda: self.assertEqual(text, 2)) Graph.objects.get(name="Bob's graph").destroy() def test_graph_export_gexf(self): create_graph(self) create_schema(self) create_type(self) create_data(self) self.browser.find_by_id('toolsMenu').first.click() cookies = {self.browser.cookies.all()[0]["name"]: self.browser.cookies.all()[0]["value"], self.browser.cookies.all()[1]["name"]: self.browser.cookies.all()[1]["value"]} result = requests.get(self.live_server_url + '/tools/bobs-graph/export/gexf/', cookies=cookies) spin_assert(lambda: self.assertEqual( result.headers['content-type'], 'application/xml')) spin_assert(lambda: self.assertEqual( self.browser.status_code.is_success(), True)) fw = open('sylva/sylva/tests/files/bobs-graph.gexf', 'w') fw.write(result.content) fw.close() f = open('sylva/sylva/tests/files/bobs-graph.gexf') xmlFile = "" for line in f: xmlFile += line f.close() spin_assert(lambda: self.assertEqual(xmlFile, result.content)) Graph.objects.get(name="Bob's graph").destroy() def test_graph_export_csv(self): create_graph(self) create_schema(self) create_type(self) create_data(self) self.browser.find_by_id('toolsMenu').first.click() cookies = {self.browser.cookies.all()[0]["name"]: self.browser.cookies.all()[0]["value"], self.browser.cookies.all()[1]["name"]: self.browser.cookies.all()[1]["value"]} result = requests.get(self.live_server_url + '/tools/bobs-graph/export/csv/', cookies=cookies) spin_assert(lambda: self.assertEqual( result.headers['content-type'], 'application/zip')) spin_assert(lambda: self.assertEqual( self.browser.status_code.is_success(), True)) test_file = StringIO(result.content) csv_zip = ZipFile(test_file) for name in csv_zip.namelist(): fw = open('sylva/sylva/tests/files/' + name, 'w') fw.write(csv_zip.read(name)) fw.close() for name in csv_zip.namelist(): f = open('sylva/sylva/tests/files/' + name) csvFile = "" for line in f: csvFile += line f.close() spin_assert(lambda: self.assertEqual(csv_zip.read(name), csvFile)) Graph.objects.get(name="Bob's graph").destroy()
# Mouse browser.find_by_tag('h1').mouse_over() browser.find_by_tag('h1').mouse_out() browser.find_by_tag('h1').click() browser.find_by_tag('h1').double_click() browser.find_by_tag('h1').right_click() # Mouse drag and drop draggable = browser.find_by_tag('h1') target = browser.find_by_css('.container') draggable.drag_and_drop(target) # Interacting with forms browser.fill('query', 'my name') browser.attach_file('file', '/path/to/file/somefile.jpg') browser.choose('some-radio', 'radio-value') browser.check('some-check') browser.uncheck('some-check') browser.select('uf', 'rj') # screenshot browser.driver.save_screenshot('your_screenshot.png') # 看不太懂 # trigger JavaScript events, like KeyDown or KeyUp, you can use the type method. browser.type('type', 'typing text') ''' If you pass the argument slowly=True to the type method you can interact with the page on every key pressed. Useful for ''' # testing field's auto completion (the browser will wait until next iteration to type the subsequent key). for key in browser.type('type', 'typing slowly', slowly=True): pass # make some assertion here with the key object :)
from splinter import Browser import time # NOT-1: tarayici olarak chrome'u kullanmak isterseniz # driver'i indirip path'inize eklemeniz gerekiyor; linki: # http://chromedriver.storage.googleapis.com/index.html # eger firefox kullanmak isterseniz tarayicinin yuklu olmasi yeterli # yalniz, bir defaliga mahsus bir ayar yapmaniz gerekiyor (bkz. NOT-2) browser = Browser('firefox') #Secim sonuclari sayfasi browser.visit("https://sonuc.ysk.gov.tr/module/GirisEkrani.jsf") #Browser tavsiye ekrani browser.find_by_name('closeMessageButton').click() #Yerel secimler 2014 browser.choose('j_id111:secimSorgulamaForm:j_id114:secimSecmeTable:1:secimId', 'true') browser.find_by_name('j_id111:secimSorgulamaForm:j_id141').first.click() # NOT-2: Eger tarayici olarak firefox'u secti isteniz tam bu asamada # herhangi bir ilcenin datasini manuel olarak indirmeye calisin # karsiniza cikan pencerede her zaman kaydet kutucugunu seciniz ! for il in range(0, 82): browser.select('j_id47:j_id48:j_id88:cmbIl', str(il)) time.sleep(2) # ilcelerin dolmasini bekle ilce_sayisi = len( browser.find_by_id("j_id47:j_id48:j_id100:cmbSecimCevresi").first. find_by_tag('option')) - 1 for i in range(0, ilce_sayisi): i = i + 1 #ilce indexi [1,ilce_sayisi] araliginda ilceler = browser.find_by_id("j_id47:j_id48:j_id100:cmbSecimCevresi"
class AutoElectBrowser(object): def __init__( self, username, password, course_code, which_class, elect_type='qx', course_type='bx', browser_type='chrome', delay=1, ): self.username = username self.password = password self.course_code = course_code self.which_class = which_class self.elect_type = elect_type self.course_type = course_type self.delay = delay self.browser = Browser(browser_type) self.class_info = [] print(type(self.browser)) def login(self): u"""手动输入验证码后登录,调用该函数将返回抢选界面(必修课选课)的browser对象""" self.browser.visit(website["login"]) self.browser.fill('user', self.username) self.browser.fill('pass', self.password) while self.browser.title != u'上海交通大学教学信息服务网-学生服务平台': time.sleep(0.1) print(self.browser.windows[0], self.browser.windows[1]) self.browser.windows[1].close() def elect_site(self): u"""从教学信息服务网主页面到选课页面""" self.browser.visit(website[self.elect_type]) self.browser.check('CheckBox1') self.browser.find_by_name('btnContinue').first.click() def jump_to_list(self): u"""从某种课程的列表跳转到指定种类的列表 course_type:'bx'必修,'rw'人文,'sk'社科,'zk'自科,'sx'数学与逻辑,'xx'限选,'rx'任选""" self.browser.visit(website[self.course_type]) try: if self.course_type == 'xx': self.browser.choose('gridModule$ctl02$radioButton', 'radioButton') if self.course_type == 'rw': self.browser.choose('gridGModule$ctl02$radioButton', 'radioButton') if self.course_type == 'sk': self.browser.choose('gridGModule$ctl03$radioButton', 'radioButton') if self.course_type == 'zk': self.browser.choose('gridGModule$ctl04$radioButton', 'radioButton') if self.course_type == 'sx': self.browser.choose('gridGModule$ctl05$radioButton', 'radioButton') if self.course_type == 'rx': pass except ValueError as e: print e def course_arrange(self): u"""从课程列表进入到选择教师列表""" browser = self.browser course_code = self.course_code while 1: try: browser.choose('myradiogroup', course_code) time.sleep(self.delay) # 0.6会出现刷新过于频繁 browser.find_by_value(u'课程安排').first.click() if browser.title == 'messagePage': browser.find_by_value(u'返回').first.click() print( u'-------刷新过于频繁' + time.strftime( '%H:%M:%S', time.localtime(time.time())) + '-------') time.sleep(1.2) else: break except StaleElementReferenceException as e: print(e) time.sleep(1) except WebDriverException as e: print(e) time.sleep(1) def check_is_empty(self): u"""若有多个班同时人数未满,将选择列表中第一个,并返回0 若所有班人数满,将返回-1""" browser = self.browser html = browser.html self.class_info = [] soup = BeautifulSoup(html) table = soup.find_all('table', class_='alltab')[0].table all_class = table.contents[1] all_class = all_class.contents[1:-1] for c in all_class: each_class_info = [] each_class = c.contents[1:-1] each_class_info.append( each_class[0].contents[1].contents[0].attrs['value']) each_class = each_class[1:] for ec in each_class: each_class_info.append(unicode(ec.string).strip()) self.class_info.append(each_class_info) for wc in self.which_class: if wc == each_class_info[3]: if each_class_info[11] == u'人数未满': self.browser.choose("myradiogroup", each_class_info[0]) return 0 return -1 def submit(self): self.press_button(u'选定此教师') self.press_button(u'选课提交') def return_page(self): self.press_button(u'返 回') def press_button(self, name): self.browser.find_by_value(name).first.click()
while True: line = motifs.readline().strip() if line == "": break if line.startswith(">") == False: s += " ".join(x for x in map(str, line.split())) + "\n" else: # print "Opening browser..." from splinter import Browser browser = Browser() browser.visit("http://meme.nbcr.net/meme/cgi-bin/tomtom.cgi") # print "Filling form..." browser.choose("motif_src", "matrix") browser.fill("matrix_data", s) browser.select("motif_db", 3) browser.find_by_name("search").click() while True: time.sleep(4) if browser.title.endswith("e"): break # print "Getting txt output..." u = browser.url browser.visit(u[:-10] + "tomtom.txt") page = browser.html browser.quit()
from splinter import Browser import time # NOT-1: tarayici olarak chrome'u kullanmak isterseniz # driver'i indirip path'inize eklemeniz gerekiyor; linki: # http://chromedriver.storage.googleapis.com/index.html # eger firefox kullanmak isterseniz tarayicinin yuklu olmasi yeterli # yalniz, bir defaliga mahsus bir ayar yapmaniz gerekiyor (bkz. NOT-2) browser = Browser('firefox') #Secim sonuclari sayfasi browser.visit("https://sonuc.ysk.gov.tr/module/GirisEkrani.jsf") #Browser tavsiye ekrani browser.find_by_name('closeMessageButton').click() #Yerel secimler 2014 browser.choose('j_id111:secimSorgulamaForm:j_id114:secimSecmeTable:1:secimId','true') browser.find_by_name('j_id111:secimSorgulamaForm:j_id141').first.click() # NOT-2: Eger tarayici olarak firefox'u secti isteniz tam bu asamada # herhangi bir ilcenin datasini manuel olarak indirmeye calisin # karsiniza cikan pencerede her zaman kaydet kutucugunu seciniz ! for il in range(0,82): browser.select('j_id47:j_id48:j_id88:cmbIl',str(il)) time.sleep(2) # ilcelerin dolmasini bekle ilce_sayisi = len(browser.find_by_id("j_id47:j_id48:j_id100:cmbSecimCevresi").first.find_by_tag('option'))-1 for i in range(0,ilce_sayisi): i = i + 1 #ilce indexi [1,ilce_sayisi] araliginda ilceler = browser.find_by_id("j_id47:j_id48:j_id100:cmbSecimCevresi").first.find_by_tag('option') browser.select('j_id47:j_id48:j_id100:cmbSecimCevresi',ilceler[i].value) time.sleep(2) #lutfen bekleyinizi bekle :S
def post_resume(login, passw, sity): sity = unicode(sity) browser = Browser(user_agent=useragent) browser.visit('http://hh.ru/auth/employer') browser.fill('username', login) browser.fill('password', passw) time.sleep(1) browser.find_by_xpath( '//*[starts-with(@class,"HH-SimpleValidation-Submit")]').first.click() time.sleep(3) #browser.click_link_by_href('hh.ru/employer/vacancy.do') #browser.visit('http://hh.ru/employer/vacancy.do') browser.find_by_xpath( '//*[starts-with(@href,"/employer/vacancy.do")]').first.click() time.sleep(3) try: browser.find_by_xpath( '//*[starts-with(@class,"newpopup__button")]').first.click() browser.find_by_xpath( '//*[starts-with(@class,"newpopup__closeable")]').first.click() except: pass v_name = u'Стажер-разработчик Python (OpenERP)' v_desc = u""" Обязанности: Программирование OpenERP Требования: Опыт работы с Python, Опыт работы с реляционными СУБД Условия: Удаленное обучение. Работа постоянная, удаленная, сдельная. Для стажера сумма вознаграждения по результатам собеседования.. Подробнее http://arterp.ru/vacancy-openerp-trainee/ """ browser.fill('name', v_name) browser.fill('areaName', sity) browser.choose('scheduleId', '3') browser.choose('employmentId', '1') browser.find_by_xpath( '//*[starts-with(@class,"b-forma-text")]').first.select("1") browser.find_by_id('HH-specializationChooser-checkbox_50').first.check() #Stage browser.find_by_id('HH-specializationChooser-checkbox_172').first.check() frame = browser.find_by_xpath( '//*[starts-with(@class,"jsxComponents-Editor-Frame")]')[0] print frame.value print frame['class']
def register(activity): username = '******' password = '******' browser = Browser('chrome', headless=True) # browse the warrior index page # browser.visit('https://warrior.uwaterloo.ca/') # browse Facility Access Reservation # browser.visit('https://warrior.uwaterloo.ca/Program/GetProducts?classification=01e6d66f-044b-42c0-9cc9-495c9586f4db') # Browse the Facility Access Reservation categories # browser.find_by_css('.Menu-Item').first.click() # browse activity page directly based on the activities if (activity == 'gym'): browser.visit('https://warrior.uwaterloo.ca/Program/GetProgramDetails?courseId=cc2a16d7-f148-461e-831d-7d4659726dd1&semesterId=b0d461c3-71ea-458e-b150-134678037221') if (activity == 'badminton'): browser.visit('https://warrior.uwaterloo.ca/Program/GetProgramDetails?courseId=5f834760-8c08-4eff-8d1d-fbe01dd538f6&semesterId=b0d461c3-71ea-458e-b150-134678037221') # Browse the CIF FITNESS CENTER program # dict = {'gym': 1, 'badminton': 2} # browser.find_by_css('.list-group-item')[dict[activity]].click() # Check login status if browser.is_element_present_by_text('Log In'): print("Login required!") browser.execute_script("showLogin();") # wait for dynamic content to load while not browser.find_by_id("modalLogin").first.visible: time.sleep(.1) browser.execute_script("showLocalLoginForm();") # Fill the username and password print("Filling in user info...") while not browser.find_by_name("Username").first.visible: time.sleep(.1) while(browser.find_by_name("Username").first.value == ''): browser.fill('Username', username) while(browser.find_by_name("Password").first.value == ''): browser.fill('Password', password) # Submit and login browser.execute_script("submitLogin();") # Wait for login process to finish, then reload print("Logging in...") while browser.is_element_present_by_id("modalLogin"): time.sleep(.1) print("Login Successful!") browser.reload() # Login before the hour in case there are other toolmen if (datetime.now().minute == 59): print("Toolman stand by...") while(datetime.now().minute != 0): time.sleep(1) browser.reload() # Register the latest reservation resv = browser.find_by_text("Register") resv.last.click() # Accept the waiver and checkout print("Signing the waiver...") while browser.is_text_not_present("ACCEPT NOW"): time.sleep(.1) browser.find_by_text("Accept Now").first.click() for i in range(1, 9): browser.choose('CustomPrompts[{}].CommonInput'.format(i), 'False') browser.find_by_text("Add to Cart").first.click() browser.execute_script("Submit();") print("Registerd!") return
secfirst = True for radiooption in profradiooptions: if secfirst: secfirst = False else: browser.select('selectlistLan', county) print "Current county: " + curcounty browser.select('selectlistKommun', municipality) print "Current municipality: " + curmunicipality browser.select('selectlistYrkesomrade', workarea) print "Current workarea: " + curworkarea browser.select('selectlistDelomrade', profession) print "Current profession: " + curprofession browser.find_by_name('cmdSearch').click() browser.choose('iYrkeBenamningID', radiooption) curdetailedprof = browser.find_by_value(radiooption).find_by_xpath('..').text print "Current detailed profession: " + curdetailedprof browser.find_by_name('cmdSearch').click() # Saving current options to an external file currentoptions = (county, municipality, workarea, profession, radiooption) with open('options.dump', 'wb+') as dmp: pickle.dump(currentoptions, dmp) # Saving entries
class DataNodeTestCase(LiveServerTestCase): """ A set of tests to test all interaction related to the creation and deletion of nodes and relationships. Also, we test export the data in two formats: gexf and csv. """ def setUp(self): self.browser = Browser() signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') def tearDown(self): logout(self) self.browser.quit() def test_data_node_addition(self): create_graph(self) create_schema(self) create_type(self) create_data(self) # Check the node name self.browser.find_by_xpath( "//td[@class='dataList']/a[@class='edit']").first.click() text = self.browser.find_by_id('propertiesTitle').first.value self.assertEqual(text, 'Properties') self.browser.find_by_xpath( "//span[@class='buttonLinkOption buttonLinkRight']/a").first.click( ) self.browser.choose('confirm', '1') self.browser.find_by_value('Continue').first.click() text = self.browser.find_by_xpath( "//div[@class='indent']/div").first.value Graph.objects.get(name="Bob's graph").destroy() self.assertEqual(text, 'Nodes: 0') def test_data_node_addition_rel_add_del(self): create_graph(self) create_schema(self) create_type(self) create_node(self, "Bob") create_node(self, "Alice") # We create a allowed relation js_code = "$('a#schema-link')[0].click();" self.browser.execute_script(js_code) self.browser.find_by_id('allowedRelations').first.click() self.browser.select('source', '1') self.browser.find_by_name('name').fill('Bob\'s rel') self.browser.select('target', '1') self.browser.find_by_id('id_description').fill( 'This the allowed relationship for Bob\'s graph') self.browser.find_by_value('Save Type').first.click() self.assertEqual(self.browser.title, "SylvaDB - Bob's graph") # We create the link between the nodes self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath( "//td[@class='dataActions']/a[@class='dataOption list']" ).first.click() self.browser.find_by_xpath( "//td[@class='dataList']/a[@class='edit']").first.click() self.browser.find_by_xpath( "//li[@class='token-input-input-token']/input").first.fill('Alice') self.browser.is_element_present_by_id("id_user_wait", 5) self.browser.find_by_xpath( "//div[@class='token-input-dropdown']//li[@class='token-input-dropdown-item2 token-input-selected-dropdown-item']/b" ).first.click() self.browser.find_by_value('Save Bob\'s type').first.click() self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() text = self.browser.find_by_xpath( "//div[@class='flags-block']/span[@class='graph-relationships']" ).first.value self.assertEqual(text, "1 relationships") # Delete the relationship self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath( "//td[@class='dataActions']/a[@class='dataOption list']" ).first.click() self.browser.find_by_xpath( "//td[@class='dataList']/a[@class='edit']").first.click() self.browser.find_by_xpath( "//span[@class='all-relationships incoming-relationships i_bobs_rel1-relationships']//a[@class='delete-row initial-form floating']" ).first.click() self.browser.find_by_value('Save Bob\'s type').first.click() self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() text = self.browser.find_by_xpath( "//div[@class='flags-block']/span[@class='graph-relationships']" ).first.value self.assertEqual(text, "0 relationships") Graph.objects.get(name="Bob's graph").destroy() def test_node_type_deletion_keeping_nodes(self): create_graph(self) create_schema(self) create_type(self) # Adding relationship to the type self.browser.find_by_id('allowedRelations').first.click() self.browser.select('source', '1') self.browser.find_by_name('name').fill("Bob's rel") self.browser.select('target', '1') self.browser.find_by_id('id_description').fill( 'The loved relationship') self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_xpath( "//div[@class='form-row indent']/label").first.value self.assertNotEqual(text.find("Bob's rel"), -1) # Creating nodes create_node(self, 'Bob') create_node(self, 'Alice') # Creating relationship between nodes self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath( "//td[@class='dataActions']/a[@class='dataOption list']" ).first.click() self.browser.find_by_xpath( "//td[@class='dataList']/a[@class='edit']").first.click() self.browser.find_by_xpath( "//li[@class='token-input-input-token']/input").first.fill('Alice') self.browser.is_element_present_by_id("id_user_wait", wait_time=5) self.browser.find_by_xpath( "//div[@class='token-input-dropdown']//li[@class='token-input-dropdown-item2 token-input-selected-dropdown-item']/b" ).first.click() self.browser.find_by_value('Save Bob\'s type').first.click() self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() text = self.browser.find_by_xpath( "//div[@class='flags-block']/span[@class='graph-relationships']" ).first.value self.assertEqual(text, "1 relationships") # Deleting type js_code = "$('a#schema-link')[0].click();" self.browser.execute_script(js_code) self.browser.find_by_xpath( "//fieldset[@class='module aligned wide model']/h2/a").first.click( ) self.browser.find_by_xpath( "//span[@class='buttonLinkOption buttonLinkRight']/a[@class='delete']" ).first.click() text = self.browser.find_by_xpath( "//p/label[@for='id_option_0']").first.value self.assertNotEqual(text.find("We found some elements of this type"), -1) # Keeping nodes self.browser.choose('option', 'no') self.browser.find_by_value('Continue').first.click() text = self.browser.find_by_xpath( "//div[@class='body-inside']/p").first.value self.assertEqual(text, 'There are no types defined yet.') # Checking self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() text = self.browser.find_by_xpath( "//div[@class='flags-block']/span[@class='graph-nodes']" ).first.value self.assertEqual(text, "2 nodes") text = self.browser.find_by_xpath( "//div[@class='flags-block']/span[@class='graph-relationships']" ).first.value self.assertEqual(text, "1 relationships") self.browser.is_element_present_by_id('wait_for_js', 3) js_code = ''' var instanceId = '0'; for (key in sigma.instances) { instanceId = key; break; } var instance = sigma.instances[instanceId]; sigma.test_node_count = instance.getNodesCount(); ''' self.browser.execute_script(js_code) text = self.browser.evaluate_script('sigma.test_node_count') self.assertEqual(text, 0) Graph.objects.get(name="Bob's graph").destroy() def test_node_type_deletion_deleting_nodes(self): create_graph(self) create_schema(self) create_type(self) # Adding relationship to the type self.browser.find_by_id('allowedRelations').first.click() self.browser.select('source', '1') self.browser.find_by_name('name').fill("Bob's rel") self.browser.select('target', '1') self.browser.find_by_id('id_description').fill( 'The loved relationship') self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_xpath( "//div[@class='form-row indent']/label").first.value self.assertNotEqual(text.find("Bob's rel"), -1) # Creating nodes create_node(self, 'Bob') create_node(self, 'Alice') # Creating relationship between nodes self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath( "//td[@class='dataActions']/a[@class='dataOption list']" ).first.click() self.browser.find_by_xpath( "//td[@class='dataList']/a[@class='edit']").first.click() self.browser.find_by_xpath( "//li[@class='token-input-input-token']/input").first.fill('Alice') self.browser.is_element_present_by_id("id_user_wait", wait_time=5) self.browser.find_by_xpath( "//div[@class='token-input-dropdown']//li[@class='token-input-dropdown-item2 token-input-selected-dropdown-item']/b" ).first.click() self.browser.find_by_value('Save Bob\'s type').first.click() self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() text = self.browser.find_by_xpath( "//div[@class='flags-block']/span[@class='graph-relationships']" ).first.value self.assertEqual(text, "1 relationships") # Deleting type js_code = "$('a#schema-link')[0].click();" self.browser.execute_script(js_code) self.browser.find_by_xpath( "//fieldset[@class='module aligned wide model']/h2/a").first.click( ) self.browser.find_by_xpath( "//span[@class='buttonLinkOption buttonLinkRight']/a[@class='delete']" ).first.click() text = self.browser.find_by_xpath( "//p/label[@for='id_option_0']").first.value self.assertNotEqual(text.find("We found some elements of this type"), -1) # Deleting nodes self.browser.choose('option', 'de') self.browser.find_by_value('Continue').first.click() text = self.browser.find_by_xpath( "//div[@class='body-inside']/p").first.value self.assertEqual(text, 'There are no types defined yet.') # Checking self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() text = self.browser.find_by_xpath( "//div[@class='flags-block']/span[@class='graph-nodes']" ).first.value self.assertEqual(text, "0 nodes") text = self.browser.find_by_xpath( "//div[@class='flags-block']/span[@class='graph-relationships']" ).first.value self.assertEqual(text, "0 relationships") Graph.objects.get(name="Bob's graph").destroy() def test_data_node_clone(self): create_graph(self) create_schema(self) create_type(self) create_data(self) original_name = self.browser.find_by_xpath( "//table[@id='content_table']/tbody/tr/td")[1].value # Clone the node self.browser.find_by_xpath( "//table[@id='content_table']/tbody/tr/td/a[@class='edit']" ).first.click() self.browser.find_by_name('Name').first.fill(original_name + " clone") self.browser.find_by_name("as-new").first.click() # Check that two nodes exist original_name = self.browser.find_by_xpath( "//table[@id='content_table']/tbody/tr/td")[1].value clone_name = self.browser.find_by_xpath( "//table[@id='content_table']/tbody/tr/td")[4].value self.assertEqual(original_name, "Bob's node") self.assertEqual(clone_name, "Bob's node clone") Graph.objects.get(name="Bob's graph").destroy() def test_sigma_visualization_in_node_view(self): create_graph(self) create_schema(self) create_type(self) # Adding relationship to the type self.browser.find_by_id('allowedRelations').first.click() self.browser.select('source', '1') self.browser.find_by_name('name').fill("Bob's rel") self.browser.select('target', '1') self.browser.find_by_id('id_description').fill( 'The loved relationship') self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_xpath( "//div[@class='form-row indent']/label").first.value self.assertNotEqual(text.find("Bob's rel"), -1) # Creating nodes create_node(self, 'Bob') create_node(self, 'Alice') # Creating relationship between nodes self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath( "//td[@class='dataActions']/a[@class='dataOption list']" ).first.click() self.browser.find_by_xpath( "//td[@class='dataList']/a[@class='edit']").first.click() self.browser.find_by_xpath( "//li[@class='token-input-input-token']/input").first.fill('Alice') self.browser.is_element_present_by_id("id_user_wait", wait_time=5) self.browser.find_by_xpath( "//div[@class='token-input-dropdown']//li[@class='token-input-dropdown-item2 token-input-selected-dropdown-item']/b" ).first.click() self.browser.find_by_value('Save Bob\'s type').first.click() # Checking self.browser.find_by_xpath( "//table[@id='content_table']/tbody/tr/td/p/a[@title='View node' and text()='Alice']" ).first.click() self.browser.is_element_present_by_id('wait_for_js', 3) js_code = ''' var instanceId = '0'; for (key in sigma.instances) { instanceId = key; break; } var instance = sigma.instances[instanceId]; sigma.test_node_count = instance.getNodesCount(); ''' self.browser.execute_script(js_code) text = self.browser.evaluate_script('sigma.test_node_count') self.assertEqual(text, 2) Graph.objects.get(name="Bob's graph").destroy() def test_graph_export_gexf(self): create_graph(self) create_schema(self) create_type(self) create_data(self) self.browser.find_by_id('toolsMenu').first.click() cookies = { self.browser.cookies.all()[0]["name"]: self.browser.cookies.all()[0]["value"], self.browser.cookies.all()[1]["name"]: self.browser.cookies.all()[1]["value"] } result = requests.get(self.live_server_url + '/tools/bobs-graph/export/gexf/', cookies=cookies) self.assertEqual(result.headers['content-type'], 'application/xml') self.assertEqual(self.browser.status_code.is_success(), True) fw = open('sylva/base/tests/files/bobs-graph.gexf', 'w') fw.write(result.content) fw.close() f = open('sylva/base/tests/files/bobs-graph.gexf') xmlFile = "" for line in f: xmlFile += line f.close() self.assertEqual(xmlFile, result.content) Graph.objects.get(name="Bob's graph").destroy() def test_graph_export_csv(self): create_graph(self) create_schema(self) create_type(self) create_data(self) self.browser.find_by_id('toolsMenu').first.click() cookies = { self.browser.cookies.all()[0]["name"]: self.browser.cookies.all()[0]["value"], self.browser.cookies.all()[1]["name"]: self.browser.cookies.all()[1]["value"] } result = requests.get(self.live_server_url + '/tools/bobs-graph/export/csv/', cookies=cookies) self.assertEqual(result.headers['content-type'], 'application/zip') self.assertEqual(self.browser.status_code.is_success(), True) test_file = StringIO(result.content) csv_zip = ZipFile(test_file) for name in csv_zip.namelist(): fw = open('sylva/base/tests/files/' + name, 'w') fw.write(csv_zip.read(name)) fw.close() for name in csv_zip.namelist(): f = open('sylva/base/tests/files/' + name) csvFile = "" for line in f: csvFile += line f.close() self.assertEqual(csv_zip.read(name), csvFile) Graph.objects.get(name="Bob's graph").destroy()
import os import sys import time import telepot import splinter import selenium import time #for checking runtime from bs4 import BeautifulSoup from splinter import Browser #geckodriver must be installed!!! browser = Browser('firefox') #start_time = time.time() with Browser() as browser: url = "https://wish.wis.ntu.edu.sg/webexe/owa/aus_schedule.main" browser.visit(url) browser.fill("r_subj_code", "CZ1005") browser.choose("r_search_type", "F") browser.find_by_value("Search").first.click() while len(browser.windows) > 0: for ii in browser.windows: if ii.url == "https://wish.wis.ntu.edu.sg/webexe/owa/AUS_SCHEDULE.main_display1": browser.windows.current = ii html_page = browser.html #print(html_page) soup = BeautifulSoup(html_page, 'html.parser') print(soup) ii.close()
class SchemaTestCase(LiveServerTestCase): """ A set of tests for testing export schema, import schema and everything related to advanced types (patterns, options, etc.). """ def setUp(self): self.browser = Browser() signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') def tearDown(self): logout(self) self.browser.quit() def test_export_schema(self): create_graph(self) create_schema(self) create_type(self) self.browser.find_by_id('toolsMenu').first.click() cookies = {self.browser.cookies.all()[0]["name"]: self.browser.cookies.all()[0]["value"], self.browser.cookies.all()[1]["name"]: self.browser.cookies.all()[1]["value"]} result = requests.get(self.live_server_url + '/schemas/bobs-graph/export/', cookies=cookies) self.assertEqual(result.headers['content-type'], 'application/json') self.assertEqual(self.browser.status_code.is_success(), True) f = open('sylva/base/tests/files/bobs-graph_schema.json') self.assertEqual(f.read().split("\n")[0], result.content) def test_import_schema(self): create_graph(self) create_schema(self) self.browser.find_by_id('schemaImport').first.click() file_path = os.path.join( os.path.abspath(os.path.dirname(__file__)), 'files/bobs-graph_schema.json' ) self.browser.attach_file('file', file_path) self.browser.find_by_value('Continue').first.click() self.assertEqual(self.browser.title, "SylvaDB - Bob's graph") text = self.browser.find_by_id('diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "Name") def test_new_type(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_xpath( "//div[@class='content2-first']/p/textarea[@name='description']").first.fill('The loved type') self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_xpath( "//div[@id='diagramBox_bobs-type']/div[@class='title']").first.value self.assertNotEqual(text.find("Bob's type"), -1) def test_new_advanced_type(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_name('properties-0-default').first.fill( "Bob's node default name") self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "Name") def test_new_advanced_type_string_empty(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('String name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Basic']/option[@value='s']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "String name") # Testing data self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath("//td[@class='dataActions']/a[@class='dataOption new']").first.click() self.browser.find_by_name('String name').first.fill('') self.browser.find_by_value("Save Bob's type").first.click() text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text self.assertEqual(text, 'This field is required.') Graph.objects.get(name="Bob's graph").destroy() def test_new_advanced_type_boolean(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Boolean name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Basic']/option[@value='b']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "Boolean name") def test_new_advanced_type_number(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Number name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Basic']/option[@value='n']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "Number name") def test_new_advanced_type_number_float(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Number name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Basic']/option[@value='n']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "Number name") # Testing data self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath("//td[@class='dataActions']/a[@class='dataOption new']").first.click() self.browser.find_by_name('Number name').first.fill('1.5') self.browser.find_by_value("Save Bob's type").first.click() text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text self.assertEqual(text, 'Enter a whole number.') Graph.objects.get(name="Bob's graph").destroy() def test_new_advanced_type_number_string(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Number name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Basic']/option[@value='n']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "Number name") # Testing data self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath("//td[@class='dataActions']/a[@class='dataOption new']").first.click() self.browser.find_by_name('Number name').first.fill('number') self.browser.find_by_value("Save Bob's type").first.click() text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text self.assertEqual(text, 'Enter a whole number.') Graph.objects.get(name="Bob's graph").destroy() def test_new_advanced_type_text(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Text name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='x']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "Text name") def test_new_advanced_type_date(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Date name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='d']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "Date name") def test_new_advanced_type_time(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Time name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='t']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "Time name") def test_new_advanced_type_time_string(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Time name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='t']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "Time name") # Testing data self.browser.find_by_id('dataMenu').first.click() self.browser.find_by_xpath("//td[@class='dataActions']/a[@class='dataOption new']").first.click() self.browser.find_by_name('Time name').first.fill('0123456789') self.browser.find_by_xpath("//button[@class='ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all']").first.click() self.browser.find_by_value("Save Bob's type").first.click() text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text self.assertEqual(text, 'Enter a valid time.') Graph.objects.get(name="Bob's graph").destroy() def test_new_advanced_type_choices(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('Choices name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='c']").first.click() self.browser.find_by_name('properties-0-default').first.fill('Bob, Alice') self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "Choices name") def test_new_advanced_type_float(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('float name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='f']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "float name") def test_new_advanced_type_collaborator(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('collaborator name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Advanced']/option[@value='r']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "collaborator name") def test_new_advanced_type_auto_now(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('auto now name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Auto']/option[@value='w']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "auto now name") def test_new_advanced_type_auto_now_add(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('auto now add name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Auto']/option[@value='a']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "auto now add name") def test_new_advanced_type_auto_increment(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('auto increment name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Auto']/option[@value='i']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "auto increment name") def test_new_advanced_type_auto_increment_update(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('auto increment update') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Auto']/option[@value='o']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "auto increment update") def test_new_advanced_type_auto_user(self): create_graph(self) create_schema(self) self.browser.find_link_by_href( '/schemas/bobs-graph/types/create/').first.click() text = self.browser.find_by_xpath( "//div[@class='content2-first']/h2").first.value self.assertEqual(text, 'Type') self.browser.find_by_name('name').first.fill("Bob's type") self.browser.find_by_id('advancedModeButton').first.click() self.browser.find_by_name('properties-0-key').first.fill('auto user name') self.browser.find_by_name('properties-0-display').first.check() self.browser.find_by_name('properties-0-required').first.check() self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Auto']/option[@value='e']").first.click() self.browser.find_by_name('properties-0-order').first.fill('1') self.browser.find_by_name('properties-0-description').first.fill( "The name of this Bob's node") self.browser.find_by_value('Save Type').first.click() text = self.browser.find_by_id( 'diagramBoxField_bobs-graph.bobs-type.undefined').first.value self.assertEqual(text, "auto user name") def test_schema_allowed_rel_addition(self): create_graph(self) self.assertEqual(self.browser.title, 'SylvaDB - Dashboard') create_schema(self) create_type(self) self.assertEqual(self.browser.title, "SylvaDB - Bob's graph") self.browser.find_by_id('allowedRelations').first.click() self.browser.select('source', '1') self.browser.find_by_name('name').fill('Bob\'s rel') self.browser.select('target', '1') self.browser.find_by_id('id_description').fill('This the allowed relationship for Bob\'s graph') self.browser.find_by_value('Save Type').first.click() self.assertEqual(self.browser.title, "SylvaDB - Bob's graph") text = self.browser.find_by_xpath( "//div[@class='form-row indent']/label").first.value self.assertNotEqual(text.find('Bob\'s rel'), -1) def test_schema_allowed_rel_addition_deletion(self): create_graph(self) self.assertEqual(self.browser.title, 'SylvaDB - Dashboard') create_schema(self) create_type(self) self.assertEqual(self.browser.title, "SylvaDB - Bob's graph") self.browser.find_by_id('allowedRelations').first.click() self.browser.select('source', '1') self.browser.find_by_name('name').fill('Bob\'s rel') self.browser.select('target', '1') self.browser.find_by_id('id_description').fill('This the allowed relationship for Bob\'s graph') self.browser.find_by_value('Save Type').first.click() self.assertEqual(self.browser.title, "SylvaDB - Bob's graph") text = self.browser.find_by_xpath( "//div[@class='form-row indent']/label").first.value self.assertNotEqual(text.find('Bob\'s rel'), -1) self.browser.find_by_xpath("//div[@class='form-row indent']/div[@class='form-row indent']/a").first.click() self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkRight']/a[@class='delete']").first.click() self.browser.choose('confirm', '1') self.browser.find_by_value('Continue').first.click() notExists = self.browser.is_element_not_present_by_xpath( "//div[@class='form-row indent']/label") self.assertEqual(notExists, True)
class CollaboratorTestCase(LiveServerTestCase): """ These tests check the permissions system creating two users: one creates a graph and gives permissions to the other, the other tests the permissions given. On these tests, is the developer who must keep the logic of the permissions. If he/she wants to give any permission to an user he/she must first creates the usar and then creates the collaboration adding the basic perrmission: 'chk_graph_view_graph'. The name of the tests self-explain the behaviour of them. """ def setUp(self): self.browser = Browser() def tearDown(self): logout(self) self.browser.quit() def test_graph_view_without_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) self.browser.find_by_xpath("//div[@class='dashboard-graphs']/div/div/span[@class='graph-title']/a").first.click() logout(self) signin(self, 'alice', 'alice_secret') self.browser.visit(self.live_server_url + '/graphs/bobs-graph/') text = self.browser.find_by_xpath( "//div[@class='heading']/h1").first.value self.assertNotEqual(text.find("403"), -1) Graph.objects.get(name="Bob's graph").destroy() def test_graph_view_with_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) self.browser.find_by_xpath("//div[@class='dashboard-graphs']/div/div/span[@class='graph-title']/a").first.click() add_permission(self, 'alice', CREATE_COLLAB) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() text = self.browser.find_by_xpath("//div[@class='graph-item']/span[@class='graph-title']/a").first.value self.assertEqual(text, "Bob's graph") Graph.objects.get(name="Bob's graph").destroy() def test_graph_change_without_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) self.browser.find_by_xpath("//div[@class='dashboard-graphs']/div/div/span[@class='graph-title']/a").first.click() add_permission(self, 'alice', CREATE_COLLAB) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath("//div[@class='graph-item']/span[@class='graph-title']/a").first.click() text = self.browser.find_by_xpath( "//div[@class='heading']/h1").first.value self.assertNotEqual(text.find("403"), -1) Graph.objects.get(name="Bob's graph").destroy() def test_graph_change_with_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) self.browser.find_by_xpath("//div[@class='dashboard-graphs']/div/div/span[@class='graph-title']/a").first.click() add_permission(self, 'alice', CREATE_COLLAB) add_permission(self, 'alice', GRAPH_CHANGE) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath("//div[@class='graph-item']/span[@class='graph-title']/a").first.click() self.browser.find_by_xpath( "//input[@id='id_name']").first.fill("Alice's graph") self.browser.find_by_xpath( "//form/input[@type='submit']").first.click() text = self.browser.find_by_xpath("//div[@class='graph-item']/span[@class='graph-title']/a").first.value self.assertEqual(text, "Alice's graph") Graph.objects.get(name="Alice's graph").destroy() def test_schema_view_without_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) create_schema(self) create_type(self) add_permission(self, 'alice', CREATE_COLLAB) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath( "//nav[@class='menu']/ul/li[3]/a").first.click() text = self.browser.find_by_xpath( "//div[@class='heading']/h1").first.value self.assertNotEqual(text.find("403"), -1) Graph.objects.get(name="Bob's graph").destroy() def test_schema_view_with_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) create_schema(self) create_type(self) add_permission(self, 'alice', CREATE_COLLAB) add_permission(self, 'alice', SCHEMA_VIEW) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath( "//nav[@class='menu']/ul/li[3]/a").first.click() text = self.browser.find_by_xpath( "//fieldset[@class='module aligned wide model']/h2/a").first.value self.assertEqual(text, "Bob's type") Graph.objects.get(name="Bob's graph").destroy() def test_schema_change_without_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) create_schema(self) create_type(self) add_permission(self, 'alice', CREATE_COLLAB) add_permission(self, 'alice', SCHEMA_VIEW) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath( "//nav[@class='menu']/ul/li[3]/a").first.click() self.browser.find_by_xpath("//fieldset[@class='module aligned wide model']/h2/a").first.click() text = self.browser.find_by_xpath( "//div[@class='heading']/h1").first.value self.assertNotEqual(text.find("403"), -1) Graph.objects.get(name="Bob's graph").destroy() def test_schema_change_with_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) create_schema(self) create_type(self) add_permission(self, 'alice', CREATE_COLLAB) add_permission(self, 'alice', SCHEMA_VIEW) add_permission(self, 'alice', SCHEMA_CHANGE) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath( "//nav[@class='menu']/ul/li[3]/a").first.click() self.browser.find_by_xpath("//fieldset[@class='module aligned wide model']/h2/a").first.click() self.browser.find_by_xpath( "//input[@id='id_name']").first.fill("Alice's type") self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkLeft']/input[@type='submit']").first.click() text = self.browser.find_by_xpath( "//fieldset[@class='module aligned wide model']/h2/a").first.value self.assertEqual(text, "Alice's type") Graph.objects.get(name="Bob's graph").destroy() def test_data_view_without_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) create_schema(self) create_type(self) create_data(self) add_permission(self, 'alice', CREATE_COLLAB) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath("//a[@id='dataMenu']").first.click() self.browser.find_by_xpath("//div[@id='dataBrowse']/table/tbody/tr/td/a[@class='dataOption list']").first.click() text = self.browser.find_by_xpath( "//div[@class='heading']/h1").first.value self.assertNotEqual(text.find("403"), -1) Graph.objects.get(name="Bob's graph").destroy() def test_data_view_with_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) create_schema(self) create_type(self) create_data(self) add_permission(self, 'alice', CREATE_COLLAB) add_permission(self, 'alice', DATA_VIEW) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath("//a[@id='dataMenu']").first.click() self.browser.find_by_xpath("//div[@id='dataBrowse']/table/tbody/tr/td/a[@class='dataOption list']").first.click() text = self.browser.find_by_xpath("//table[@id='content_table']/tbody/tr/td")[1].value self.assertEqual(text, "Bob's node") Graph.objects.get(name="Bob's graph").destroy() def test_data_change_without_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) create_schema(self) create_type(self) create_data(self) add_permission(self, 'alice', CREATE_COLLAB) add_permission(self, 'alice', DATA_VIEW) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath("//a[@id='dataMenu']").first.click() self.browser.find_by_xpath("//div[@id='dataBrowse']/table/tbody/tr/td/a[@class='dataOption list']").first.click() self.browser.find_by_xpath("//td/a[@title='Edit node']").first.click() text = self.browser.find_by_xpath( "//div[@class='heading']/h1").first.value self.assertNotEqual(text.find("403"), -1) Graph.objects.get(name="Bob's graph").destroy() def test_data_change_with_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) create_schema(self) create_type(self) create_data(self) add_permission(self, 'alice', CREATE_COLLAB) add_permission(self, 'alice', DATA_VIEW) add_permission(self, 'alice', DATA_CHANGE) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath("//a[@id='dataMenu']").first.click() self.browser.find_by_xpath("//div[@id='dataBrowse']/table/tbody/tr/td/a[@class='dataOption list']").first.click() self.browser.find_by_xpath("//td/a[@title='Edit node']").first.click() self.browser.find_by_xpath( "//input[@id='id_Name']").first.fill("Alice's node") self.browser.find_by_xpath("//input[@type='submit']").first.click() text = self.browser.find_by_xpath("//table[@id='content_table']/tbody/tr/td")[1].value self.assertEqual(text, "Alice's node") Graph.objects.get(name="Bob's graph").destroy() def test_data_add_without_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) create_schema(self) create_type(self) add_permission(self, 'alice', CREATE_COLLAB) add_permission(self, 'alice', DATA_VIEW) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath("//a[@id='dataMenu']").first.click() self.browser.find_by_xpath("//div[@id='dataBrowse']/table/tbody/tr/td/a[@class='dataOption new']").first.click() text = self.browser.find_by_xpath( "//div[@class='heading']/h1").first.value self.assertNotEqual(text.find("403"), -1) Graph.objects.get(name="Bob's graph").destroy() def test_data_add_with_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) create_schema(self) create_type(self) add_permission(self, 'alice', CREATE_COLLAB) add_permission(self, 'alice', DATA_VIEW) add_permission(self, 'alice', DATA_ADD) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath("//a[@id='dataMenu']").first.click() self.browser.find_by_xpath("//div[@id='dataBrowse']/table/tbody/tr/td/a[@class='dataOption new']").first.click() self.browser.find_by_xpath( "//input[@id='id_Name']").first.fill("Alice's node") self.browser.find_by_xpath("//input[@type='submit']").first.click() text = self.browser.find_by_xpath("//table[@id='content_table']/tbody/tr/td")[1].value self.assertEqual(text, "Alice's node") Graph.objects.get(name="Bob's graph").destroy() def test_data_delete_without_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) create_schema(self) create_type(self) create_data(self) add_permission(self, 'alice', CREATE_COLLAB) add_permission(self, 'alice', DATA_VIEW) add_permission(self, 'alice', DATA_CHANGE) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath("//a[@id='dataMenu']").first.click() self.browser.find_by_xpath("//div[@id='dataBrowse']/table/tbody/tr/td/a[@class='dataOption list']").first.click() self.browser.find_by_xpath("//td/a[@title='Edit node']").first.click() self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkRight']/a[text()='Remove']").first.click() text = self.browser.find_by_xpath( "//div[@class='heading']/h1").first.value self.assertNotEqual(text.find("403"), -1) Graph.objects.get(name="Bob's graph").destroy() def test_data_delete_with_permissions(self): signup(self, 'alice', '*****@*****.**', 'alice_secret') signin(self, 'alice', 'alice_secret') logout(self) signup(self, 'bob', '*****@*****.**', 'bob_secret') signin(self, 'bob', 'bob_secret') create_graph(self) create_schema(self) create_type(self) create_data(self) add_permission(self, 'alice', CREATE_COLLAB) add_permission(self, 'alice', DATA_VIEW) add_permission(self, 'alice', DATA_CHANGE) add_permission(self, 'alice', DATA_DELETE) logout(self) signin(self, 'alice', 'alice_secret') self.browser.find_link_by_href('/graphs/bobs-graph/').first.click() self.browser.find_by_xpath("//a[@id='dataMenu']").first.click() self.browser.find_by_xpath("//div[@id='dataBrowse']/table/tbody/tr/td/a[@class='dataOption list']").first.click() self.browser.find_by_xpath("//td/a[@title='Edit node']").first.click() self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkRight']/a[text()='Remove']").first.click() self.browser.choose('confirm', '1') self.browser.find_by_xpath("//input[@type='submit']").first.click() text = self.browser.find_by_xpath( "//div[@id='content2']/div[@class='indent']").first.value self.assertNotEqual(text.find('Nodes: 0'), -1) Graph.objects.get(name="Bob's graph").destroy()
def send(self): usrname, passwd = getLogin() if usrname == "failed": if passwd == "fileNotFound": self.report({ "ERROR" }, "you must enter your account in first. You can find them in the user preferences under the addon" ) return "CANCELLED" pjsname = "phantomjs-win.exe" pjspath = os.path.dirname(os.path.abspath(__file__)) + "\\" + pjsname browser = Browser("phantomjs", executable_path=pjspath, service_log_path=tempfile.gettempdir() + "\\l.log") browser.visit("https://www.sheepit-renderfarm.com/index.php") Button1 = browser.find_by_css("button.navbar-toggle") Button1.first.click() time.sleep(1) Button2 = browser.find_by_css("a.dropdown-toggle.dropdown-form-toggle") Button2.first.click() usernameField = browser.find_by_id("login-header_login") usernameField.type(usrname) passwordField = browser.find_by_id("login-header_password") passwordField.type(passwd) browser.screenshot(name="A", suffix='.png') signInButton = browser.find_by_id("login-header_submit") signInButton.click() time.sleep(1) browser.screenshot(name="B", suffix='.png') if browser.is_element_present_by_id("login_login"): self.report({ "ERROR" }, "Check your credentials. You can find them in the user preferences under the addon" ) return "CANCELLED" browser.visit("https://www.sheepit-renderfarm.com/jobs.php?mode=add") browser.screenshot(name="C", suffix='.png') if browser.is_element_present_by_text("Your current limit is 2 projects."): self.report({"ERROR"}, "You allready have 2 Projects") return "CANCELLED" browser.attach_file("addjob_archive", bpy.context.blend_data.filepath) browser.screenshot(name="C", suffix='.png') sendButton = browser.find_by_value("Send this file") sendButton.first.click() browser.screenshot(name="D", suffix='.png') exeVersion = browser.find_by_id("addjob_exe") exeVersion.first.select(bpy.context.scene.sheepIt.Version) renderableByAll = browser.find_by_name("public_render") if bpy.context.scene.sheepIt.Renderable_by_all_members: renderableByAll.check() else: renderableByAll.uncheck() browser.choose("addjob_change_type_0", bpy.context.scene.sheepIt.RenderMode) if bpy.context.scene.sheepIt.RenderMode == "singleframe": browser.execute_script("addjob_split_sample_range_value_0.value = " + str(bpy.context.scene.sheepIt.stillSplitting)) else: browser.execute_script( "addjob_split_animation_sample_range_value_0.value = " + str(bpy.context.scene.sheepIt.animationSplitting)) browser.screenshot(name="E", suffix='.png') okButton = browser.find_by_id("addjob_submit_0") okButton.first.click() time.sleep(2) browser.screenshot(name="F", suffix='.png') self.report({'INFO'}, "uploaded") browser.quit() return "FINISHED"
def get_flights(origin_airport_code, destination_airport_code, departure_date_str): browser = Browser('phantomjs') browser.visit('https://www.southwest.com/') booking_button = browser.find_by_id('booking-form--flight-tab')[0] booking_button.click() #if return_date: # browser.choose('twoWayTrip','true') #else: browser.choose('twoWayTrip', 'false') #departure_date_str = departure_date.strftime("%m/%d/%y") # works better with the date selected first... no idea why. browser.execute_script( "document.getElementsByName('outboundDateString')[0].type = 'visible'") time.sleep(2) browser.fill('originAirport', origin_airport_code) browser.fill('destinationAirport', destination_airport_code) browser.execute_script( "document.getElementsByName('outboundDateString')[0].type = 'visible'") browser.fill('outboundDateString', departure_date_str) submit_button = browser.find_by_id('jb-booking-form-submit-button')[0] submit_button.click() flights_DOM_table = browser.find_by_css('.bugTableRow') flights_table = [] for flight_DOM in flights_DOM_table: depart_time = flight_DOM.find_by_css('.depart_column .time').text depart_time = depart_time.zfill(5) depart_am_pm = flight_DOM.find_by_css('.depart_column .indicator').text duration = parse_duration(flight_DOM.find_by_css('.duration').text) depart_str = departure_date_str + ", " + depart_time + depart_am_pm departure = datetime.datetime.strptime(depart_str, "%m/%d/%y, %I:%M%p") arrival = departure + duration #arrive_time = flight_DOM.find_by_css('.arrive_column .time').text #arrive_am_pm = flight_DOM.find_by_css('.arrive_column .indicator').text flight_nums = flight_DOM.find_by_css( '.bugLinkText') # could be a few of these f = [] for num in flight_nums: f.append(num.text[0:-14]) routing = flight_DOM.find_by_css('.bugLinkRouting').text[0:-14] if len(f) > 1: routing += " - " + flight_DOM.find_by_css( '.search-results--flight-stops').text box = flight_DOM.find_by_css('.price_column')[ 2] # only the wanna get away #check if sold out, unavailable or available price = None try: price = box.find_by_css('label.product_price')[0].text[ 1:] #strips the currency symbol except splinter.exceptions.ElementDoesNotExist: pass try: price = box.find_by_css('.insufficientInventory')[0].text.strip() except splinter.exceptions.ElementDoesNotExist: pass try: price = box.find_by_css('.unqualifiedForAnyFare')[0].text.strip() except: pass flight = (origin_airport_code, destination_airport_code, departure, arrival, tuple(f), routing, price) flights_table.append(flight) return flights_table
def get_flights(origin_airport_code, destination_airport_code, departure_date_str): browser = Browser('phantomjs') browser.visit('https://www.southwest.com/') booking_button = browser.find_by_id('booking-form--flight-tab')[0] booking_button.click() #if return_date: # browser.choose('twoWayTrip','true') #else: browser.choose('twoWayTrip','false') #departure_date_str = departure_date.strftime("%m/%d/%y") # works better with the date selected first... no idea why. browser.execute_script("document.getElementsByName('outboundDateString')[0].type = 'visible'") time.sleep(2) browser.fill('originAirport', origin_airport_code) browser.fill('destinationAirport', destination_airport_code) browser.execute_script("document.getElementsByName('outboundDateString')[0].type = 'visible'") browser.fill('outboundDateString', departure_date_str) submit_button = browser.find_by_id('jb-booking-form-submit-button')[0] submit_button.click() flights_DOM_table = browser.find_by_css('.bugTableRow') flights_table = [] for flight_DOM in flights_DOM_table: depart_time = flight_DOM.find_by_css('.depart_column .time').text depart_time = depart_time.zfill(5) depart_am_pm = flight_DOM.find_by_css('.depart_column .indicator').text duration = parse_duration(flight_DOM.find_by_css('.duration').text) depart_str = departure_date_str + ", " + depart_time + depart_am_pm departure = datetime.datetime.strptime(depart_str, "%m/%d/%y, %I:%M%p") arrival = departure + duration #arrive_time = flight_DOM.find_by_css('.arrive_column .time').text #arrive_am_pm = flight_DOM.find_by_css('.arrive_column .indicator').text flight_nums = flight_DOM.find_by_css('.bugLinkText') # could be a few of these f = [] for num in flight_nums: f.append(num.text[0:-14]) routing = flight_DOM.find_by_css('.bugLinkRouting').text[0:-14] if len(f) > 1: routing += " - " + flight_DOM.find_by_css('.search-results--flight-stops').text box = flight_DOM.find_by_css('.price_column')[2] # only the wanna get away #check if sold out, unavailable or available price = None try: price = box.find_by_css('label.product_price')[0].text[1:] #strips the currency symbol except splinter.exceptions.ElementDoesNotExist: pass try: price = box.find_by_css('.insufficientInventory')[0].text.strip() except splinter.exceptions.ElementDoesNotExist: pass try: price = box.find_by_css('.unqualifiedForAnyFare')[0].text.strip() except: pass flight = (origin_airport_code, destination_airport_code, departure, arrival, tuple(f), routing, price) flights_table.append(flight) return flights_table