Example #1
0
 def setUp(self):
     # ontology to be tested on
     self.ontology_path = resource_filename('toflerdb', self.ONTOLOGY_PATH)
     # few sample facts
     self.facts_path = resource_filename('toflerdb', self.FACTS_PATH)
     self.author = 'toflerdb'
     gcc_api.insert_ontology(file=self.ontology_path, author=self.author)
     do_sleep(30, msg='Inserting Ontology')
     res = gcc_api.insert_facts(file=self.facts_path, author=self.author)
     do_sleep(30, msg='Inserting Facts')
     self.templatized_id_map = res['templatized_id_map']
     self.name_map = {
         '_person_1': 'Mckenzie Mclean',
         '_person_2': 'Mays Talley',
         '_person_3': 'Carrillo Parsons',
         '_person_4': 'Mcmahon Phillips',
         '_person_5': 'Mccarty Atkins',
         '_person_6': 'Elisa Beasley',
         '_person_7': 'Tisha Moreno',
         '_person_8': 'Holloway Irwin',
         '_person_9': 'Kirkland Hughes',
         '_person_10': 'Trudy Maxwell',
         '_person_11': 'Black Malone',
         '_person_12': 'Ashlee Silva',
     }
def test_initial_gw_selection_depends_on_query_param():
    """If gateway param is given, that gateway is selected automatically."""
    user = get_e2e_user("e2e_user")
    assert user is not None
    # Extract the first device's ID
    devices = user.devices['items']
    devices = sorted(devices, key=lambda d: d['devConnectwareId'])
    devid = devices[0]['devConnectwareId']

    splinter_tests.visit("/#/xbee_network?gateway=" + devid)

    do_sleep()

    assert browser.is_text_present("XBee Network View")

    gw_select = browser.find_by_css("select#gateway")
    assert not gw_select.is_empty()
    # Check that the first gateway is selected
    assert_that(gw_select.first.value, is_("0"))

    # 'Fetch from' select box should be visible now
    assert browser.is_text_present("Fetch from:")
    # 'Device Cloud' is automatically selected
    fetch_from = browser.find_by_css('select#fetch_from')
    assert not fetch_from.is_empty()
    assert_that(fetch_from.first.value, is_("dc"))
Example #3
0
def insert_facts(fact_tuples):
    em = EntryMaker()
    em.turn_off_validation()
    for row in fact_tuples:
        em.add_input(row[0], row[1], row[2])
    em.commit()
    test_utils.do_sleep(2, msg='Inserting')
def test_url_changes_with_gw_selection():
    """URL query param should change when gateway selection changes."""
    splinter_tests.visit("/#/xbee_network")

    assert browser.is_text_present("XBee Network View")

    # Since this user has more than one gateway, it shouldn't auto-select one.
    gw_select = browser.find_by_css('select#gateway')
    assert not gw_select.is_empty()  # Check that the select box is present
    assert_that(gw_select.first.value, is_("?"))

    # Pick the first gateway
    browser.select("gateway", "0")
    do_sleep()

    user = get_e2e_user("e2e_user")
    assert user is not None

    # Selected gateway should be first in order of devConnectwareId
    devices = user.devices['items']
    devices = sorted(devices, key=lambda d: d['devConnectwareId'])
    devid = devices[0]['devConnectwareId']
    assert_that(browser.url, ends_with("/xbee_network?gateway=" + devid))

    # Select the second gateway
    browser.select("gateway", "1")
    devid = devices[1]['devConnectwareId']
    assert_that(browser.url, ends_with("/xbee_network?gateway=" + devid))
def test_delete_disabled_without_dashboards():
    """Without a dashboard, Advanced Options does not enable the delete button."""
    splinter_tests.visit("#/advanced")

    do_sleep()

    button = find_delete_button()
    assert button.first['disabled']
    assert_that(button.first.text, is_("No dashboards in your account"))
Example #6
0
def insert_ontology(onto_tuples):
    om = OntoMaker()
    om.turn_off_validation()
    for row in onto_tuples:
        om.add_input(row[0], row[1], row[2])

    om.make_mapping()
    om.commit()
    test_utils.do_sleep(2, msg='Creating Ontology')
def test_delete_enabled_with_dashboard():
    """With a dashboard, Advanced Options enables the delete button."""
    splinter_tests.visit("#/advanced")

    do_sleep()

    button = find_delete_button()
    assert not button.first['disabled']
    assert_that(button.first.text, is_("Delete dashboard"))
def make_dashboard():
    # Create a blank dashboard.
    req = requests.post(splinter_tests.SERVER_URL + '/api/dashboards',
                        data='{"widgets": []}',
                        headers={'content-type': 'application/json'},
                        auth=('test_user#login.etherios.com', 'e2e_password'))
    req.raise_for_status()

    # Pause for a moment.
    do_sleep(multiplier=0.5)
def re_login_tst_user():  # tst, not test, so nose ignores this.
    splinter_tests.visit("/logout")
    splinter_tests.visit("/#/login")
    assert not browser.find_by_id("login_error").visible
    browser.fill("username", "test_user")
    browser.fill("password", "e2e_password")
    browser.find_by_css('.btn.login-button').click()

    do_sleep()

    assert not browser.is_text_present("Username or password was incorrect.")
    assert_that(browser.url, ends_with("#/setup"))
def re_login_tst_user():  # tst, not test, so nose ignores this.
    splinter_tests.visit("/logout")
    splinter_tests.visit("/#/login")
    assert not browser.find_by_id("login_error").visible
    browser.fill("username", "test_user")
    browser.fill("password", "e2e_password")
    browser.find_by_css('.btn.login-button').click()

    do_sleep()

    assert not browser.is_text_present("Username or password was incorrect.")
    assert_that(browser.url, ends_with("#/setup"))
