def test_config_returns_url_with_port_and_subdomain(self): cf = config.Config() cf.base_url = self.test_url cf.subdomain = self.test_sub_domain cf.port = self.test_port val_to_test = 'http://' + self.test_sub_domain + '.' + self.test_url + ':' + self.test_port self.assertEqual(cf.url(), val_to_test)
def test_config_returns_url_with_subdomain(self): cf = config.Config() cf.base_url = self.test_url cf.subdomain = self.test_sub_domain cf.port = '' self.assertEqual( cf.url(), 'http://' + self.test_sub_domain + '.' + self.test_url)
def test_config_returns_url_with_port_only(self): cf = config.Config() cf.base_url = self.test_url cf.subdomain = '' cf.port = self.test_port self.assertEqual(cf.url(), 'http://' + self.test_url + ':' + self.test_port)
class TestFeature(unittest.TestCase): cf = config.Config() cf.base_url = 'erikwhiting.com' cf.subdomain = '' cf.base_url += '/newsOutlet' def test_write_and_click_with_headless(self): self.cf.options_list = ["headless"] bp = page.Page(self.cf) bp.go() bp.element_by("id", "sourceNews").input_text("Hello") bp.element_by("id", "transmitter").click() english_div = helper.evaluate_element_text(bp.element_by("id", "en1"), "Hello") self.assertTrue(english_div) bp.close() def test_page_source_feature(self): self.cf.options_list = ["headless"] bp = page.Page(self.cf) bp.go() source = bp.page_source() self.assertIn('<body onload="defaultBreaking()">', source) def test_page_url(self): self.cf.options_list = ["headless"] bp = page.Page(self.cf) bp.go() current_url = bp.get_url() if current_url[current_url.__len__() - 1] == "/": current_url = current_url[:-1] self.assertEqual(self.cf.url(), current_url)
def parse_income_sheet(): conf = config.Config('income_responses') json_key = json.load(open(conf.key)) scope = ['https://spreadsheets.google.com/feeds'] credentials = SignedJwtAssertionCredentials( json_key['client_email'], bytes(json_key['private_key'], 'UTF-8'), scope) session = gspread.authorize(credentials) workbook = session.open_by_key(conf.workbook) worksheet = workbook.worksheet(conf.worksheet) worksheet_values = worksheet.get_all_values() export_directory = os.path.join(os.path.dirname(__file__), 'exports') export_filename = 'export_{0}.csv'.format( datetime.datetime.today().strftime('%Y-%m-%d_%H:%M:%S')) export_path = os.path.join(export_directory, export_filename) # Append feed source to each row in the export. for row in worksheet_values: row.append(export_filename) with open(export_path, 'w') as f: writer = csv.writer(f) writer.writerows(worksheet_values) return 0
def get_list_of_feeds(): feeds = [] conf = config.Config('income') for feed in glob.glob(os.path.join(conf.exports_directory, '*.csv')): feeds.append(feed) return feeds
def __init__(self, entry): self.amount = entry.amount self.category = entry.category self.notes = entry.notes self.conf = config.Config('income_form') self.submission = { 'entry.1788911046': self.amount, 'entry.22851461': '__other_option__', 'entry.22851461.other_option_response': self.category, 'entry.1728679999': self.notes } self.response_code = None
def psql_call(query, logger): conf = config.Config('database') con = None try: con = psycopg2.connect(database=conf.database, user=conf.user, password=conf.password) cur = con.cursor() cur.execute(query) con.commit() except psycopg2.DatabaseError as exception: logger.critical(exception) raise exception finally: if con: con.close()
def test_calculator_page(self): cf = config.Config() cf.http_prefix = 'http://' cf.base_url = 'www.math.com/' cf.base_url += 'students/calculators/source/basic.htm' cf.options_list.append("headless") bp = page.Page(cf) bp.go() bp.element_by("name", "five").click() bp.element_by("name", "plus").click() bp.element_by("name", "seven").click() bp.element_by("name", "DoIt").click() answer = bp.element_by("name", "Input").get("value") self.assertEqual(answer, "12") bp.close()
class TestBasePage(unittest.TestCase): cf = config.Config() cf.driver = 'TestDriver' cf.base_url = 'TestMe.com' def test_base_page_returns_config_url(self): bp = page.Page(self.cf) self.assertEqual(bp.url, self.cf.url()) def test_base_page_returns_config_url_with_sub_dir(self): bp = page.Page(self.cf, 'about') self.assertEqual(bp.url, self.cf.url() + '/about') def test_page_knows_its_headless(self): self.cf.options_list = ['headless'] bp = page.Page(self.cf) self.assertIn("headless", bp.options_list) def test_page_knows_its_not_headless(self): self.cf.options_list = [] bp = page.Page(self.cf) self.assertNotIn("headless", bp.options_list)
def parse_entries_sheet(): conf = config.Config('income_entries') json_key = json.load(open(conf.key)) scope = ['https://spreadsheets.google.com/feeds'] credentials = SignedJwtAssertionCredentials( json_key['client_email'], bytes(json_key['private_key'], 'UTF-8'), scope) session = gspread.authorize(credentials) workbook = session.open_by_key(conf.workbook) worksheet = workbook.worksheet(conf.worksheet) # Parse row-by-row until an empty row is encountered (data starts on second row). row_index = 2 entries = [] while worksheet.row_values(row_index) and row_index <= worksheet.row_count: row = worksheet.row_values(row_index) entry = create_entry(row) entries.append(entry) row_index += 1 return entries
def __init__(self): """ TODO Make this useful. This is a method of Service. """ self.config = config.Config('email_service')
def test_config_returns_basic_url(self): cf = config.Config() cf.base_url = self.test_url cf.subdomain = '' cf.port = '' self.assertEqual(cf.url(), 'http://' + self.test_url)