def get_token(): """ Get the access token :return string """ refresh_token = Config.get_config(Config.FIELD_REFRESH_TOKEN) if refresh_token: client_id = Config.get_config(Config.FIELD_CLIENT_ID) client_secret = Config.get_config(Config.FIELD_CLIENT_SECRET) auth_data = { "client_id": client_id, "client_secret": client_secret, "refresh_token": refresh_token, "grant_type": "refresh_token" } result = requests.post(AlexaService.AMAZON_TOKEN_URL, data=auth_data) resp = json.loads(result.text) Config.save_config(Config.FIELD_ACCESS_TOKEN, resp['refresh_token']) return resp['access_token'] else: return False
def code(self, var=None, **params): """ The code page """ client_id = Config.get_config(Config.FIELD_CLIENT_ID) client_secret = Config.get_config(Config.FIELD_CLIENT_SECRET) code = urllib.quote(cherrypy.request.params['code']) callback = cherrypy.url() payload = { "client_id": client_id, "client_secret": client_secret, "code": code, "grant_type": "authorization_code", "redirect_uri": callback } result = requests.post(AlexaService.AMAZON_TOKEN_URL, data=payload) result = result.json() # Save the refresh token and reset access token Config.save_config(Config.FIELD_REFRESH_TOKEN, format(result['refresh_token'])) Config.save_config(Config.FIELD_ACCESS_TOKEN, "") html = "<b>Success!</b><br/>" html += "Refresh token has been added to your credentials file.<br/>" html += "You may now reboot the Pi or restart the service.<br/>" html += "Your token: %s" % result['refresh_token'] return html
def index(self): """ The main page """ product_id = Config.get_config(Config.FIELD_PRODUCT_ID) client_id = Config.get_config(Config.FIELD_CLIENT_ID) scope_data = json.dumps({ "alexa:all": { "productID": product_id, "productInstanceAttributes": { "deviceSerialNumber": "001" } } }) callback = cherrypy.url() + "code" payload = { "client_id": client_id, "scope": "alexa:all", "scope_data": scope_data, "response_type": "code", "redirect_uri": callback } req = requests.Request('GET', AlexaService.AMAZON_BASE_URL, params=payload) raise cherrypy.HTTPRedirect(req.prepare().url)
def root(): """ Main page :return: string """ # Weather zip_code = Config.get_config( Config.WEATHER_SECTION, Config.FIELD_API_KEY_ZIP_CODE ) refresh_rate_weather = Config.get_config( Config.WEATHER_SECTION, Config.FIELD_REFRESH_RATE ) # Get date and time extra_clocks_1 = {} extra_clocks_2 = {} clock_timezone_1 = Config.get_config( Config.DATETIME_SECTION, Config.FIELD_DATE_TIME_1_TIMEZONE ) clock_label_1 = Config.get_config( Config.DATETIME_SECTION, Config.FIELD_DATE_TIME_1_LABEL ) clock_timezone_2 = Config.get_config( Config.DATETIME_SECTION, Config.FIELD_DATE_TIME_2_TIMEZONE ) clock_label_2 = Config.get_config( Config.DATETIME_SECTION, Config.FIELD_DATE_TIME_2_LABEL ) if clock_timezone_1 != "": extra_clocks_1['timezone'] = clock_timezone_1 extra_clocks_1['label'] = clock_label_1 if clock_timezone_2 != "": extra_clocks_2['timezone'] = clock_timezone_2 extra_clocks_2['label'] = clock_label_2 # News refresh_rate_news = Config.get_config( Config.NEWS_SECTION, Config.FIELD_REFRESH_RATE ) return render_template( 'index.html', ZIP_CODE=zip_code, CLOCK_1=extra_clocks_1, CLOCK_2=extra_clocks_2, REFRESH_RATE_WEATHER=int(refresh_rate_weather), REFRESH_RATE_NEWS=int(refresh_rate_news) )
def get_url(zip_code, mode): """ Get the API URL :param zip_code: The zip code :param mode: The mode :return: string """ api_key = Config.get_config(Config.WEATHER_SECTION, Config.FIELD_API_KEY_WEATHER) url = Weather.BASE_URL + mode + \ "?zip=" + str(zip_code) + ",us&" + \ "&appid=" + api_key + "&" + \ "units=" + Weather.UNITS return url
import os, time import requests from selenium import webdriver from behave import given, then, when from lib.Config import Config from support.Case_1_Page import Case_1_Page from support.SkyEng_Login_Page import SkyEng_Login_Page from selenium.common.exceptions import TimeoutException from selenium.webdriver.common.keys import Keys cf = Config() cs = Case_1_Page() lg = SkyEng_Login_Page() skyengprod = cf.get_config('config/config.ini', 'links', 'skyengprod') skyengstaging = cf.get_config('config/config.ini', 'links', 'skyengstaging') @then(u'I select New Student') def step_impl(context): cs.new_student(context) time.sleep(3) print(cs.new_student_mode_title(context)) assert cs.new_student_mode_title(context) == "New Student mode" @then(u'I select options General English, Beginner, 1st lesson') def step_impl(context): cs.mode_general(context) cs.mode_level_beginner(context) time.sleep(2) cs.mode_lesson_1(context)
import os, time, random from behave import given, then, when from lib.Config import Config from support.Search_Page import Search from selenium.webdriver.common.keys import Keys cf = Config() sp = Search() baaqmd_qa_eng = cf.get_config('config/config.ini', 'search', 'baaqmd_qa_eng') baaqmd_prod_main_eng = cf.get_config('config/config.ini', 'search', 'baaqmd_prod_main_eng') @given(u"I navigate to STA SMS Form page") def step_impl(context): #if (os.environ['location'] == "qa"): # context.browser.get(baaqmd_qa_eng) #elif (os.environ['location'] == "prod"): context.browser.get(baaqmd_prod_main_eng) time.sleep(3) @when(u'I fill telephone number in phone field') def step_impl(context): sp.phone_field_click(context) sp.phone_field_click(context) sp.phone_field(context).send_keys("4154948693") time.sleep(4)
import os,time,random from selenium import webdriver from behave import given, then, when from support.Gmail_Page import Login from support.Gmail_Page import Inbox from functions.Gmail_Login import Gmail_Login from lib.Config import Config cf = Config() gmail = Gmail_Login() inbox = Inbox() login = Login() url = cf.get_config('config/config.ini','gmail', 'url') logout = cf.get_config('config/config.ini','gmail', 'logout') @given(u'I sing in to Gmail') def impl(context): gmail.signin(context) time.sleep(3) @when(u'I click on the Compose Button') def step_impl(context): inbox.composebutton(context) time.sleep(2) assert inbox.composedialog(context) @then(u'I sign-Out from the gmail account') def step_impl(context): gmail.logout(context)
import os, time from selenium import webdriver from behave import given, then, when from lib.Config import Config from functions.Vimbox_Login import Vimbox_Login from support.Vimbox_Login_Page import Vimbox_Login_Page from selenium.common.exceptions import TimeoutException cf = Config() log = Vimbox_Login() lg = Vimbox_Login_Page() vimboxstaging = cf.get_config('config/config.ini', 'links', 'vimboxstaging') vimboxprod = cf.get_config('config/config.ini', 'links', 'vimboxprod') @given(u'I navigate to Vimbox login page') def step_impl(context): if (os.environ['location'] == "staging"): context.browser.get(vimboxstaging) elif (os.environ['location'] == "prod"): context.browser.get(vimboxprod) time.sleep(3) #print(lg.header_login(context)) #assert (lg.header_login(context)).is_displayed() #@when(u'I log in with "*****@*****.**" and "111111"') @when(u'I log in with "{email}" and "{password}"') def step_impl(context, email, password): try: