Exemple #1
0
def splinter(url):
    browser = Browser()
    # login 126 email websize
    browser.visit(url)
    time.sleep(1)
    browser.find_by_id("text").fill(text)
    browser.find_by_id("go").click()
    time.sleep(1)
    # print browser.find_by_id('download-png')
    browser.find_by_id("download-png").click()
    browser.attach_file("transparent shrinkToFit", "C:\\somefile.jpg")

    time.sleep(1)
Exemple #2
0
def configWattbox(panel, ip, passwordTested):
    # Get wattbox SN
    ip = ip.strip()
    url = 'http://' + ip + '/wattbox_info.xml'
    if passwordTested is False:
        with requests.session() as sessionID:
            r = sessionID.get(url, auth=('wattbox', 'wattbox'))
            r = ElementTree.fromstring(r.content)
            panel.wattSN = r.findtext('serial_number')
            dir_path = os.path.dirname(os.path.realpath(__file__))

            browser = Browser('chrome', headless=True)
            browser.visit('http://*****:*****@' + ip + '/save_restore.htm')
            try:
                browser.attach_file(
                    'settings_file',
                    dir_path + '/WattBox/' + panel.ssid + '.cfg')
            except splinter.exceptions.ElementDoesNotExist:
                browser.quit()
                raise splinter.exceptions.ElementDoesNotExist
            browser.find_by_value('Restore').first.click()
            browser.quit()

    elif passwordTested is True:
        with requests.session() as sessionID:
            r = sessionID.get(url, auth=('admin', panel.sitePassword))
            r = ElementTree.fromstring(r.content)
            panel.wattSN = r.findtext('serial_number')
            dir_path = os.path.dirname(os.path.realpath(__file__))

            browser = Browser('chrome', headless=True)
            browser.visit('http://*****:*****@' + ip +
                          '/save_restore.htm')
            try:
                browser.attach_file(
                    'settings_file',
                    dir_path + '/WattBox/' + panel.ssid + '.cfg')
            except splinter.exceptions.ElementDoesNotExist:
                browser.quit()
                raise splinter.exceptions.ElementDoesNotExist
            browser.find_by_value('Restore').first.click()
            browser.quit()
    else:
        with requests.session() as sessionID:
            r = sessionID.get(url, auth=('admin', passwordTested))
            r = ElementTree.fromstring(r.content)
            panel.wattSN = r.findtext('serial_number')
            dir_path = os.path.dirname(os.path.realpath(__file__))

            browser = Browser('chrome', headless=True)
            browser.visit('http://*****:*****@' + ip +
                          '/save_restore.htm')
            try:
                browser.attach_file(
                    'settings_file',
                    dir_path + '/WattBox/' + panel.ssid + '.cfg')
            except splinter.exceptions.ElementDoesNotExist:
                browser.quit()
                raise splinter.exceptions.ElementDoesNotExist
            browser.find_by_value('Restore').first.click()
            browser.quit()

    return panel
Exemple #3
0
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))
Exemple #4
0
def add_album_to_rym(args, config_file):
    br = Browser()

    br.visit('https://rateyourmusic.com/account/login')
    time.sleep(3)

    # Login
    br.fill('username', credentials.username)
    br.fill('password', credentials.password)
    br.find_by_id('login_submit').click()
    time.sleep(5)

    (title, artist, tracklist, release,
     cover) = config.read_config(config_file)
    """
    if args.update_album:

        br.visit(args.rym_album)

    else:
    """

    if args.add_artist:
        br.visit('https://rateyourmusic.com/artist_add')

        #br.fill('lastname', unicode(artist))
        br.fill('lastname', artist)
        br.fill('comments', args.url)

        br.find_by_id('submitbtn').click()

        time.sleep(3)

        br.find_by_text(artist).click()

    else:
        br.visit(args.rym_profile)

    time.sleep(3)

    br.click_link_by_partial_href('/releases/ac?artist_id=')

    # Add data
    #br.fill('title', unicode(title))
    br.fill('title', title)

    br.find_by_id('format58').click()

    br.find_by_id('goAdvancedBtn').click()
    tracks_div = br.find_by_id('tracks_adv')
    tracks_text_area = tracks_div.find_by_id('track_advanced')
    #tracks_text_area.fill(unicode(tracklist))
    tracks_text_area.fill(tracklist)
    br.find_by_id('goSimpleBtn').click()

    br.fill('notes', args.url)

    (year, month, day) = parse_release_date(release)

    release_month_selector = br.find_by_id('month')
    release_month_selector.select(month)

    release_day_selector = br.find_by_id('day')
    release_day_selector.select(day)

    release_year_selector = br.find_by_id('year')
    release_year_selector.select(year)

    br.find_by_id('previewbtn').click()
    br.find_by_id('submitbtn').click()

    # Add cover art
    """
    coverart_img_element = br.find_by_xpath("//img[@class='coverart_img']")
    print(coverart_im_element)
    sys.exit(0)
    """

    br.click_link_by_partial_href('/images/upload?type=l&assoc_id=')
    br.attach_file('upload_file', cover)

    br.fill('source', args.url)
    br.find_by_id('uploadbutton').click()
    time.sleep(5)

    br.click_link_by_partial_href('javascript:setStatus')

    # Vote for genre
    br.click_link_by_partial_href('/release/')
    time.sleep(3)

    br.click_link_by_partial_href('/rgenre/set?')

    prigen_text_area = br.find_by_xpath("//input[@id='prigen']")
    prigen_text_area.fill('vaporwave')

    prigen_vote_button = br.find_by_xpath("//input[@value='+ propose']").first
    prigen_vote_button.click()

    # Done
    br.click_link_by_partial_href('/release/')
    print("Finished")
browser.find_link_by_text('my link').first.click()

# 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):
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"
Exemple #7
0
class WebSiteIntegrationTests(StaticLiveServerTestCase):
    """Integration test suite for testing the HandClassifier Site

    Test that the view from the classifier works as expected.
    This means it should receive only a certain type of image and that it actually
    classifies and gives a result.
    """
    def setUp(self):
        """Initialize the browser and visit the app url

        """
        self.browser = Browser('chrome')
        self.browser.visit(self.live_server_url + reverse('classifier_upload'))

    def tearDown(self):
        """At the end of tests, close the browser.

        """
        self.browser.quit()

    def test_main_page(self):
        """Test for url with name 'classifier_upload'

        Check it actually renders what is expected from this template
        """
        test_text = 'Clasificación de Imágenes: Lenguaje de Señas Mexicano'
        self.assertTrue(self.browser.is_text_present(test_text))

    def test_main_button(self):
        """ Test for url with name 'classifier_upload'

        Check if the url is accesible and check the buttons are showing correctly
        """
        self.assertTrue(self.browser.is_text_present('SELECCIONAR IMAGEN'))
        self.assertTrue(self.browser.is_text_present('CLASIFICAR'))

    def test_accurate_classification(self):
        """ Test for url with name 'classifier_upload'

        Check that the prediction is the desired
        Check that the model is accurate
        """
        cwd = os.getcwd()
        self.browser.attach_file('hand_img', cwd + '/test_images/a/0.png')
        time.sleep(2)
        self.browser.find_by_id('guardar').click()
        self.assertTrue(self.browser.is_text_present('Resultado: a'))

    def test_invalid_image(self):
        """ Test for url with name 'classifier_upload'

        Check that any invalid image is getting an error
        """
        cwd = os.getcwd()
        self.assertFalse(self.browser.is_text_present('Error:'))
        self.browser.attach_file('hand_img', cwd + '/test_images/invalid.png')
        time.sleep(2)
        self.browser.find_by_id('guardar').click()
        self.assertTrue(self.browser.is_text_present('Error:'))

    def test_no_image(self):
        """ Test for url with name 'classifier_upload'

        Check that if no image is uploaded it returns the error.
        """
        self.assertFalse(self.browser.is_text_present('Error:'))
        self.browser.find_by_id('guardar').click()
        self.assertTrue(self.browser.is_text_present('Error:'))

    def test_image_upload(self):
        """ Test for url with name 'classifier_upload'

        Check the image is shown inmediately after being selected.
        """
        cwd = os.getcwd()
        img = self.browser.find_by_id('imageTemp1')
        self.browser.attach_file('hand_img', cwd + '/test_images/a/0.png')
        time.sleep(2)
        img = self.browser.find_by_id('imageTemp1')
        # Check if the content is the recently loaded
        self.assertTrue('data:' in img['src'])
Exemple #8
0
class SplinterBrowserDriver(BaseBrowserDriver):
    """
        This is a BrowserDriver for splinter
        (http://splinter.cobrateam.info)
        that implements the BaseBrowserDriver API.

        To use it, you must have splinter installed on your env.

        For itself it's a browser driver that supports multiple browsing
        technologies such as selenium, phantomjs, zope, etc.
    """

    driver_name = 'splinter'

    def __init__(self):
        super(SplinterBrowserDriver, self).__init__()
        if not splinter_available:
            raise ImportError(
                "In order to use splinter Base Driver you have to install it. "
                "Check the instructions at http://splinter.cobrateam.info")
        self._browser = Browser(config.default_browser)

    def _handle_empty_element_action(self, element):
        if not element:
            raise ActionNotPerformableException(
                "The action couldn't be perfomed because the element couldn't "
                "be found; Try checking if your element"
                "selector is correct and if the page is loaded properly.")

    @property
    def page_url(self):
        return self._browser.url

    @property
    def page_source(self):
        return self._browser.html

    @property
    def page_title(self):
        return self._browser.title

    def open_url(self, url):
        self._browser.driver.get(url)

    def quit(self):
        return self._browser.quit()

    def is_element_visible(self, element):
        return element.visible

    def get_element_text(self, element):
        return element.text

    def get_element_by_xpath(self, selector):
        return self._browser.find_by_xpath(selector)

    def get_element_by_css(self, selector):
        return self._browser.find_by_css(selector)

    def get_element_by_id(self, selector):
        return self._browser.find_by_id(selector)

    def get_element_by_tag(self, selector):
        return self._browser.find_by_tag(selector)

    @element_action
    def type(self, element, text, slowly=False):
        return element.type(text, slowly)

    @element_action
    def fill(self, element, text):
      return element.fill(text)

    @element_action
    def clear(self, element):
      self.fill(element, '')

    @element_action
    def click(self, element):
        return element.click()

    @element_action
    def check(self, element):
        return element.check()

    @element_action
    def uncheck(self, element):
        return element.uncheck()

    @element_action
    def mouse_over(self, element):
        return element.mouse_over()

    @element_action
    def mouse_out(self, element):
        return element.mouse_out()

    def reload(self):
        return self._browser.reload()

    def go_back(self):
        return self._browser.back()

    def go_forward(self):
        return self._browser.forward()

    def execute_script(self, script):
        return self._browser.evaluate_script(script)

    def get_iframe(self, iframe_id):
        return self._browser.get_iframe(iframe_id)

    def get_alert(self):
        return self._browser.get_alert()

    def attach_file(self, input_name, file_path):
        return self._browser.attach_file(input_name, file_path)

    def wait_pageload(self, timeout=30):
        wait_interval = 0.05
        elapsed = 0

        while self.execute_script('document.readyState') != 'complete':
            self.wait(wait_interval)
            elapsed += wait_interval

            if elapsed > timeout:
                raise PageNotLoadedException

    def click_and_wait(self, element, timeout=30):
        self.click(element)
        self.wait_pageload(timeout)
Exemple #9
0
class ToolsTestCaseCsv(LiveServerTestCase):
    """
    A master test to check the behaviour of the new 'auto' fields.
    Actually only works with gephi format.
    """

    def setUp(self):
        self.browser = Browser()
        socket.setdefaulttimeout(30)
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.firstGraphName = "bobgraph"
        self.secondGraphName = "alicegraph"

    def tearDown(self):
        logout(self)
        self.browser.quit()

    @classmethod
    def tearDownClass(cls):
        sleep(10)  # It needs some time for close the LiverServerTestCase
        super(ToolsTestCaseCsv, cls).tearDownClass()

    def test_graph_export_csv(self):
        # Create a graph with a auto_user property
        create_graph(self, self.firstGraphName)
        create_advanced_schema(self, self.firstGraphName)
        create_advanced_type(self, self.firstGraphName, "e")
        create_advanced_data(self)
        # Create new graph for import the data
        import_advanced_schema_csv(self, self.firstGraphName, self.secondGraphName)
        # Data import
        self.browser.find_by_id('toolsMenu').first.click()
        self.browser.find_link_by_href('/tools/' + self.secondGraphName + '/import/').first.click()
        self.browser.find_by_id('csv-radio').first.click()
        # Change the display field of input to attach the file
        script = """
            $('#files').css('display', '');
            """
        self.browser.execute_script(script)
        self.browser.is_text_present('Drop your nodes files here', wait_time=10)
        # Import the nodes
        file_path = os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
            'files/csv/bobs-type.csv'
        )
        self.browser.attach_file('file', file_path)
        self.browser.is_text_present('Nodes files loaded. Loading edges files...', wait_time=10)
        # Wait until the data is imported
        self.browser.is_text_present('Now drop your edges files', wait_time=10)
        # Change the display field of input to attach the file
        script = """
            $('#files2').css('display', '');
            """
        self.browser.execute_script(script)
        # Import the relationships
        file_path = os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
            'files/csv/bobs-rels.csv'
        )
        self.browser.attach_file('file2', file_path)
        self.browser.is_text_present('Data loaded. Uploading to the server...', wait_time=10)
        # Wait until the data is imported
        self.browser.is_text_present('Data uploaded.', wait_time=10)
        # Check that nodes and relationships are ok
        self.browser.find_by_id('dataMenu').first.click()
        self.browser.find_by_xpath("//a[@class='dataOption list']").first.click()
        alicegraph = Graph.objects.get(name=self.secondGraphName)
        alicegraphNodes = alicegraph.nodes.count()
        spin_assert(lambda: self.assertEqual(3, alicegraph.nodes.count()))
        spin_assert(lambda: self.assertEqual(
            1, alicegraph.relationships.count()))
        # Add new nodes and relationships and check all is correct
        self.browser.find_by_id('dataMenu').first.click()
        self.browser.find_by_xpath(
            "//a[@class='dataOption new']").first.click()
        text = self.browser.find_by_id('propertiesTitle').first.value
        spin_assert(lambda: self.assertEqual(text, 'Properties'))
        self.browser.find_by_value("Save Bob's type").first.click()
        text = self.browser.find_by_xpath("//div[@class='pagination']/span[@class='pagination-info']").first.value
        spin_assert(lambda: self.assertNotEqual(
            text.find(" elements Bob's type."), -1))
        spin_assert(lambda: self.assertEqual(
            alicegraphNodes + 1, alicegraph.nodes.count()))
        # Destroy the databases
        Graph.objects.get(name=self.firstGraphName).destroy()
        Graph.objects.get(name=self.secondGraphName).destroy()
Exemple #10
0
class Brain1(MegaBrainTools):
    def __init__(self, account):

        if account == '':
            ####?
            self.gender = 'MALE'
            self.inn = invents()

            self.invent_user()

        #if account=='FEMALE':
        #	self.inn=invents()
        #	self.invent_user()

        else:
            self.account = account
            self.read_data()
            self.inn = invents()

        self.browser = Browser('firefox', profile_preferences=proxy_settings)

    def twitter_purge_about(self):
        self.browser.visit('https://mobile.twitter.com/settings/profile')
        time.sleep(3)
        self.browser.find_by_name('settings[description]').last.fill('')
        time.sleep(3)
        self.browser.find_by_name('commit').last.click()

    def twitter_change_login(self):
        self.browser.visit('https://mobile.twitter.com/settings/screen_name')
        self.browser.find_by_name('settings[screen_name]').last.fill(
            self.login)
        self.browser.find_by_name('settings[password]').last.fill(
            self.password)
        time.sleep(3)
        self.browser.find_by_name('commit').last.click()

    def twitter_login(self):
        print 'Login user %s' % self.login

        self.browser.visit('https://mobile.twitter.com/session/new')

        if hasattr(self, 'temp_pass'):
            passwd = self.temp_pass
        else:
            passwd = self.password
        login = self.twitter_phone

        print 'User login %s' % login
        print 'User password %s' % passwd

        if self.browser.url != 'https://mobile.twitter.com/':
            self.browser.find_by_name('session[username_or_email]').last.fill(
                login)
            self.browser.find_by_name('session[password]').last.fill(passwd)
            self.browser.find_by_xpath('//button[@type="submit"]').click()
            time.sleep(5)

        if '/login/error?' in self.browser.url:
            print 'Error Login in Twitter for User %s' % self.login
            return False

        if hasattr(self, 'temp_pass'):
            print self.login
            print self.temp_pass
            print self.password

            self.browser.visit('https://mobile.twitter.com/settings/password')

            self.browser.find_by_name('settings[current_password]').last.fill(
                self.temp_pass)
            time.sleep(3)
            self.browser.find_by_name('settings[password]').last.fill(
                self.password)
            time.sleep(3)
            self.browser.find_by_name(
                'settings[password_confirmation]').last.fill(self.password)
            time.sleep(3)
            self.browser.find_by_name('commit').last.click()
            time.sleep(5)
            print 'First login for account %s done. Save to storage' % self.login

            del self.temp_pass
            self.dump_to_xml()

            self.twitter_login()
            self.twitter_change_login()

            self.twitter_profile()
        return True

    def twitter_logout(self):
        self.browser.visit('https://mobile.twitter.com/account')
        self.browser.find_by_xpath('//input[@value="Log out"]').click()

    def twitter_compose(self, mess):

        self.browser.visit('https://mobile.twitter.com/compose/tweet')
        self.browser.find_by_name(
            '//textarea[@class="tweet-box-textarea userselect"]').last.fill(
                mess)
        self.browser.find_by_xpath(
            '//a[@class="tweet-button button disabled"]').click()

    def twitter_read_account(self, account):

        print 'https://twitter.com/%s' % account
        self.browser.visit('https://twitter.com/%s' % account)
        button = self.browser.find_by_xpath(
            '//button[@class="user-actions-follow-button js-follow-btn follow-button btn"]'
        )

        if button.text in ['Follow', u'Читать']:
            button.click()
        else:
            print 'May be already read Unwrong button value- %s' % button.text

        time.sleep(5)

    def twitter_stop(self):
        val = raw_input("Stop Was Here")

    def twitter_check(self):
        pass

    def twitter_retweet(self, mess_id):

        self.browser.visit('https://mobile.twitter.com/statuses/%s/retweet' %
                           mess_id)

        if not self.browser.is_element_not_present_by_xpath(
                "//form[@action='/statuses/%s/retweet']//input[@name='commit']"
                % mess_id):
            self.browser.find_by_xpath(
                "//form[@action='/statuses/%s/retweet']//input[@name='commit']"
                % mess_id).last.click()
        else:
            print 'Element for read don found. May be already retweet'

    def twitter_profile(self):
        print self.photo_path

        if not os.path.exists(self.photo_path):
            print 'Error get file %s' % self.photo_path

        self.browser.visit('https://twitter.com/%s' % self.login)
        self.browser.find_by_xpath(
            "//button[contains(@class,'UserActions-editButton edit-button btn')]"
        ).click()
        time.sleep(1)

        self.browser.find_by_xpath(
            xpath=
            '//div[@class="ProfileCanopy-avatar"]//button[@class="ProfileAvatarEditing-button u-boxShadowInsetUserColorHover"]'
        ).click()
        time.sleep(1)
        self.browser.attach_file('media[]', self.photo_path)
        time.sleep(1)

        self.browser.find_by_xpath(
            xpath=
            '//div[@id="profile_image_upload_dialog"]//button[@class="btn primary-btn profile-image-save"]'
        ).click()
        time.sleep(1)

        #self.browser.find_by_xpath(xpath='//div[@class="Grid-cell"]//button[@id="js-userColorButton"]').click()
        #colours=['0000FF','2E2B57','008b45','ff0000','6633FF','3300CC','3300FF','6600CC','006633','FF6600']
        #self.browser.find_by_xpath(xpath='//div[@class="ColorPicker dropdown-menu"]//input[@class="ColorPicker-hexInput"]').fill(random.choice(colours))

        self.browser.visit('https://mobile.twitter.com/settings/profile')
        time.sleep(3)
        self.browser.find_by_name('settings[fullname]').last.fill(
            self.first_last_name)
        time.sleep(3)
        self.browser.find_by_name('settings[location]').last.fill(self.city)
        time.sleep(3)
        #self.browser.find_by_name('settings[description]').last.fill(self.inn.get_citation())

        self.browser.find_by_name('commit').last.click()

        self.browser.visit('https://mobile.twitter.com/settings/email')
        time.sleep(3)
        self.browser.find_by_name('settings[email]').last.fill(self.email)
        time.sleep(3)
        self.browser.find_by_name('settings[password]').last.fill(
            self.password)
        time.sleep(3)
        #self.browser.find_by_name('settings[description]').last.fill(self.inn.get_citation())

        self.browser.find_by_name('commit').last.click()
Exemple #11
0
class UserTestCase(LiveServerTestCase):
    """
    A set of tests for testing Users, Accounts and UserProfiles. Also, we
    check the patterns for the required fields for signup, signin, the menu of
    user details, the change password view and the change email view.
    """
    def setUp(self):
        self.browser = Browser()

    def tearDown(self):
        self.browser.quit()

    def test_user_signup(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        self.assertEqual(
            self.browser.find_by_css('.body-inside').first.value,
            'Thank you for signing up with us!\nYou can now use the supplied credentials to signin.'
        )
        self.assertEqual(self.browser.title, 'SylvaDB - Signup almost done!')

    def test_user_singup_empty_email(self):
        self.browser.visit(self.live_server_url + '/accounts/signup/')
        self.browser.find_by_name('username').fill('bob')
        self.browser.find_by_name('email').fill('')
        self.browser.find_by_name('password1').fill('bob_secret')
        self.browser.find_by_name('password2').fill('bob_secret')
        self.browser.find_by_value('Signup').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')

    def test_user_singup_bad_email(self):
        self.browser.visit(self.live_server_url + '/accounts/signup/')
        self.browser.find_by_name('username').fill('bob')
        self.browser.find_by_name('email').fill('bobcultureplex.ca')
        self.browser.find_by_name('password1').fill('bob_secret')
        self.browser.find_by_name('password2').fill('bob_secret')
        self.browser.find_by_value('Signup').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Enter a valid e-mail address.')

    def test_user_singup_empty_name(self):
        self.browser.visit(self.live_server_url + '/accounts/signup/')
        self.browser.find_by_name('username').fill('')
        self.browser.find_by_name('email').fill('*****@*****.**')
        self.browser.find_by_name('password1').fill('bob_secret')
        self.browser.find_by_name('password2').fill('bob_secret')
        self.browser.find_by_value('Signup').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')

    def test_user_singup_empty_password(self):
        self.browser.visit(self.live_server_url + '/accounts/signup/')
        self.browser.find_by_name('username').fill('bob')
        self.browser.find_by_name('email').fill('*****@*****.**')
        self.browser.find_by_name('password1').fill('')
        self.browser.find_by_name('password2').fill('bob_secret')
        self.browser.find_by_value('Signup').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')

    def test_user_singup_password_unmatched(self):
        self.browser.visit(self.live_server_url + '/accounts/signup/')
        self.browser.find_by_name('username').fill('bob')
        self.browser.find_by_name('email').fill('*****@*****.**')
        self.browser.find_by_name('password1').fill('bob_secret')
        self.browser.find_by_name('password2').fill('bob_password')
        self.browser.find_by_value('Signup').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'The two password fields didn\'t match.')

    def test_user_signin(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        logout(self)

    def test_user_signin_empty_user(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        self.browser.visit(self.live_server_url + '/accounts/signin/')
        self.browser.find_by_name('identification').fill('')
        self.browser.find_by_name('password').fill('bob_secret')
        self.browser.find_by_xpath(
            "//div[@id='body']/div/form/input").first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Either supply us with your email or username.')

    def test_user_signin_bad_user(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        self.browser.visit(self.live_server_url + '/accounts/signin/')
        self.browser.find_by_name('identification').fill('alice')
        self.browser.find_by_name('password').fill('bob_secret')
        self.browser.find_by_xpath(
            "//div[@id='body']/div/form/input").first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(
            text,
            'Please enter a correct username or email and password. Note that both fields are case-sensitive.'
        )

    def test_user_signin_empty_password(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        self.browser.visit(self.live_server_url + '/accounts/signin/')
        self.browser.find_by_name('identification').fill('bob')
        self.browser.find_by_name('password').fill('')
        self.browser.find_by_xpath(
            "//div[@id='body']/div/form/input").first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')

    def test_user_signin_bad_password(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        self.browser.visit(self.live_server_url + '/accounts/signin/')
        self.browser.find_by_name('identification').fill('bob')
        self.browser.find_by_name('password').fill('alice_secret')
        self.browser.find_by_xpath(
            "//div[@id='body']/div/form/input").first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(
            text,
            'Please enter a correct username or email and password. Note that both fields are case-sensitive.'
        )

    def test_user_logout(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        logout(self)
        self.assertEqual(self.browser.title, 'SylvaDB - Signed out')
        self.assertEqual(
            self.browser.find_by_css('.body-inside').first.value,
            'You have been signed out. Till we meet again.')

    def test_user_details(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/edit/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Account setup')
        self.browser.find_by_name('first_name').fill('Bob')
        self.browser.find_by_name('last_name').fill('Doe')
        self.browser.attach_file(
            'mugshot',
            'http://www.gravatar.com/avatar/3d4bcca5d9c3a56a0282f308f9acda07?s=90'
        )
        self.browser.select('language', 'en')
        self.browser.select('gender', '1')
        self.browser.find_by_name('website').fill('http://www.bobweb.com')
        self.browser.find_by_name('location').fill('London, Ontario')
        self.browser.find_by_name('birth_date').fill('01/01/1975')
        self.browser.find_by_name('about_me').fill('I am a very nice guy')
        self.browser.find_by_name('institution').fill('University')
        self.browser.find_by_name('company').fill('CulturePlex')
        self.browser.find_by_name('lab').fill('CulturePlex')
        self.browser.find_by_value('Save changes').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        logout(self)

    def test_user_details_bad_website(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/edit/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Account setup')
        self.browser.find_by_name('first_name').fill('Bob')
        self.browser.find_by_name('last_name').fill('Doe')
        self.browser.attach_file(
            'mugshot',
            'http://www.gravatar.com/avatar/3d4bcca5d9c3a56a0282f308f9acda07?s=90'
        )
        self.browser.select('language', 'en')
        self.browser.select('gender', '1')
        self.browser.find_by_name('website').fill('bobweb')
        self.browser.find_by_name('location').fill('London, Ontario')
        self.browser.find_by_name('birth_date').fill('01/01/1975')
        self.browser.find_by_name('about_me').fill('I am a very nice guy')
        self.browser.find_by_name('institution').fill('University')
        self.browser.find_by_name('company').fill('CulturePlex')
        self.browser.find_by_name('lab').fill('CulturePlex')
        self.browser.find_by_value('Save changes').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Enter a valid URL.')
        logout(self)

    def test_user_details_bad_birthdate(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/edit/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Account setup')
        self.browser.find_by_name('first_name').fill('Bob')
        self.browser.find_by_name('last_name').fill('Doe')
        self.browser.attach_file(
            'mugshot',
            'http://www.gravatar.com/avatar/3d4bcca5d9c3a56a0282f308f9acda07?s=90'
        )
        self.browser.select('language', 'en')
        self.browser.select('gender', '1')
        self.browser.find_by_name('website').fill('http://www.bobweb.com')
        self.browser.find_by_name('location').fill('London, Ontario')
        self.browser.find_by_name('birth_date').fill('birthdate')
        self.browser.find_by_name('about_me').fill('I am a very nice guy')
        self.browser.find_by_name('institution').fill('University')
        self.browser.find_by_name('company').fill('CulturePlex')
        self.browser.find_by_name('lab').fill('CulturePlex')
        self.browser.find_by_value('Save changes').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Enter a valid date.')
        logout(self)

    def test_user_details_future_birthdate(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/edit/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Account setup')
        self.browser.find_by_name('first_name').fill('Bob')
        self.browser.find_by_name('last_name').fill('Doe')
        self.browser.attach_file(
            'mugshot',
            'http://www.gravatar.com/avatar/3d4bcca5d9c3a56a0282f308f9acda07?s=90'
        )
        self.browser.select('language', 'en')
        self.browser.select('gender', '1')
        self.browser.find_by_name('website').fill('http://www.bobweb.com')
        self.browser.find_by_name('location').fill('London, Ontario')
        self.browser.find_by_name('birth_date').fill('2015-01-11')
        self.browser.find_by_name('about_me').fill('I am a very nice guy')
        self.browser.find_by_name('institution').fill('University')
        self.browser.find_by_name('company').fill('CulturePlex')
        self.browser.find_by_name('lab').fill('CulturePlex')
        self.browser.find_by_value('Save changes').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'You need to introduce a past date.')
        logout(self)

    def test_user_change_pass(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/password/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Change password')
        self.browser.find_by_name('old_password').fill('bob_secret')
        self.browser.find_by_name('new_password1').fill('bob_password')
        self.browser.find_by_name('new_password2').fill('bob_password')
        self.browser.find_by_value('Change password').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Password changed')
        logout(self)

    def test_user_change_pass_empty(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/password/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Change password')
        self.browser.find_by_name('old_password').fill('')
        self.browser.find_by_name('new_password1').fill('bob_password')
        self.browser.find_by_name('new_password2').fill('bob_password')
        self.browser.find_by_value('Change password').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')
        logout(self)

    def test_user_change_pass_incorrectly(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/password/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Change password')
        self.browser.find_by_name('old_password').fill('bad_password')
        self.browser.find_by_name('new_password1').fill('bob_password')
        self.browser.find_by_name('new_password2').fill('bob_password')
        self.browser.find_by_value('Change password').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(
            text,
            'Your old password was entered incorrectly. Please enter it again.'
        )
        logout(self)

    def test_user_change_new_pass_empty(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/password/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Change password')
        self.browser.find_by_name('old_password').fill('bob_secret')
        self.browser.find_by_name('new_password1').fill('')
        self.browser.find_by_name('new_password2').fill('bob_password')
        self.browser.find_by_value('Change password').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')
        logout(self)

    def test_user_change_new_pass_unmatched(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/password/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Change password')
        self.browser.find_by_name('old_password').fill('bob_secret')
        self.browser.find_by_name('new_password1').fill('bob_password')
        self.browser.find_by_name('new_password2').fill('alice_password')
        self.browser.find_by_value('Change password').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'The two password fields didn\'t match.')
        logout(self)

    def test_user_change_mail(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/email/').first.click()
        self.assertEqual(self.browser.title,
                         'SylvaDB - Welcome to The Sylva Project')
        self.browser.find_by_name('email').fill('*****@*****.**')
        self.browser.find_by_value('Change email').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Email verification')

    def test_user_change_mail_empty(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/email/').first.click()
        self.assertEqual(self.browser.title,
                         'SylvaDB - Welcome to The Sylva Project')
        self.browser.find_by_name('email').fill('')
        self.browser.find_by_value('Change email').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')

    def test_user_change_bad(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/email/').first.click()
        self.assertEqual(self.browser.title,
                         'SylvaDB - Welcome to The Sylva Project')
        self.browser.find_by_name('email').fill('bobnewcultureplex.ca')
        self.browser.find_by_value('Change email').first.click()
        text = self.browser.find_by_xpath(
            "//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Enter a valid e-mail address.')
class UploadTestCase(unittest.TestCase):

  def setUp(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_datastore_v3_stub()
    self.testbed.init_memcache_stub()
    self.browser = Browser('chrome')

  def tearDown(self):
    self.testbed.deactivate()

  def test_when_create_task_upload_file(self):
    #login
    self.browser.visit("http://127.0.0.1:8080/")
    self.assertEqual(self.browser.find_by_tag("h3").first.text, "Not logged in")
    self.browser.find_by_id("submit-login").first.click()
    self.assertEqual(self.browser.find_link_by_text("Insurance").first.text, "Insurance")

    self.browser.visit("http://127.0.0.1:8080/tasks")

    self.browser.click_link_by_text('Create new task')

    self.browser.fill('title', 'title')
    self.browser.fill('text', 'text')

    self.browser.is_element_present_by_name('files[]', wait_time=10)

    self.browser.attach_file('files[]', os.path.join(os.path.dirname(__file__),'1.png'))
    #self.browser.attach_file('files[]', 'test/1.png')
    self.browser.find_by_css('.btn.btn-primary.start').first.click()


    self.assertEqual(1, len(self.browser.find_by_css('.template-download.fade.in')))
    self.assertEqual(4, len(self.browser.find_by_css('.template-download.fade.in td')))

  def test_when_create_task_upload_many_files(self):
    #login
    self.browser.visit("http://127.0.0.1:8080/")
    self.assertEqual(self.browser.find_by_tag("h3").first.text, "Not logged in")
    self.browser.find_by_id("submit-login").first.click()
    self.assertEqual(self.browser.find_link_by_text("Insurance").first.text, "Insurance")

    self.browser.visit("http://127.0.0.1:8080/tasks")

    self.browser.click_link_by_text('Create new task')

    self.browser.fill('title', 'title')
    self.browser.fill('text', 'text')

    self.browser.is_element_present_by_name('files[]')

    self.browser.attach_file('files[]', os.path.join(os.path.dirname(__file__),'1.png'))
    self.browser.attach_file('files[]', os.path.join(os.path.dirname(__file__),'1.png'))
    self.browser.attach_file('files[]', os.path.join(os.path.dirname(__file__),'1.png'))

    #self.browser.attach_file('files[]', 'test/1.png')
    self.browser.find_by_css('.btn.btn-primary.start').first.click()
    sleep(3)

    self.assertEqual(3, len(self.browser.find_by_css('.files tr.template-download')))
Exemple #13
0
class control_google():
    def init_browser(self, email, passwd):
        self.state = 'good'
        self.passwd = passwd
        self.login = email

        param = {
            'chrome.noWebsiteTestingDefaults': True,
            'chrome.prefs': {
                'profile.default_content_settings': {
                    'images': 2
                },
            }
        }
        from selenium.webdriver.chrome.options import Options
        options = Options()

        #options.add_argument('--allow-running-insecure-content')
        #options.add_argument('--disable-web-security')
        #options.add_argument('--disk-cache-dir=/var/www/cake2.2.4/app/tmp/cache/selenium-chrome-cache')
        #options.add_argument('--no-referrers')
        #options.add_argument('--window-size=1003,719')
        #options.add_argument('--proxy-server=localhost:8118')
        options.add_argument(
            "'chrome.prefs': {'profile.managed_default_content_settings.images': 2}"
        )

        CHROME = {
            "browserName": "chrome",
            "chrome.prefs": {
                "profile.managed_default_content_settings.images": 2
            },
            "chrome.switches": ["disable-images"],
        }

        self.browser = Browser('chrome', user_agent=useragent)
        #self.browser = Browser('chrome', user_agent=useragent, desired_capabilities=CHROME)

        load_page = 'https://accounts.google.com/ServiceLogin?btmpl=mobile_tier2&hl=ru&service=mobile'
        self.browser.visit(load_page)

        self.browser.find_by_id('Email').first.fill(email + '@gmail.com')
        self.browser.find_by_id('Passwd').first.fill(passwd)

        self.browser.find_by_id('signIn').first.click()

    def _google_hook(self):
        if self.browser.is_element_present_by_id('358'):
            self.browser.find_by_id('358').first.click()

        if self.browser.is_element_present_by_id('link_dismiss'):
            try:
                self.browser.find_by_id('link_dismiss').first.click()
            except:
                pass

        if 'getstarted' in self.browser.url:
            self.browser.back()

        if self.browser.is_element_present_by_id('link_dismiss'):
            self.browser.find_by_id('link_dismiss').first.click()

    def open_profile(self):
        print 'Open light version profile'
        load_page = 'https://plus.google.com/app/basic/%s/about' % self.profile_id
        self.browser.visit(load_page)

    def save_profile(self):
        self.browser.find_by_id('177').first.click()

    def register_google_plus(self, firstName, lastName):
        load_page = 'https://plus.google.com/u/0/?gpsrc=ogpy0&tab=XX'
        self.browser.visit(load_page)

        self.browser.fill('firstName', firstName)
        self.browser.fill('lastName', lastName)

        self.browser.find_by_name('buttonPressed').first.click()

        self.browser.find_by_id('357').first.click()

    def get_profile_id(self):
        load_page = 'https://www.google.com/settings/general-light?ref=/settings/account'
        self.browser.visit(load_page)
        if self.browser.is_element_present_by_xpath('//a[@class="CS"]'):
            profile_link = self.browser.find_by_xpath('//a[@class="CS"]').first
            link_path = profile_link['href']

            return link_path.split('/')[3]
        else:
            return False

    def profile_edit(self, vals):
        self.open_profile()

        print 'Click change profile'
        self.browser.find_by_id('59').first.click()

        #Confirm mobile rules
        self._google_hook()

        self.browser.find_by_name('peWork0').first.fill(vals['company'])
        self.browser.find_by_name('peWorkTitle0').first.fill(vals['position'])
        self.browser.find_by_name('peWorkStartYear0').first.fill(
            vals['year_start'])
        self.browser.find_by_name('peWorkEndYear0').first.fill(
            vals['year_stop'])

        self.browser.find_by_name('peSchool0').first.fill(
            vals['university_name'])
        self.browser.find_by_name('peSchoolMajor0').first.fill(
            vals['field_education_name'])
        self.browser.find_by_name('peSchoolStartYear0').first.fill(
            vals['going_to_college_year'])
        self.browser.find_by_name('peSchoolEndYear0').first.fill(
            vals['after_graduation_year'])

        self.browser.find_by_name('pePlaceLived0').first.fill(
            vals['place_lived'])

        self.browser.find_by_name('pePlaceLivedIsCurrent').first.check()

        self.browser.find_by_name('peGender').first.select("1")

        print 'Done profile_edit'

        self.save_profile()

    def change_photo(self, photo_path):
        self.open_profile()

        print 'Click change profile'
        self.browser.find_by_id('59').first.click()

        print 'Click change photo'
        self.browser.find_by_id('375').first.click()

        self.browser.attach_file('photo_upload_file_name', self.photo_path)
        print 'Done profile_edit'

        self.browser.find_by_id('314').first.click()

        self.save_profile()

    def change_pass(self, old_pass, new_pass):
        print 'Open password  change page'
        load_page = 'https://accounts.google.com/b/0/EditPasswd?hl=ru'
        self.browser.visit(load_page)

        self.browser.find_by_id('OldPasswd').first.fill(old_pass)
        self.browser.find_by_id('Passwd').first.fill(new_pass)
        self.browser.find_by_id('PasswdAgain').first.fill(new_pass)

        self.browser.find_by_id('save').first.click()
        print 'Done change pass'

    def open_full_plus(self):
        'Print open full Google+'
        load_page = 'https://plus.google.com/u/0/'
        self.browser.visit(load_page)

    def open_full_profile(self):
        self.open_full_plus()
        self._google_hook()

        print 'Click user icon'
        self.browser.find_by_id('gbi4i').first.click()

        print 'Click show profile'
        #self.browser.find_by_id('gbmplp').first.click()
        self.browser.find_by_xpath(
            '//a[@class="gbqfb gbiba gbp1"]').first.click()

    def change_name(self, firstName, lastName):
        self.open_full_plus()
        self.open_full_profile()

        print 'Click change name'
        time.sleep(5)
        self.browser.find_by_xpath(
            '//div[@guidedhelpid="profile_name"]').first.click()

        print 'Fill values'
        time.sleep(5)
        self.browser.find_by_xpath(
            '//input[@class="l-pR osa g-A-G"]').first.fill(firstName)
        self.browser.find_by_xpath(
            '//input[@class="l-oR Ika g-A-G"]').first.fill(lastName)

        print 'Save results'
        self.browser.find_by_xpath(
            '//*[starts-with(@class,"a-f-e c-b c-b-M nVrMHf nZQKMd h019o")]'
        ).first.click()

        print 'Confirm'
        self.browser.find_by_name('ok').first.click()

    def youtube_hoock(self):
        if 'ServiceLogin?' in self.browser.url:
            print 'ServiceLogin? Hook'
            self.browser.fill('Passwd', self.passwd)
            self.browser.find_by_name('signIn').first.click()
            #self.browser.back()

        if 'create_channel?' in self.browser.url:
            print 'create_channel? Hook'
            self.browser.click_link_by_partial_href('create_channel')
            self.browser.fill('username', self.login)
            self.browser.find_by_id('channel_submit').click()
            self.browser.back()
            self.browser.back()
            self.browser.back()

        if 'select_site?' in self.browser.url:
            print 'select_site? Hook'
            self.browser.find_by_xpath('//input[@type="submit"]').click()
            self.browser.back()
            self.browser.back()

        if 'switch-profile.g?' in self.browser.url:
            print 'switch-profile.g? Hook'
            self.browser.find_by_id('switchButton').click()

    def youtube_like(self, url):
        self.browser.visit(url)
        self.browser.click_link_by_partial_href('action_like=1')

        self.youtube_hoock(url)

        self.browser.find_by_name('action_rate').click()

    def youtube_dislike(self, url):
        self.browser.visit(url)
        self.browser.click_link_by_partial_href('action_dislike=1')

        self.youtube_hoock()

        self.browser.find_by_name('action_rate').click()

    def youtube_comment(self, url, comment):
        self.browser.visit(url)

        self.browser.click_link_by_partial_href('post_comment')

        self.youtube_hoock()
        try:
            self.browser.click_link_by_partial_href('post_comment')
        except:
            pass

        self.youtube_hoock()
        self.browser.fill('comment', comment)
        self.browser.find_by_name('action_comment').click()

        self.youtube_hoock()

    def youtube_subscribe(self, chane_name):
        load_page = 'http://m.youtube.com/user/%s' % chane_name
        self.browser.visit(load_page)

        self.browser.find_by_name('submit')[1].click()

        self.youtube_hoock()

        try:
            self.browser.find_by_name('submit')[1].click()
        except:
            pass

    def google_friend_connector(self):
        #self.browser.click_link_by_partial_href('post_comment')
        pass

    def blogspot_follow(self, url):
        pass

    def get_capture(self):
        cap_element = self.browser.find_by_xpath('//img[@width="300"]').first
        cap_code = recognize_captcha(cap_element['src'])
        self.browser.fill('recaptcha_response_field', cap_code)

    def blogspot_post_plus(self, url):
        self.browser.visit(url)
        frame_name = self.browser.find_by_xpath(
            '//*[starts-with(@name,"I0_")]')[0]['name']
        print frame_name
        with self.browser.get_iframe(frame_name) as iframe:
            #	#self.browser.find_by_xpath('//span[@class="hAa Qo Bg"]').first.click()
            iframe.find_by_xpath('//span[@class="hAa Qo Bg"]').first.click()

    def blogspot_post(self, url, comment):
        self.browser.visit(url)

        with self.browser.get_iframe('comment-editor') as iframe:
            self.browser.fill('commentBody', comment)
            iframe.find_by_id('postCommentSubmit').click()
            self.youtube_hoock()

        with self.browser.get_iframe('comment-editor') as iframe:
            if iframe.is_element_present_by_id('recaptcha_image'):
                self.get_capture()
                iframe.find_by_id('postCommentSubmit').click()

        if 'showComment=' in self.browser.url:
            return True
        else:
            return False

    def google_post_like(self, url):
        self.browser.visit(url)

        if not self.browser.is_element_present_by_name('stupop'):
            self.browser.find_by_id('162').click()
            return True
        else:
            return False

    def google_post_dislike(self, url):
        self.browser.visit(url)

        if self.browser.is_element_present_by_name('stupop'):
            self.browser.find_by_id('162').click()
            return True
        else:
            return False

    def google_post_comment(self, url, comment):
        self.browser.visit(url)

        self.browser.fill('adcp', comment)
        self.browser.find_by_id('110').click()

    def google_post_share(self, url, comment):
        self.browser.visit(url)

        self.browser.find_by_id('396').click()
        self.browser.fill('rpPostMsg', comment)
        self.browser.find_by_id('253').click()

    def google_profile_join(self, id):
        self.browser.visit('https://plus.google.com/app/basic/%s/' % id)

        self.browser.find_by_id('59').click()
        self.circle_join()

    def circle_join(self):
        self.browser.find_by_name('chcccp')[3].click()
        self.browser.find_by_id('49').click()
        self.browser.reload()

    def google_communities_enter(self, id):
        self.browser.visit('https://plus.google.com/u/0/communities/%s/' % id)
        self._google_hook()

    def google_communities_join(self, id):
        self.google_communities_enter(id)

        if self.browser.is_element_present_by_xpath(
                '//*[starts-with(@class,"a-f-e c-b c-b-La")]'):
            self.browser.find_by_xpath(
                '//*[starts-with(@class,"a-f-e c-b c-b-La")]').first.click()

    def google_communities_post(self, id, mess):
        print 'Start  communities post'
        self.google_communities_join(id)
        time.sleep(60)
        #for i in self.browser.find_by_xpath('//a[@class="FW9qdb Wk"]'):
        #`	print i['oid']

        #self.browser.reload()
        self.browser.find_by_xpath(
            '//div[@guidedhelpid="sharebox_textarea"]').first.click()
        self.browser.find_by_xpath('//div[@class="yd editable"]').first.fill(
            mess)
        self.browser.find_by_xpath(
            '//div[@guidedhelpid="sharebutton"]').click()
        time.sleep(60)
        self.browser.find_by_xpath('//div[@class="a-n Ph Hw"]').first.click()
        print '-' * 30
        for i in self.browser.find_by_xpath('//a[@class="FW9qdb Wk"]'):
            print i['oid']

    def google_people_suggested(self):
        self.browser.visit(
            'https://plus.google.com/app/basic/people/suggested?')
        for i in range(10):
            try:
                self.browser.find_by_xpath('//a[@class="vfc"]').first.click()
                self.circle_join()
            except:
                self.browser.visit(
                    'https://plus.google.com/app/basic/people/suggested?')

    def google_grab_comm_members(self, id, qty):
        irr_qty = int((qty - 64) / 20.00) + 3
        print 'Irr qty= %d' % irr_qty

        self.browser.visit(
            'https://plus.google.com/u/0/communities/%s/members' % id)
        ret_arr = []

        js_del_all_img = """
		var images = document.getElementsByTagName('img');
			while(images.length > 0) 
			{
    		images[0].parentNode.removeChild(images[0]);
			}
		"""

        for i in range(irr_qty):
            elem_arr = self.browser.find_by_xpath('//div[@class="ib31if"]')
            print 'Array len %d' % len(elem_arr)
            print i
            print ''
            elem_arr[len(elem_arr) - 2].right_click()
            #self.browser.execute_script(js_del_all_img)
            for elem in elem_arr:
                oid = elem['oid']
                img = self.browser.find_by_xpath('//img[@oid="%s"]' % oid)[0]
                #print img['src']

                if not oid in ret_arr:
                    ret_arr.append(oid)
                    print oid

        f = open('/tmp/google_oid.txt', 'w')
        for s in ret_arr:
            f.write('<item>' + s + '</item>\n')
        f.close()
        print 'Grab done'

    def quit(self):
        self.browser.quit()
Exemple #14
0
def add_album_to_rym(args, config_file):
    br = Browser()

    br.visit('https://rateyourmusic.com/account/login')
    time.sleep(3)

    # Login
    br.fill('username', credentials.username)
    br.fill('password', credentials.password)
    br.find_by_id('login_submit').click()
    time.sleep(5)

    (title, artist, tracklist, release, cover) = config.read_config(config_file)
   

    """
    if args.update_album:

        br.visit(args.rym_album)

    else:
    """

    if args.add_artist:
        br.visit('https://rateyourmusic.com/artist_add')

        #br.fill('lastname', unicode(artist))
        br.fill('lastname', artist)
        br.fill('comments', args.url)

        br.find_by_id('submitbtn').click()

        time.sleep(3)
        
        br.find_by_text(artist).click()
    
    else:
        br.visit(args.rym_profile)
    
    time.sleep(3)
    
    br.click_link_by_partial_href('/releases/ac?artist_id=')
    
    # Add data
    #br.fill('title', unicode(title))
    br.fill('title', title)
    
    br.find_by_id('format58').click()

    br.find_by_id('goAdvancedBtn').click()
    tracks_div = br.find_by_id('tracks_adv')
    tracks_text_area = tracks_div.find_by_id('track_advanced')
    #tracks_text_area.fill(unicode(tracklist)) 
    tracks_text_area.fill(tracklist) 
    br.find_by_id('goSimpleBtn').click()

    br.fill('notes', args.url)
 
    (year, month, day)      = parse_release_date(release)

    release_month_selector  = br.find_by_id('month')
    release_month_selector.select(month)
    
    release_day_selector    = br.find_by_id('day')
    release_day_selector.select(day)
    
    release_year_selector   = br.find_by_id('year')
    release_year_selector.select(year)

    br.find_by_id('previewbtn').click()
    br.find_by_id('submitbtn').click()

    # Add cover art

    """
    coverart_img_element = br.find_by_xpath("//img[@class='coverart_img']")
    print(coverart_im_element)
    sys.exit(0)
    """

    br.click_link_by_partial_href('/images/upload?type=l&assoc_id=')
    br.attach_file('upload_file', cover)

    br.fill('source', args.url)
    br.find_by_id('uploadbutton').click()
    time.sleep(5)

    br.click_link_by_partial_href('javascript:setStatus')


    # Vote for genre
    br.click_link_by_partial_href('/release/')
    time.sleep(3)

    br.click_link_by_partial_href('/rgenre/set?')

    prigen_text_area = br.find_by_xpath("//input[@id='prigen']")
    prigen_text_area.fill('vaporwave')

    prigen_vote_button = br.find_by_xpath("//input[@value='+ propose']").first
    prigen_vote_button.click()

    # Done
    br.click_link_by_partial_href('/release/')
    print("Finished")
Exemple #15
0
class UserTestCase(LiveServerTestCase):
    """
    A set of tests for testing Users, Accounts and UserProfiles. Also, we
    check the patterns for the required fields for signup, signin, the menu of
    user details, the change password view and the change email view.
    """

    def setUp(self):
        self.browser = Browser()

    def tearDown(self):
        self.browser.quit()

    def test_user_signup(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        self.assertEqual(self.browser.find_by_css('.body-inside').first.value, 'Thank you for signing up with us!\nYou can now use the supplied credentials to signin.')
        self.assertEqual(self.browser.title, 'SylvaDB - Signup almost done!')

    def test_user_singup_empty_email(self):
        self.browser.visit(self.live_server_url + '/accounts/signup/')
        self.browser.find_by_name('username').fill('bob')
        self.browser.find_by_name('email').fill('')
        self.browser.find_by_name('password1').fill('bob_secret')
        self.browser.find_by_name('password2').fill('bob_secret')
        self.browser.find_by_value('Signup').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')

    def test_user_singup_bad_email(self):
        self.browser.visit(self.live_server_url + '/accounts/signup/')
        self.browser.find_by_name('username').fill('bob')
        self.browser.find_by_name('email').fill('bobcultureplex.ca')
        self.browser.find_by_name('password1').fill('bob_secret')
        self.browser.find_by_name('password2').fill('bob_secret')
        self.browser.find_by_value('Signup').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Enter a valid e-mail address.')

    def test_user_singup_empty_name(self):
        self.browser.visit(self.live_server_url + '/accounts/signup/')
        self.browser.find_by_name('username').fill('')
        self.browser.find_by_name('email').fill('*****@*****.**')
        self.browser.find_by_name('password1').fill('bob_secret')
        self.browser.find_by_name('password2').fill('bob_secret')
        self.browser.find_by_value('Signup').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')

    def test_user_singup_empty_password(self):
        self.browser.visit(self.live_server_url + '/accounts/signup/')
        self.browser.find_by_name('username').fill('bob')
        self.browser.find_by_name('email').fill('*****@*****.**')
        self.browser.find_by_name('password1').fill('')
        self.browser.find_by_name('password2').fill('bob_secret')
        self.browser.find_by_value('Signup').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')

    def test_user_singup_password_unmatched(self):
        self.browser.visit(self.live_server_url + '/accounts/signup/')
        self.browser.find_by_name('username').fill('bob')
        self.browser.find_by_name('email').fill('*****@*****.**')
        self.browser.find_by_name('password1').fill('bob_secret')
        self.browser.find_by_name('password2').fill('bob_password')
        self.browser.find_by_value('Signup').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'The two password fields didn\'t match.')

    def test_user_signin(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        logout(self)

    def test_user_signin_empty_user(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        self.browser.visit(self.live_server_url + '/accounts/signin/')
        self.browser.find_by_name('identification').fill('')
        self.browser.find_by_name('password').fill('bob_secret')
        self.browser.find_by_xpath(
            "//div[@id='body']/div/form/input").first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Either supply us with your email or username.')

    def test_user_signin_bad_user(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        self.browser.visit(self.live_server_url + '/accounts/signin/')
        self.browser.find_by_name('identification').fill('alice')
        self.browser.find_by_name('password').fill('bob_secret')
        self.browser.find_by_xpath(
            "//div[@id='body']/div/form/input").first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Please enter a correct username or email and password. Note that both fields are case-sensitive.')

    def test_user_signin_empty_password(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        self.browser.visit(self.live_server_url + '/accounts/signin/')
        self.browser.find_by_name('identification').fill('bob')
        self.browser.find_by_name('password').fill('')
        self.browser.find_by_xpath(
            "//div[@id='body']/div/form/input").first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')

    def test_user_signin_bad_password(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        self.browser.visit(self.live_server_url + '/accounts/signin/')
        self.browser.find_by_name('identification').fill('bob')
        self.browser.find_by_name('password').fill('alice_secret')
        self.browser.find_by_xpath(
            "//div[@id='body']/div/form/input").first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Please enter a correct username or email and password. Note that both fields are case-sensitive.')

    def test_user_logout(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        logout(self)
        self.assertEqual(self.browser.title, 'SylvaDB - Signed out')
        self.assertEqual(self.browser.find_by_css('.body-inside').first.value, 'You have been signed out. Till we meet again.')

    def test_user_details(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/edit/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Account setup')
        self.browser.find_by_name('first_name').fill('Bob')
        self.browser.find_by_name('last_name').fill('Doe')
        self.browser.attach_file('mugshot', 'http://www.gravatar.com/avatar/3d4bcca5d9c3a56a0282f308f9acda07?s=90')
        self.browser.select('language', 'en')
        self.browser.select('gender', '1')
        self.browser.find_by_name('website').fill('http://www.bobweb.com')
        self.browser.find_by_name('location').fill('London, Ontario')
        self.browser.find_by_name('birth_date').fill('01/01/1975')
        self.browser.find_by_name('about_me').fill('I am a very nice guy')
        self.browser.find_by_name('institution').fill('University')
        self.browser.find_by_name('company').fill('CulturePlex')
        self.browser.find_by_name('lab').fill('CulturePlex')
        self.browser.find_by_value('Save changes').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        logout(self)

    def test_user_details_bad_website(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/edit/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Account setup')
        self.browser.find_by_name('first_name').fill('Bob')
        self.browser.find_by_name('last_name').fill('Doe')
        self.browser.attach_file('mugshot', 'http://www.gravatar.com/avatar/3d4bcca5d9c3a56a0282f308f9acda07?s=90')
        self.browser.select('language', 'en')
        self.browser.select('gender', '1')
        self.browser.find_by_name('website').fill('bobweb')
        self.browser.find_by_name('location').fill('London, Ontario')
        self.browser.find_by_name('birth_date').fill('01/01/1975')
        self.browser.find_by_name('about_me').fill('I am a very nice guy')
        self.browser.find_by_name('institution').fill('University')
        self.browser.find_by_name('company').fill('CulturePlex')
        self.browser.find_by_name('lab').fill('CulturePlex')
        self.browser.find_by_value('Save changes').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Enter a valid URL.')
        logout(self)

    def test_user_details_bad_birthdate(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/edit/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Account setup')
        self.browser.find_by_name('first_name').fill('Bob')
        self.browser.find_by_name('last_name').fill('Doe')
        self.browser.attach_file('mugshot', 'http://www.gravatar.com/avatar/3d4bcca5d9c3a56a0282f308f9acda07?s=90')
        self.browser.select('language', 'en')
        self.browser.select('gender', '1')
        self.browser.find_by_name('website').fill('http://www.bobweb.com')
        self.browser.find_by_name('location').fill('London, Ontario')
        self.browser.find_by_name('birth_date').fill('birthdate')
        self.browser.find_by_name('about_me').fill('I am a very nice guy')
        self.browser.find_by_name('institution').fill('University')
        self.browser.find_by_name('company').fill('CulturePlex')
        self.browser.find_by_name('lab').fill('CulturePlex')
        self.browser.find_by_value('Save changes').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Enter a valid date.')
        logout(self)

    def test_user_details_future_birthdate(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/edit/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Account setup')
        self.browser.find_by_name('first_name').fill('Bob')
        self.browser.find_by_name('last_name').fill('Doe')
        self.browser.attach_file('mugshot', 'http://www.gravatar.com/avatar/3d4bcca5d9c3a56a0282f308f9acda07?s=90')
        self.browser.select('language', 'en')
        self.browser.select('gender', '1')
        self.browser.find_by_name('website').fill('http://www.bobweb.com')
        self.browser.find_by_name('location').fill('London, Ontario')
        self.browser.find_by_name('birth_date').fill('2015-01-11')
        self.browser.find_by_name('about_me').fill('I am a very nice guy')
        self.browser.find_by_name('institution').fill('University')
        self.browser.find_by_name('company').fill('CulturePlex')
        self.browser.find_by_name('lab').fill('CulturePlex')
        self.browser.find_by_value('Save changes').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'You need to introduce a past date.')
        logout(self)

    def test_user_change_pass(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/password/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Change password')
        self.browser.find_by_name('old_password').fill('bob_secret')
        self.browser.find_by_name('new_password1').fill('bob_password')
        self.browser.find_by_name('new_password2').fill('bob_password')
        self.browser.find_by_value('Change password').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Password changed')
        logout(self)

    def test_user_change_pass_empty(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/password/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Change password')
        self.browser.find_by_name('old_password').fill('')
        self.browser.find_by_name('new_password1').fill('bob_password')
        self.browser.find_by_name('new_password2').fill('bob_password')
        self.browser.find_by_value('Change password').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')
        logout(self)

    def test_user_change_pass_incorrectly(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/password/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Change password')
        self.browser.find_by_name('old_password').fill('bad_password')
        self.browser.find_by_name('new_password1').fill('bob_password')
        self.browser.find_by_name('new_password2').fill('bob_password')
        self.browser.find_by_value('Change password').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Your old password was entered incorrectly. Please enter it again.')
        logout(self)

    def test_user_change_new_pass_empty(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/password/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Change password')
        self.browser.find_by_name('old_password').fill('bob_secret')
        self.browser.find_by_name('new_password1').fill('')
        self.browser.find_by_name('new_password2').fill('bob_password')
        self.browser.find_by_value('Change password').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')
        logout(self)

    def test_user_change_new_pass_unmatched(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/password/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Change password')
        self.browser.find_by_name('old_password').fill('bob_secret')
        self.browser.find_by_name('new_password1').fill('bob_password')
        self.browser.find_by_name('new_password2').fill('alice_password')
        self.browser.find_by_value('Change password').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'The two password fields didn\'t match.')
        logout(self)

    def test_user_change_mail(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/email/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Welcome to The Sylva Project')
        self.browser.find_by_name('email').fill('*****@*****.**')
        self.browser.find_by_value('Change email').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Email verification')

    def test_user_change_mail_empty(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/email/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Welcome to The Sylva Project')
        self.browser.find_by_name('email').fill('')
        self.browser.find_by_value('Change email').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'This field is required.')

    def test_user_change_bad(self):
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
        self.browser.find_link_by_href('/accounts/bob/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
        self.browser.find_link_by_href('/accounts/bob/email/').first.click()
        self.assertEqual(self.browser.title, 'SylvaDB - Welcome to The Sylva Project')
        self.browser.find_by_name('email').fill('bobnewcultureplex.ca')
        self.browser.find_by_value('Change email').first.click()
        text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
        self.assertEqual(text, 'Enter a valid e-mail address.')
Exemple #16
0
class ToolsTestCaseCsv(LiveServerTestCase):
    """
    A master test to check the behaviour of the new 'auto' fields.
    Actually only works with gephi format.
    """
    def setUp(self):
        self.browser = Browser()
        socket.setdefaulttimeout(30)
        signup(self, 'bob', '*****@*****.**', 'bob_secret')
        signin(self, 'bob', 'bob_secret')
        self.firstGraphName = "bobgraph"
        self.secondGraphName = "alicegraph"

    def tearDown(self):
        logout(self)
        self.browser.quit()

    @classmethod
    def tearDownClass(cls):
        sleep(10)  # It needs some time for close the LiverServerTestCase
        super(ToolsTestCaseCsv, cls).tearDownClass()

    def test_graph_export_csv(self):
        # Create a graph with a auto_user property
        create_graph(self, self.firstGraphName)
        create_advanced_schema(self, self.firstGraphName)
        create_advanced_type(self, self.firstGraphName, "e")
        create_advanced_data(self)
        # Create new graph for import the data
        import_advanced_schema_csv(self, self.firstGraphName,
                                   self.secondGraphName)
        # Data import
        self.browser.find_by_id('toolsMenu').first.click()
        self.browser.find_link_by_href('/tools/' + self.secondGraphName +
                                       '/import/').first.click()
        self.browser.find_by_id('csv-radio').first.click()
        # Change the display field of input to attach the file
        script = """
            $('#files').css('display', '');
            """
        self.browser.execute_script(script)
        self.browser.is_text_present('Drop your nodes files here',
                                     wait_time=10)
        # Import the nodes
        file_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                 'files/csv/bobs-type.csv')
        self.browser.attach_file('file', file_path)
        self.browser.is_text_present(
            'Nodes files loaded. Loading edges files...', wait_time=10)
        # Wait until the data is imported
        self.browser.is_text_present('Now drop your edges files', wait_time=10)
        # Change the display field of input to attach the file
        script = """
            $('#files2').css('display', '');
            """
        self.browser.execute_script(script)
        # Import the relationships
        file_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                 'files/csv/bobs-rels.csv')
        self.browser.attach_file('file2', file_path)
        self.browser.is_text_present('Data loaded. Uploading to the server...',
                                     wait_time=10)
        # Wait until the data is imported
        self.browser.is_text_present('Data uploaded.', wait_time=10)
        # Check that nodes and relationships are ok
        self.browser.find_by_id('dataMenu').first.click()
        self.browser.find_by_xpath(
            "//a[@class='dataOption list']").first.click()
        alicegraph = Graph.objects.get(name=self.secondGraphName)
        alicegraphNodes = alicegraph.nodes.count()
        spin_assert(lambda: self.assertEqual(3, alicegraph.nodes.count()))
        spin_assert(
            lambda: self.assertEqual(1, alicegraph.relationships.count()))
        # Add new nodes and relationships and check all is correct
        self.browser.find_by_id('dataMenu').first.click()
        self.browser.find_by_xpath(
            "//a[@class='dataOption new']").first.click()
        text = self.browser.find_by_id('propertiesTitle').first.value
        spin_assert(lambda: self.assertEqual(text, 'Properties'))
        self.browser.find_by_value("Save Bob's type").first.click()
        text = self.browser.find_by_xpath(
            "//div[@class='pagination']/span[@class='pagination-info']"
        ).first.value
        spin_assert(lambda: self.assertNotEqual(
            text.find(" elements Bob's type."), -1))
        spin_assert(lambda: self.assertEqual(alicegraphNodes + 1,
                                             alicegraph.nodes.count()))
        # Destroy the databases
        Graph.objects.get(name=self.firstGraphName).destroy()
        Graph.objects.get(name=self.secondGraphName).destroy()
Exemple #17
0
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 SplinterBrowserDriver(BaseBrowserDriver):
    """
        This is a BrowserDriver for splinter
        (http://splinter.cobrateam.info)
        that implements the BaseBrowserDriver API.

        To use it, you must have splinter installed on your env.

        For itself it's a browser driver that supports multiple browsing
        technologies such as selenium, phantomjs, zope, etc.
    """

    driver_name = 'splinter'

    def __init__(self):
        super(SplinterBrowserDriver, self).__init__()
        if not splinter_available:
            raise ImportError(
                "In order to use splinter Base Driver you have to install it. "
                "Check the instructions at http://splinter.cobrateam.info")
        self._browser = Browser(config.default_browser)

    def _handle_empty_element_action(self, element):
        if not element:
            raise ActionNotPerformableException(
                "The action couldn't be perfomed because the element couldn't "
                "be found; Try checking if your element"
                "selector is correct and if the page is loaded properly.")

    @property
    def page_url(self):
        return self._browser.url

    @property
    def page_source(self):
        return self._browser.html

    @property
    def page_title(self):
        return self._browser.title

    def open_url(self, url):
        self._browser.driver.get(url)

    def quit(self):
        return self._browser.quit()

    def is_element_visible(self, element):
        return element.visible

    def get_element_text(self, element):
        return element.text

    def get_element_by_xpath(self, selector):
        return self._browser.find_by_xpath(selector)

    def get_element_by_css(self, selector):
        return self._browser.find_by_css(selector)

    def get_element_by_id(self, selector):
        return self._browser.find_by_id(selector)

    def get_element_by_tag(self, selector):
        return self._browser.find_by_tag(selector)

    @element_action
    def type(self, element, text, slowly=False):
        return element.type(text, slowly)

    @element_action
    def fill(self, element, text):
        return element.fill(text)

    @element_action
    def clear(self, element):
        self.fill(element, '')

    @element_action
    def click(self, element):
        return element.click()

    @element_action
    def check(self, element):
        return element.check()

    @element_action
    def uncheck(self, element):
        return element.uncheck()

    @element_action
    def mouse_over(self, element):
        return element.mouse_over()

    @element_action
    def mouse_out(self, element):
        return element.mouse_out()

    def reload(self):
        return self._browser.reload()

    def go_back(self):
        return self._browser.back()

    def go_forward(self):
        return self._browser.forward()

    def execute_script(self, script):
        """This method is deprecated. Use `execute_javascript` instead.
        """
        return self._browser.evaluate_script(script)

    def execute_javascript(self, script):
        return self._browser.evaluate_script(script)

    def get_iframe(self, iframe_id):
        return self._browser.get_iframe(iframe_id)

    def get_alert(self):
        return self._browser.get_alert()

    def attach_file(self, input_name, file_path):
        return self._browser.attach_file(input_name, file_path)

    def wait_pageload(self, timeout=30):
        wait_interval = 0.05
        elapsed = 0

        while self.execute_javascript('document.readyState') != 'complete':
            self.wait(wait_interval)
            elapsed += wait_interval

            if elapsed > timeout:
                raise PageNotLoadedException

    def click_and_wait(self, element, timeout=30):
        self.click(element)
        self.wait_pageload(timeout)
import urllib2
import glob
import time
browser = Browser('chrome')
driver = webdriver.Chrome
WhileCounter = 0
print 'Hey!'
uploadLocation = raw_input(
    'What is the source of the file? Drag and drop file here (only on OSX):')
UserCounter = int(input('How many times repeat (something like 20)?? : '))
while WhileCounter < UserCounter:
    browser.visit('http://deepdreamgenerator.com/')
    uploadButton = browser.find_by_id('upload-form')
    uploadButton.click
    #    uploadLocation = '/Users/mkaptein172/Pictures/dream/wallpaper_1371895785.jpg'
    browser.attach_file('file', uploadLocation)
    #Now, it's doing stuff
    #Be sure it is there
    time.sleep(25)
    #try to avoid sketchy stuff
    try:
        browser.click_link_by_partial_href('/ddream/')
    except selenium.common.exceptions.ElementNotVisibleException:
        #IF exception, wait, then try do stuff again
        print 'Here was an exception, but we have dealt with the situation!'
        time.sleep(30)
        browser.reload()
        browser.click_link_by_partial_href('/ddream/')
#    browser.find_by_css('download-btn btn btn-primary').first.click()
#It's downloading into Downloads
    time.sleep(20)