def test_configuration_modal_basic():
    '''The configuration modal should appear when the button is clicked.'''
    with screenshot_on_exception("config_modal_basic"):
        # Get the list of widget types, and their associated value in the
        # select tag.
        options = browser.find_by_css("select#type option")
        assert not options.is_empty()

        optmap = {}
        for opt in options:
            optmap[opt.text] = opt.value

        # Select switch widget
        browser.select("type", optmap['On/Off Switch Widget'])

        # Select the first gateway in the list
        browser.select("device", '0')

        # Wait for the discovery to complete. For the e2e server this should
        # only take a second or two
        do_sleep()

        # Pick the first XBee in the list
        browser.select('xbeenode', '0')

        # Pick the first stream option (DIO0)
        xpath = '//select[@id="sets"]//option[.="DIO0"]'
        # Copied from splinter browser.select implementation
        browser.find_by_xpath(xpath).first._element.click()

        # The button should be present now. But first, make sure the modal is
        # not present currently, to be safe.
        assert not browser.is_text_present("Device IO Configuration")

        button = browser.find_by_name("checkRadioConfig")
        assert not button.is_empty()
        button.first.click()

        # Check the modal appears
        assert browser.is_text_present("Device IO Configuration", wait_time=1)

        # Check that there is a close button
        xpath = '//div[@class="modal-footer"]/button[.="Close"]'
        btn = browser.find_by_xpath(xpath)
        assert not btn.is_empty()

        # Click the close button - does the modal go away?
        btn.first.click()
        # Wait a moment
        do_sleep()
        assert not browser.is_text_present("Device IO Configuration")
        assert browser.find_by_xpath(xpath).is_empty()
def test_configuration_modal_basic():
    '''The configuration modal should appear when the button is clicked.'''
    with screenshot_on_exception("config_modal_basic"):
        # Get the list of widget types, and their associated value in the
        # select tag.
        options = browser.find_by_css("select#type option")
        assert not options.is_empty()

        optmap = {}
        for opt in options:
            optmap[opt.text] = opt.value

        # Select switch widget
        browser.select("type", optmap['On/Off Switch Widget'])

        # Select the first gateway in the list
        browser.select("device", '0')

        # Wait for the discovery to complete. For the e2e server this should
        # only take a second or two
        do_sleep()

        # Pick the first XBee in the list
        browser.select('xbeenode', '0')

        # Pick the first stream option (DIO0)
        xpath = '//select[@id="sets"]//option[.="DIO0"]'
        # Copied from splinter browser.select implementation
        browser.find_by_xpath(xpath).first._element.click()

        # The button should be present now. But first, make sure the modal is
        # not present currently, to be safe.
        assert not browser.is_text_present("Device IO Configuration")

        button = browser.find_by_name("checkRadioConfig")
        assert not button.is_empty()
        button.first.click()

        # Check the modal appears
        assert browser.is_text_present("Device IO Configuration", wait_time=1)

        # Check that there is a close button
        xpath = '//div[@class="modal-footer"]/button[.="Close"]'
        btn = browser.find_by_xpath(xpath)
        assert not btn.is_empty()

        # Click the close button - does the modal go away?
        btn.first.click()
        # Wait a moment
        do_sleep()
        assert not browser.is_text_present("Device IO Configuration")
        assert browser.find_by_xpath(xpath).is_empty()
def login_account_one_device():
    splinter_tests.visit("/logout")
    splinter_tests.visit("/#/login")
    assert not browser.find_by_id("login_error").visible

    browser.fill("username", "e2e_user_1device")
    browser.fill("password", "e2e_password")
    browser.find_by_css('.btn.login-button').click()

    # Wait for a moment
    do_sleep()

    assert not browser.is_text_present("Username or password was incorrect.")
def log_in(*auth):
    delete_all_dashboards(*auth)
    add_empty_dashboard(*auth)

    log_in_clean(*auth)

    splinter_tests.visit("/#/add_widget")

    # Wait a moment for everything to settle
    do_sleep()

    with screenshot_on_exception("log_in_not_add_widget"):
        assert_that(browser.url, ends_with('/#/add_widget'))
def log_in(*auth):
    delete_all_dashboards(*auth)
    add_empty_dashboard(*auth)

    log_in_clean(*auth)

    splinter_tests.visit("/#/add_widget")

    # Wait a moment for everything to settle
    do_sleep()

    with screenshot_on_exception("log_in_not_add_widget"):
        assert_that(browser.url, ends_with('/#/add_widget'))
def test_check_configuration():
    '''The 'Check Radio Configuration' button should appear when expected.'''
    # Locate the button by xpath, and not using its name, because we only
    # expect to see the one button, and finding it by its text is more flexible
    # (and closer to what the user would do).
    button_xpath = '//button[contains(., "Check Radio Configuration")]'

    def button_missing(missing=True):
        with screenshot_on_exception("button_missing_assert_%s" % missing):
            buttons = browser.find_by_xpath(button_xpath)

            assert_that(buttons.is_empty(), is_(missing))

    # The button should not be present.
    button_missing()

    # Get the list of widget types, and their associated value in the select
    # tag.
    options = browser.find_by_css("select#type option")
    assert not options.is_empty()

    optmap = {}
    for opt in options:
        optmap[opt.text] = opt.value

    # Select switch widget
    browser.select("type", optmap['On/Off Switch Widget'])
    # The button should not be present.
    button_missing()

    # Select the first gateway in the list
    browser.select("device", '0')
    # The button should not be present.
    button_missing()

    # Wait for the discovery to complete. For the e2e server this should only
    # take a second or two
    do_sleep(multiplier=2)

    # Pick the first XBee in the list
    browser.select('xbeenode', '0')
    # The button should not be present.
    button_missing()

    # Pick the first stream option (DIO0)
    xpath = '//select[@id="sets"]//option[.="DIO0"]'
    # Copied from splinter browser.select implementation
    browser.find_by_xpath(xpath).first._element.click()

    # The button should be present now.
    button_missing(False)
def test_check_configuration():
    '''The 'Check Radio Configuration' button should appear when expected.'''
    # Locate the button by xpath, and not using its name, because we only
    # expect to see the one button, and finding it by its text is more flexible
    # (and closer to what the user would do).
    button_xpath = '//button[contains(., "Check Radio Configuration")]'

    def button_missing(missing=True):
        with screenshot_on_exception("button_missing_assert_%s" % missing):
            buttons = browser.find_by_xpath(button_xpath)

            assert_that(buttons.is_empty(), is_(missing))

    # The button should not be present.
    button_missing()

    # Get the list of widget types, and their associated value in the select
    # tag.
    options = browser.find_by_css("select#type option")
    assert not options.is_empty()

    optmap = {}
    for opt in options:
        optmap[opt.text] = opt.value

    # Select switch widget
    browser.select("type", optmap['On/Off Switch Widget'])
    # The button should not be present.
    button_missing()

    # Select the first gateway in the list
    browser.select("device", '0')
    # The button should not be present.
    button_missing()

    # Wait for the discovery to complete. For the e2e server this should only
    # take a second or two
    do_sleep(multiplier=2)

    # Pick the first XBee in the list
    browser.select('xbeenode', '0')
    # The button should not be present.
    button_missing()

    # Pick the first stream option (DIO0)
    xpath = '//select[@id="sets"]//option[.="DIO0"]'
    # Copied from splinter browser.select implementation
    browser.find_by_xpath(xpath).first._element.click()

    # The button should be present now.
    button_missing(False)
Example #18
0
    def setUp(self):
        # insert ontology to be tested on
        self.author = 'toflerdb'
        self.ontology = [
            ('gctest:Book', 'to:subClassOf', 'to:Entity'),
            ('gctest:Author', 'to:subClassOf', 'to:Entity'),
            ('gctest:pageNumber', 'to:subClassOf', 'to:ComplexProperty'),
            ('gctest:pageNumber', 'to:domain', 'gctest:Book'),
            ('gctest:pageNumber', 'to:range', 'to:Null'),
            ('gctest:pageNumberStartsAt', 'to:subClassOf', 'to:Property'),
            ('gctest:pageNumberStartsAt', 'to:domain', 'gctest:pageNumber'),
            ('gctest:pageNumberStartsAt', 'to:range', 'to:Int'),
            ('gctest:pageNumberEndsAt', 'to:subClassOf', 'to:Property'),
            ('gctest:pageNumberEndsAt', 'to:domain', 'gctest:pageNumber'),
            ('gctest:pageNumberEndsAt', 'to:range', 'to:Int'),
            ('gctest:hasAuthor', 'to:subClassOf', 'to:RelationalProperty'),
            ('gctest:hasAuthor', 'to:domain', 'gctest:Book'),
            ('gctest:hasAuthor', 'to:range', 'gctest:Author'),
            ('gctest:numVolume', 'to:subClassOf', 'to:Property'),
            ('gctest:numVolume', 'to:domain', 'gctest:Book'),
            ('gctest:numVolume', 'to:range', 'to:Int'),
            ('gctest:numVolume', 'to:isUnique', 'True')
        ]
        # insert few facts to be deleted
        self.fact_list = [
            ('dcn8bzb83mxftp', 'to:type', 'gctest:Book'),
            ('dcn8bzb83mxftp', 'to:label', 'Test Book'),
            ('dcn8bzb83mxftp', 'to:description',
             'This book entry is done for testing deletion'),
            ('dcn8bzb83mxftp', 'gctest:numVolume', '4'),
            ('dcn8b17d8zkyr8', 'to:type', 'gctest:Author'),
            ('dcn8b17d8zkyr8', 'to:label', 'Test Author 1'),
            ('dcn8bzb83mxftp', 'gctest:hasAuthor', 'dcn8b17d8zkyr8'),
            ('dcn8b28shzvk67', 'to:type', 'gctest:Author'),
            ('dcn8b28shzvk67', 'to:label', 'Test Author 2'),
            ('dcn8bzb83mxftp', 'gctest:hasAuthor', 'dcn8b28shzvk67'),
            ('dcn8b37lhdt3fl', 'to:type', 'gctest:pageNumber'),
            ('dcn8b37lhdt3fl', 'gctest:pageNumberStartsAt', '10'),
            ('dcn8b37lhdt3fl', 'gctest:pageNumberEndsAt', '100'),
            ('dcn8bzb83mxftp', 'dcn8b37lhdt3fl', '')
        ]
        self.existing_nodes = [
            'dcn8bzb83mxftp', 'dcn8b17d8zkyr8', 'dcn8b28shzvk67'
        ]

        gcc_api.insert_ontology(self.ontology)
        test_utils.do_sleep(msg='Inserting ontology')
        gcc_api.insert_facts(self.fact_list, author=self.author)
        test_utils.do_sleep(msg='Inserting facts')
        self.fact_ids = test_utils.get_fact_ids(self.fact_list)
