Skip to content

Commit

Permalink
fixed pylint; fixed selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksym Shalenyi committed Apr 2, 2015
1 parent 8a2843f commit d61923d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
29 changes: 17 additions & 12 deletions hangout_api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
from selenium.webdriver.common.keys import Keys
from time import sleep

from selenium.webdriver.remote.remote_connection import LOGGER
import logging
LOGGER.setLevel(logging.WARNING) # reducing selenium verbosity

from .utils import (
Utils,
URLS,
Expand All @@ -32,6 +28,10 @@
from .exceptions import LoginError
from .interfaces import IModule, IOnAirModule

from selenium.webdriver.remote.remote_connection import LOGGER
import logging
LOGGER.setLevel(logging.WARNING) # reducing selenium verbosity


@retry(stop_max_attempt_number=3)
def _create_hangout_event(browser, name, attendees):
Expand All @@ -41,7 +41,7 @@ def _create_hangout_event(browser, name, attendees):
visitor is logged in
"""
browser.get(URLS.onair)
browser.by_text('Start a Hangout On Air').click(TIMEOUTS.fast)
browser.by_text('Create a Hangout On Air').click(TIMEOUTS.fast)
# Setting name
browser.xpath(
'//input[@aria-label="Give it a name"]').send_keys(name)
Expand Down Expand Up @@ -128,7 +128,7 @@ def __init__(self, executable_path=None, chrome_options=None):
kwargs = {'executable_path': executable_path or CHROMEDRV_PATH}
if chrome_options is not None:
kwargs['chrome_options'] = chrome_options
# pylint: disable=W0142

self.browser = selwrap.create('chrome', **kwargs)

self.utils = Utils(self.browser)
Expand Down Expand Up @@ -179,7 +179,8 @@ def start(self, on_air=None):
self.browser.get(URLS.hangouts_active_list)
# G+ opens new window for new hangout, so we need to
# switch selenium to it
self.browser.by_class('opd').click(timeout=TIMEOUTS.fast)
self.browser.by_text(
'Start a video Hangout').click(timeout=TIMEOUTS.fast)

# waiting until new window appears
tries_n_time_until_true(
Expand Down Expand Up @@ -302,13 +303,17 @@ def participants(self):
.. doctest:: HangoutsBase
>>> hangout.participants()
[Participant(name='John Doe', profile_id='108775712935'), ...]
[Participant(name='John Doe', profile_id='108775712935')]
"""
xpath = '//div[@data-userid]'
participants = self.browser.xpath(xpath, eager=True)
return [Participant(p.get_attribute('aria-label')[5:-11],
p.get_attribute('data-userid'))
for p in participants]
# for some reason some persons can be listed twice, so let's
# filter them with dict
participants = {
p.get_attribute('data-userid'): p.get_attribute(
'aria-label')[5:-11]
for p in self.browser.xpath(xpath, eager=True)}
return [Participant(name=pname, profile_id=pid)
for pid, pname in participants.items()]

@retry(stop_max_attempt_number=3)
def disconnect(self):
Expand Down
16 changes: 9 additions & 7 deletions hangout_api/tests/TestBaseAPI.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import operator
import unittest
from testfixtures import compare, ShouldRaise
from hangout_api.utils import Participant
Expand Down Expand Up @@ -41,14 +42,15 @@ def test_participants(self):
users = [[credentials['name_2'], credentials['password_2']],
[credentials['name_3'], credentials['password_3']]]
with hangouts_connection_manager(users, self.hangout.hangout_id):
sleep(5) # lets give some time to make sure that google add all
sleep(10) # lets give some time to make sure that google add all
# participants to hangout
participants = self.hangout.participants()
participants.sort(key=operator.attrgetter('profile_id'))
compare(
participants,
[Participant(name='John Doe',
profile_id='108775712935793912532'),
Participant(name='Lorem Impus',
profile_id='115041713348329690244'),
Participant(name='Gilgamesh Bot',
profile_id='108572696173264293426')])
[Participant(profile_id='108572696173264293426',
name='Gilgamesh Bot'),
Participant(profile_id='108775712935793912532',
name='John Doe'),
Participant(profile_id='115041713348329690244',
name='Lorem Impus')])
10 changes: 7 additions & 3 deletions hangout_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,13 @@ def is_logged_in(self):
if user loged in or not.
"""
def _is_logged_in():
self.browser.current_url.startswith(URLS.plus_main) or \
self.browser.current_url.startswith(URLS.personalinfo) or \
self.browser.current_url.startswith(URLS.my_account_page)
"""
simple function wrapper to check in user is logged in
"""
return \
self.browser.current_url.startswith(URLS.plus_main) or \
self.browser.current_url.startswith(URLS.personalinfo) or \
self.browser.current_url.startswith(URLS.my_account_page)
return tries_n_time_until_true(_is_logged_in)

@retry(stop_max_attempt_number=3)
Expand Down

0 comments on commit d61923d

Please sign in to comment.