feat: added args for user, pass, & test site
No longer hardcoded values and now able to test both versions of the site
This commit is contained in:
parent
83673f92fd
commit
07da641a12
48
main.py
48
main.py
@ -1,6 +1,7 @@
|
||||
import os
|
||||
import re
|
||||
import csv
|
||||
import argparse
|
||||
import urllib.parse as urlparse
|
||||
from urllib.parse import parse_qs
|
||||
|
||||
@ -13,11 +14,14 @@ from selenium.webdriver.support.ui import WebDriverWait
|
||||
|
||||
|
||||
class BaseTester:
|
||||
BASE_URL = "https://crm-dev.caat.org.uk/"
|
||||
USERNAME = "roxie"
|
||||
PASSWORD = ""
|
||||
def __init__(self, user: str, passwd: str, dev: bool):
|
||||
self.user = user
|
||||
self.passwd = passwd
|
||||
if dev:
|
||||
self.base_url = "https://crm-dev.caat.org.uk"
|
||||
else:
|
||||
self.base_url = "https://crm.caat.org.uk"
|
||||
|
||||
def __init__(self):
|
||||
firefox_options = webdriver.FirefoxOptions()
|
||||
firefox_options.headless = True
|
||||
self.browser = webdriver.Firefox(options=firefox_options)
|
||||
@ -25,12 +29,12 @@ class BaseTester:
|
||||
|
||||
def login(self):
|
||||
""" Login to civicrm so we can continue with the proper cookies """
|
||||
self.browser.get(self.BASE_URL)
|
||||
self.browser.get(self.base_url)
|
||||
username = self.browser.find_element_by_id("edit-name")
|
||||
password = self.browser.find_element_by_id("edit-pass")
|
||||
submit = self.browser.find_element_by_id("edit-submit")
|
||||
username.send_keys(self.USERNAME)
|
||||
password.send_keys(self.PASSWORD)
|
||||
username.send_keys(self.user)
|
||||
password.send_keys(self.passwd)
|
||||
submit.click()
|
||||
|
||||
# Wait for the js elements load so we know the cookies are good.
|
||||
@ -40,7 +44,7 @@ class BaseTester:
|
||||
)
|
||||
|
||||
def logout(self):
|
||||
self.browser.get(self.BASE_URL + "/user/logout")
|
||||
self.browser.get(self.base_url + "/user/logout")
|
||||
# Wait for the next page to load to finish logging out
|
||||
self.wait.until(
|
||||
EC.visibility_of_element_located((By.ID, "tabs-wrapper"))
|
||||
@ -57,9 +61,9 @@ class BaseTester:
|
||||
|
||||
|
||||
class ContactExport(BaseTester):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.search_url = self.BASE_URL + "/civicrm/contact/search"
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.search_url = self.base_url + "/civicrm/contact/search"
|
||||
|
||||
self.contact_selectall_id = "CIVICRM_QFID_ts_all_4"
|
||||
self.contact_dropdown_id = "select2-chosen-4"
|
||||
@ -81,7 +85,7 @@ class ContactExport(BaseTester):
|
||||
qf_key = self.get_export_id()
|
||||
data = {
|
||||
"qfKey": qf_key,
|
||||
"entryURL": self.BASE_URL + "/civicrm/contact/search",
|
||||
"entryURL": self.base_url + "/civicrm/contact/search",
|
||||
"_qf_Select_next": "Continue",
|
||||
"exportOption": 1,
|
||||
"mergeOption": 0,
|
||||
@ -89,7 +93,7 @@ class ContactExport(BaseTester):
|
||||
"addressee": 1,
|
||||
}
|
||||
req = session.request(
|
||||
"POST", self.BASE_URL + "/civicrm/contact/search", data=data
|
||||
"POST", self.base_url + "/civicrm/contact/search", data=data
|
||||
)
|
||||
return req
|
||||
|
||||
@ -152,4 +156,20 @@ class ContactExport(BaseTester):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ContactExport().test("John")
|
||||
parser = argparse.ArgumentParser(description="")
|
||||
parser.add_argument(
|
||||
"--user", "-u", type=str, dest="user", help="Username of account"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--pass", "-p", type=str, dest="passwd", help="Password of account"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dev",
|
||||
"-D",
|
||||
dest="dev",
|
||||
action="store_true",
|
||||
help="Test dev site instead of production"
|
||||
)
|
||||
parser.set_defaults(dev=False)
|
||||
arguments = parser.parse_args()
|
||||
ContactExport(arguments.user, arguments.passwd, arguments.dev).test("John")
|
||||
|
Loading…
Reference in New Issue
Block a user