Example #19
0
 def test_uploadfacts_endpoint(self):
     url = 'http://localhost:9100/upload/facts'
     query = {'fact_tuples': self.fact_list, 'author': 'toflerdb'}
     # as we are going to insert same facts again we are
     # going to delete them
     test_utils.delete_from_eternity(self.fact_ids)
     snapshot_dbutils.delete_snapshot_nodes_by_id(self.existing_nodes)
     response = requests.post(url, data=json.dumps(query), timeout=2)
     test_utils.do_sleep(msg='Uploading')
     res_data = json.loads(response.content)
     self.assertTrue(res_data['status'] == 'SUCCESS')
     for node_id in self.existing_nodes:
         self.assertIsNotNone(
             snapshot_dbutils.get_snapshot_nodes(id=node_id))
def test_select_only_gateway():
    """If account has only one gateway, it is selected automatically."""
    splinter_tests.visit("/#/xbee_network")
    do_sleep()

    user = get_e2e_user("e2e_user_1device")
    assert user is not None
    # Extract the first device's ID
    devices = user.devices['items']
    devices = sorted(devices, key=lambda d: d['devConnectwareId'])
    devid = devices[0]['devConnectwareId']

    gw_select = browser.find_by_css('select#gateway')
    assert not gw_select.is_empty()
    assert_that(gw_select.first.value, is_("0"))
    assert_that(browser.url, ends_with("/xbee_network?gateway=" + devid))
def re_login_no_devices():
    splinter_tests.visit("/logout")
    splinter_tests.visit("/#/login")

    do_sleep()

    with screenshot_on_exception("re_login_no_devices"):
        assert not browser.find_by_id("login_error").visible
        browser.fill("username", "e2e_user_nodevices")
        browser.fill("password", "e2e_password")
        browser.find_by_css('.btn.login-button').click()

        # Wait for a moment
        do_sleep()

        assert not browser.is_text_present(BAD_CREDS_TEXT)
        assert_that(browser.url, ends_with("#/setup"))
def re_login_no_devices():
    splinter_tests.visit("/logout")
    splinter_tests.visit("/#/login")

    do_sleep()

    with screenshot_on_exception("re_login_no_devices"):
        assert not browser.find_by_id("login_error").visible
        browser.fill("username", "e2e_user_nodevices")
        browser.fill("password", "e2e_password")
        browser.find_by_css('.btn.login-button').click()

        # Wait for a moment
        do_sleep()

        assert not browser.is_text_present(BAD_CREDS_TEXT)
        assert_that(browser.url, ends_with("#/setup"))
def test_linked_to_from_devices_page():
    """Devices page should deep-link to XBee Network page."""
    user = get_e2e_user("test_user")
    assert user is not None
    # Extract the first device's ID
    devices = user.devices['items']
    devices = sorted(devices, key=lambda d: d['devConnectwareId'])
    devid = devices[0]['devConnectwareId']

    splinter_tests.visit("/#/devices")
    do_sleep()

    xpath = '//td[.="{}"]/..//a[.="View"]'.format(devid)
    view_btn = browser.find_by_xpath(xpath)
    assert not view_btn.is_empty()
    assert_that(view_btn.first['href'],
                ends_with("/xbee_network?gateway=" + devid))
def test_xbees_show_up():
    """XBees (but not coordinators) should be listed in the table correctly."""
    user = get_e2e_user("test_user")
    assert user is not None
    # Extract the first device's ID
    devices = user.devices['items']
    devices = sorted(devices, key=lambda d: d['devConnectwareId'])
    devid = devices[0]['devConnectwareId']

    splinter_tests.visit("/#/xbee_network?gateway=" + devid)
    do_sleep()

    xbees = user.xbees['items']

    for xbee in xbees:
        if str(xbee.get('xpNetAddr')) != "0":
            assert browser.is_text_present(xbee['xpExtAddr'])
            assert browser.is_text_present(xbee['xpNodeId'])
Example #25
0
def test_login_bad_credentials():
    """When the user enters bad credentials, an error appears."""
    browser = splinter_tests.browser

    # Check that no error is on screen yet.
    assert browser.find_by_id("login_error").has_class("hide")

    # Fill in bogus credentials.
    browser.fill('username', 'foo')
    browser.fill('password', 'bar')

    # Click "Log in"
    browser.find_by_css('.btn.login-button').click()

    utils.do_sleep()

    # Check that the login error has appeared.
    assert not browser.find_by_id("login_error").has_class("hide")
    assert browser.is_text_present("Username or password was incorrect.")
Example #26
0
def test_login_bad_credentials():
    """When the user enters bad credentials, an error appears."""
    browser = splinter_tests.browser

    # Check that no error is on screen yet.
    assert browser.find_by_id("login_error").has_class("hide")

    # Fill in bogus credentials.
    browser.fill('username', 'foo')
    browser.fill('password', 'bar')

    # Click "Log in"
    browser.find_by_css('.btn.login-button').click()

    utils.do_sleep()

    # Check that the login error has appeared.
    assert not browser.find_by_id("login_error").has_class("hide")
    assert browser.is_text_present("Username or password was incorrect.")
def test_delete_works_and_moves_user_to_setup():
    """'Delete dashboard' button works and redirects user to setup page."""
    splinter_tests.visit("#/advanced")

    do_sleep()

    button = find_delete_button()
    assert not button.first['disabled']

    # Click the delete button
    button.click()

    # Wait a moment while the deletion happens
    do_sleep()

    # Are we at the setup page now?
    assert_that(browser.url, ends_with("#/setup"))

    # If we go back to Advanced Options, is the button disabled?
    splinter_tests.visit("#/advanced")

    do_sleep()

    button = find_delete_button()
    assert button.first['disabled']
Example #28
0
def do_check_device_list(test_user):
    # Do a fresh login
    log_in_clean(*test_user.auth)

    # Navigate to the Devices page
    splinter_tests.visit("/#/devices")
    do_sleep(multiplier=0.5)

    assert_that(browser.title, starts_with("XBee Gateways in your account"))

    # Make sure we didn't get redirected away or anything
    assert_that(browser.url, ends_with("#/devices"))

    # Check the contents of the page
    assert browser.is_text_present("XBee Gateways in your account")
    assert not browser.find_link_by_text("Manage Devices").is_empty()

    # Allow the device list fetch to complete. (Should be wicked fast on
    # integration test backend.)
    do_sleep(multiplier=0.5)

    def check_devices():
        for device in test_user.devices['items']:
            assert browser.is_text_present(device['devConnectwareId'])
            if device.get('dpDescription'):
                assert browser.is_text_present(device['dpDescription'])

            # Check the connection status indicator is correct.
            conn_status = device.get('dpConnectionStatus', "0")

            conn_image = "device_disconnected.png"

            try:
                if int(conn_status):
                    conn_image = "device_connected.png"
            except (ValueError, TypeError):
                pass

            # Find the image. This XPath ensures that the connection status
            # image is in the cell immediately before the device ID.
            xpath = '//td[.="{}"]/preceding-sibling::td[1]/img'
            xpath = xpath.format(device['devConnectwareId'])
            img = browser.find_by_xpath(xpath)
            assert not img.is_empty()
            assert_that(len(img), is_(1))

            assert_that(img.first['src'], ends_with(conn_image))

    # Check the device list right now
    check_devices()

    # Refresh the list, check it again.
    ref_button = browser.find_by_xpath('//button[contains(., "Refresh List")]')
    assert not ref_button.is_empty()
    ref_button.click()
    # Wait for list to load
    do_sleep()
    # Check the list again
    check_devices()
Example #29
0
def go(api: twitter.api.Api, start_user: str) -> collections.Counter:
    # sanity check
    utils.verify(api)
    LOGGER.info(utils.get_rate_limit(api))

    # {'user screen name': 'count'}
    stats: Counter = collections.Counter()

    friends = utils.get_friends(api, start_user)
    LOGGER.info('%s has %d friends', start_user, len(friends))

    for u in tqdm(friends):
        LOGGER.info(
            '@%s (following %d, followers %d) => %s',
            u.screen_name, u.friends_count, u.followers_count, u.name
        )
        stats[u.screen_name] += 1

        for u2 in utils.get_friends(api, u.screen_name):
            stats[u2.screen_name] += 1

        utils.do_sleep()

    return stats
def test_page_no_xbees():
    """Node table should remain empty if no XBees are found."""
    splinter_tests.visit("/#/xbee_network")

    assert browser.is_text_present("XBee Network View")

    # Since this user has more than one gateway, it shouldn't auto-select one.
    gw_select = browser.find_by_css('select#gateway')
    assert not gw_select.is_empty()  # Check that the select box is present
    assert_that(gw_select.first.value, is_("?"))

    # Pick the first gateway
    browser.select("gateway", "0")
    do_sleep()

    # 'Fetch from' select box should be visible now
    assert browser.is_text_present("Fetch from:")
    # 'Device Cloud' is automatically selected
    fetch_from = browser.find_by_css('select#fetch_from')
    assert not fetch_from.is_empty()
    assert_that(fetch_from.first.value, is_("dc"))

    # Nodes table should be empty
    assert browser.find_by_css('table.network-table tbody tr').is_empty()
def test_refresh_xbee_list():
    """Clicking the XBee 'Refresh List' button clears selection, etc."""
    # Pick this user's one gateway
    browser.select("inputDevice", "0")

    # Wait for XBee list to populate
    do_sleep()

    # Get the test_user's remote XBees, count them
    test_xbees = (x for x in get_e2e_user('test_user').xbees['items']
                  if int(x.get('xpNetAddr', 0)))
    num_xbees = len(list(test_xbees))

    xbee_count = len(browser.find_by_css('select#inputRadio option'))
    assert_that(xbee_count, is_(num_xbees + 1))  # some XBees, one empty option
    # The first option in the list is the empty option
    first = browser.find_by_css('select#inputRadio option:first-of-type')
    assert not first.is_empty()
    assert_that(first.value, is_(""))
    assert first.selected

    cbutton = browser.find_by_name("createDash").first

    # No XBees should have been selected yet, so no create dashboard button
    assert not cbutton.visible

    # Pick the first XBee in the list
    browser.select("inputRadio", "0");

    # Step 4, configuring the radio should show up.
    assert browser.is_text_present(STEP_TITLES[4])
    # Wait for configuration check to complete
    do_sleep()

    # If we click Refresh List, the selection should be cleared out
    button = browser.find_by_name("refreshXbees")
    assert not button.is_empty()
    button.click()
    # Step 4 should go away then
    assert not browser.is_text_present(STEP_TITLES[4])

    do_sleep()

    # Check XBee node list again, and the selection
    xbee_count = len(browser.find_by_css('select#inputRadio option'))
    assert_that(xbee_count, is_(num_xbees + 1))  # some XBees, one empty option
    # The first option in the list is the empty option
    first = browser.find_by_css('select#inputRadio option:first-of-type')
    assert not first.is_empty()
    assert_that(str(first.value), is_(""))
    assert first.selected
def test_refresh_xbee_list():
    """Clicking the XBee 'Refresh List' button clears selection, etc."""
    # Pick this user's one gateway
    browser.select("inputDevice", "0")

    # Wait for XBee list to populate
    do_sleep()

    # Get the test_user's remote XBees, count them
    test_xbees = (x for x in get_e2e_user('test_user').xbees['items']
                  if int(x.get('xpNetAddr', 0)))
    num_xbees = len(list(test_xbees))

    xbee_count = len(browser.find_by_css('select#inputRadio option'))
    assert_that(xbee_count, is_(num_xbees + 1))  # some XBees, one empty option
    # The first option in the list is the empty option
    first = browser.find_by_css('select#inputRadio option:first-of-type')
    assert not first.is_empty()
    assert_that(first.value, is_(""))
    assert first.selected

    cbutton = browser.find_by_name("createDash").first

    # No XBees should have been selected yet, so no create dashboard button
    assert not cbutton.visible

    # Pick the first XBee in the list
    browser.select("inputRadio", "0")

    # Step 4, configuring the radio should show up.
    assert browser.is_text_present(STEP_TITLES[4])
    # Wait for configuration check to complete
    do_sleep()

    # If we click Refresh List, the selection should be cleared out
    button = browser.find_by_name("refreshXbees")
    assert not button.is_empty()
    button.click()
    # Step 4 should go away then
    assert not browser.is_text_present(STEP_TITLES[4])

    do_sleep()

    # Check XBee node list again, and the selection
    xbee_count = len(browser.find_by_css('select#inputRadio option'))
    assert_that(xbee_count, is_(num_xbees + 1))  # some XBees, one empty option
    # The first option in the list is the empty option
    first = browser.find_by_css('select#inputRadio option:first-of-type')
    assert not first.is_empty()
    assert_that(str(first.value), is_(""))
    assert first.selected
def test_create_dashboard():
    """Test out straight-through setting up dashboard."""
    assert browser.is_text_present(STEP_TITLES[1])
    assert browser.is_text_present(STEP_TITLES[2])

    # Select the first gateway
    browser.select("inputDevice", "0")

    # Wait for XBee list to populate
    do_sleep()

    assert browser.is_text_present(STEP_TITLES[3])
    # Select the first XBee
    browser.select("inputRadio", "0")

    assert browser.is_text_present(STEP_TITLES[4])
    # Wait for configuration check to go through.
    do_sleep(multiplier=2)
    if browser.find_by_id("configureRadio").first.visible:
        # Skip reconfiguration
        skip_button = browser.find_by_id("skipConfig")
        skip_button.click()
    elif browser.is_text_present("An error occurred"):
        # Error. Fail out.
        raise Exception("Configuration check had an error.")
    else:
        # Configuration check is really slow.
        import time
        now = time.time()
        while time.time() < now + 10:
            if browser.is_text_present("radio is configured", wait_time=1):
                break
            elif browser.is_text_present("An error occurred"):
                raise Exception("Configuration check had an error.")
        else:
            # Configuration check was too slow, or something else is wrong
            raise Exception("Configuration check never completed?")

    # hit the 'Create Dashboard!' button, check that it worked
    cbutton = browser.find_by_name("createDash")
    assert cbutton.first.visible

    cbutton.click()
    do_sleep()

    assert_that(browser.url, ends_with("#/dashboard"))
    # Make sure some of the expected widgets are visible
    assert browser.is_text_present("Potentiometer")
    assert browser.is_text_present("Buzzer Toggle")
def test_create_dashboard():
    """Test out straight-through setting up dashboard."""
    assert browser.is_text_present(STEP_TITLES[1])
    assert browser.is_text_present(STEP_TITLES[2])

    # Select the first gateway
    browser.select("inputDevice", "0")

    # Wait for XBee list to populate
    do_sleep()

    assert browser.is_text_present(STEP_TITLES[3])
    # Select the first XBee
    browser.select("inputRadio", "0")

    assert browser.is_text_present(STEP_TITLES[4])
    # Wait for configuration check to go through.
    do_sleep(multiplier=2)
    if browser.find_by_id("configureRadio").first.visible:
        # Skip reconfiguration
        skip_button = browser.find_by_id("skipConfig")
        skip_button.click()
    elif browser.is_text_present("An error occurred"):
        # Error. Fail out.
        raise Exception("Configuration check had an error.")
    else:
        # Configuration check is really slow.
        import time
        now = time.time()
        while time.time() < now + 10:
            if browser.is_text_present("radio is configured", wait_time=1):
                break
            elif browser.is_text_present("An error occurred"):
                raise Exception("Configuration check had an error.")
        else:
            # Configuration check was too slow, or something else is wrong
            raise Exception("Configuration check never completed?")

    # hit the 'Create Dashboard!' button, check that it worked
    cbutton = browser.find_by_name("createDash")
    assert cbutton.first.visible

    cbutton.click()
    do_sleep()

    assert_that(browser.url, ends_with("#/dashboard"))
    # Make sure some of the expected widgets are visible
    assert browser.is_text_present("Potentiometer")
    assert browser.is_text_present("Buzzer Toggle")
def test_add_device():
    """Test out adding a device to a user's account."""
    # Pick Cloud Kit dashboard
    browser.select("inputDashboard", "0")

    # Step 1 and Step 2 should be visible now
    assert browser.is_text_present(STEP_TITLES[1])
    assert browser.is_text_present(STEP_TITLES[2])

    # Wait a moment for the devices fetch to work.
    do_sleep()

    # Make sure no devices are selected.
    # (This user has no devices in their account anyway.)
    assert_that(browser.find_by_name("inputDevice").first.value, is_(""))

    # check that the Create Dashboard button is not visible
    button_xpath = '//button[contains(., "Create Dashboard!")]'
    cbutton = browser.find_by_xpath(button_xpath)
    assert not cbutton.is_empty()
    assert not cbutton.first.visible

    # Click 'Add New Device' button
    add_new_button = browser.find_by_name("addDevice")
    assert not add_new_button.is_empty()
    add_new_button.click()

    # Check that the modal has appeared.
    assert browser.is_text_present(NEW_DEVICE_MODAL_TITLE, 1)
    assert browser.is_text_present("What's This?")

    # Click 'Cancel' button
    browser.find_by_xpath('//button[.="Cancel"]').first.click()
    # Check that the modal has disappeared.
    assert not browser.is_text_present(NEW_DEVICE_MODAL_TITLE, 1)
    assert not browser.is_text_present("What's This?")

    # Click 'Add New Device' button again.
    add_new_button.click()
    # Check that the modal has appeared.
    assert browser.is_text_present(NEW_DEVICE_MODAL_TITLE, 1)
    assert browser.is_text_present("What's This?")

    # Check that the "Add Device" button is disabled
    button = browser.find_by_xpath('//button[contains(., "Add Device")]')
    assert not button.is_empty()
    assert button.first['disabled'], "Add Device button isn't disabled!"

    add_button = button

    # Check that the serial number field has 00409D pre-filled
    assert_that(browser.find_by_name("input_mac").first['placeholder'],
                is_("00409D ______"))

    # Enter some non-numeric characters in the serial number field
    browser.fill("input_mac", "zanzibar")
    assert add_button.first['disabled'], "Add Device button isn't disabled!"

    # Enter valid characters
    browser.fill("input_mac", "665544")
    assert not add_button.first['disabled'], "Add Device button isn't enabled!"
    # Enter description
    browser.fill("input_desc", "Integration test device description")

    # Click the button
    add_button.click()

    # Wait a moment while the POST happens. We'll know it worked when the
    # notification comes up. (Wait up to 10 seconds)
    assert browser.is_text_present("provisioned to your Device Cloud account",
                                   wait_time=10)
    # We then attempt configuration. Wait for that to pass. Should only take a
    # moment
    do_sleep(multiplier=3)

    # Check that the modal has disappeared.
    assert not browser.is_text_present(NEW_DEVICE_MODAL_TITLE)
    assert not browser.is_text_present("What's This?")

    # We should have automatically selected the new device.
    sel_value = str(browser.find_by_name("inputDevice").first.value)
    assert_that(sel_value, is_not(""))
Example #36
0
def delete_facts(fact_ids):
    ers = Eraser()
    ers.erase_facts(fact_ids)
    test_utils.do_sleep(3, msg='Deleting')
Example #37
0
def delete_node(node_ids):
    ers = Eraser()
    ers.erase_nodes(node_ids)
    test_utils.do_sleep(2, msg='Deleting Node')
Example #38
0
def test_add_widget_simple():
    # First, make sure we're at the dashboard page.
    # (Note: We want the first thing we do in this test function to be a yield,
    # so that later asserts which aren't contained in yielded functions are not
    # executed when nose runs this function to acquire the generator.)
    yield check_we_are_at_dashboard_page

    # Click 'Add Widget' (also checks that we end up on the 'Create a new
    # Widget' page)
    yield click_add_widget

    # If we click Cancel, do we end up back on the dashboard page?
    yield click_cancel

    # Return to Add Widget page
    yield click_add_widget

    # Open the username menu, so we can check the links
    expand_username_menu()

    # Verify the 'Devices', 'Advanced Options' and 'Manage Account' links
    yield do_check_link("Devices", splinter_tests.SERVER_URL + "/#/devices")
    yield do_check_link("Advanced Options",
                        splinter_tests.SERVER_URL + "/#/advanced")
    yield do_check_link("Manage Account", "https://login.etherios.com/home.do")

    # 'Cancel' should bring us back to the dashboard
    yield click_cancel

    # 'Add Widget' should bring us back there
    yield click_add_widget

    # Verify all the other links that should be on this page.
    for linktext, url in get_general_page_links():
        yield do_check_link(linktext, url)

    # Wait for Angular to catch up to us (specifically, to allow Angular to
    # fetch the user's devices and populate the selection box)
    do_sleep()

    # Test how selecting a gateway changes the error state on the page
    # TODO Should this go in something like test_add_widget_page?

    gateway_selection_row = browser.find_by_xpath(
        # Find the 'select' with name 'device', get its grandparent
        '//select[@name = "device"]/../..')
    assert not gateway_selection_row.is_empty()
    assert gateway_selection_row.first.has_class('has-error')

    # There should also be some error text near the top of the page
    # Find the list item with a bold "Gateway:" string inside it
    err_item_xpath = ("//div[contains(@class, 'alert alert-danger')]/ul/li"
                      "/strong[.='Gateway:']/..")
    gateway_error = browser.find_by_xpath(err_item_xpath)
    assert not gateway_error.is_empty()
    # Check that this item is visible on the page
    assert gateway_error.first.visible
    # The error should be 'You need to select a gateway'
    assert_that("You need to select a gateway", is_in(gateway_error.text))

    # If we select a gateway, the has-error class should go away
    # test_user has only one device, so select value 0
    browser.select("device", "0")

    assert not gateway_selection_row.first.has_class('has-error')
    # The error should also disappear
    # The 'Gateway:' error item is only hidden when the value becomes valid,
    # and not destroyed, so we can reuse the gateway_error variable from above
    assert not gateway_error.first.visible
def test_add_widget_simple():
    # First, make sure we're at the dashboard page.
    # (Note: We want the first thing we do in this test function to be a yield,
    # so that later asserts which aren't contained in yielded functions are not
    # executed when nose runs this function to acquire the generator.)
    yield check_we_are_at_dashboard_page

    # Click 'Add Widget' (also checks that we end up on the 'Create a new
    # Widget' page)
    yield click_add_widget

    # If we click Cancel, do we end up back on the dashboard page?
    yield click_cancel

    # Return to Add Widget page
    yield click_add_widget

    # Open the username menu, so we can check the links
    expand_username_menu()

    # Verify the 'Devices', 'Advanced Options' and 'Manage Account' links
    yield do_check_link("Devices", splinter_tests.SERVER_URL + "/#/devices")
    yield do_check_link("Advanced Options",
                        splinter_tests.SERVER_URL + "/#/advanced")
    yield do_check_link("Manage Account", "https://login.etherios.com/home.do")

    # 'Cancel' should bring us back to the dashboard
    yield click_cancel

    # 'Add Widget' should bring us back there
    yield click_add_widget

    # Verify all the other links that should be on this page.
    for linktext, url in get_general_page_links():
        yield do_check_link(linktext, url)

    # Wait for Angular to catch up to us (specifically, to allow Angular to
    # fetch the user's devices and populate the selection box)
    do_sleep()

    # Test how selecting a gateway changes the error state on the page
    # TODO Should this go in something like test_add_widget_page?

    gateway_selection_row = browser.find_by_xpath(
        # Find the 'select' with name 'device', get its grandparent
        '//select[@name = "device"]/../..')
    assert not gateway_selection_row.is_empty()
    assert gateway_selection_row.first.has_class('has-error')

    # There should also be some error text near the top of the page
    # Find the list item with a bold "Gateway:" string inside it
    err_item_xpath = ("//div[contains(@class, 'alert alert-danger')]/ul/li"
                      "/strong[.='Gateway:']/..")
    gateway_error = browser.find_by_xpath(err_item_xpath)
    assert not gateway_error.is_empty()
    # Check that this item is visible on the page
    assert gateway_error.first.visible
    # The error should be 'You need to select a gateway'
    assert_that("You need to select a gateway", is_in(gateway_error.text))

    # If we select a gateway, the has-error class should go away
    # test_user has only one device, so select value 0
    browser.select("device", "0")

    assert not gateway_selection_row.first.has_class('has-error')
    # The error should also disappear
    # The 'Gateway:' error item is only hidden when the value becomes valid,
    # and not destroyed, so we can reuse the gateway_error variable from above
    assert not gateway_error.first.visible
def test_add_device():
    """Test out adding a device to a user's account."""
    # Pick Cloud Kit dashboard
    browser.select("inputDashboard", "0")

    # Step 1 and Step 2 should be visible now
    assert browser.is_text_present(STEP_TITLES[1])
    assert browser.is_text_present(STEP_TITLES[2])

    # Wait a moment for the devices fetch to work.
    do_sleep()

    # Make sure no devices are selected.
    # (This user has no devices in their account anyway.)
    assert_that(browser.find_by_name("inputDevice").first.value, is_(""))

    # check that the Create Dashboard button is not visible
    button_xpath = '//button[contains(., "Create Dashboard!")]'
    cbutton = browser.find_by_xpath(button_xpath)
    assert not cbutton.is_empty()
    assert not cbutton.first.visible

    # Click 'Add New Device' button
    add_new_button = browser.find_by_name("addDevice")
    assert not add_new_button.is_empty()
    add_new_button.click()

    # Check that the modal has appeared.
    assert browser.is_text_present(NEW_DEVICE_MODAL_TITLE, 1)
    assert browser.is_text_present("What's This?")

    # Click 'Cancel' button
    browser.find_by_xpath('//button[.="Cancel"]').first.click()
    # Check that the modal has disappeared.
    assert not browser.is_text_present(NEW_DEVICE_MODAL_TITLE, 1)
    assert not browser.is_text_present("What's This?")

    # Click 'Add New Device' button again.
    add_new_button.click()
    # Check that the modal has appeared.
    assert browser.is_text_present(NEW_DEVICE_MODAL_TITLE, 1)
    assert browser.is_text_present("What's This?")

    # Check that the "Add Device" button is disabled
    button = browser.find_by_xpath('//button[contains(., "Add Device")]')
    assert not button.is_empty()
    assert button.first['disabled'], "Add Device button isn't disabled!"

    add_button = button

    # Check that the serial number field has 00409D pre-filled
    assert_that(
        browser.find_by_name("input_mac").first['placeholder'],
        is_("00409D ______"))

    # Enter some non-numeric characters in the serial number field
    browser.fill("input_mac", "zanzibar")
    assert add_button.first['disabled'], "Add Device button isn't disabled!"

    # Enter valid characters
    browser.fill("input_mac", "665544")
    assert not add_button.first['disabled'], "Add Device button isn't enabled!"
    # Enter description
    browser.fill("input_desc", "Integration test device description")

    # Click the button
    add_button.click()

    # Wait a moment while the POST happens. We'll know it worked when the
    # notification comes up. (Wait up to 10 seconds)
    assert browser.is_text_present("provisioned to your Device Cloud account",
                                   wait_time=10)
    # We then attempt configuration. Wait for that to pass. Should only take a
    # moment
    do_sleep(multiplier=3)

    # Check that the modal has disappeared.
    assert not browser.is_text_present(NEW_DEVICE_MODAL_TITLE)
    assert not browser.is_text_present("What's This?")

    # We should have automatically selected the new device.
    sel_value = str(browser.find_by_name("inputDevice").first.value)
    assert_that(sel_value, is_not(""))