def test_state_not_persisted(self): gform = GForm('dG02c3hqdEZBaWZMN1NBdnBCZkVzdWc6MQ') self.assertIn('SmsSid', gform.labels) self.assertNotIn('One', gform.labels) gform = GForm('dHk3N2M5NlAtZV9mMlAyOEU5VE05dEE6MQ') self.assertNotIn('SmsSid', gform.labels) self.assertIn('One', gform.labels)
def form(formkey): gform = GForm(formkey) # I could probably re-implement this with fewer lines using sets for key in request.form: if key in gform.labels: name = gform.labels[key] gform.parameters[name] = request.form[key] return gform.submit()
def __init__(self, url): self.parameters = None self.message = "" self.url = url parsed_url = urlparse.urlparse(url) if not "http" in parsed_url.scheme: raise NoURLException("No input, expected URL.") if not "google.com" in parsed_url.netloc: message = "Input URL must contain 'google.com'." raise NoGoogleInURLException(message) query = urlparse.parse_qs(parsed_url.query) if query and 'key' in query: message = "URL appears to be for a spreadsheet, " \ "URL must be for a form." raise URLForGoogleSpreadsheetNotFormException(message) if not query or not 'formkey' in query: message = "Input URL must contain 'formkey' query parameter." raise URLNotForGoogleFormException(message) self.formkey = query['formkey'][0] try: gform = GForm(self.formkey) except: message = "Error form at URL, " \ "does the URL exist and point to a form?" raise GoogleFormDoesntExistException(message) intersection = twilio_parameters.intersection(gform.labels) if intersection == set(): message = "Form at URL must contain at least " \ "one input with a label that matches a Twilio parameter." raise NoTwilioParametersInFormException(message) self.parameters = intersection
def test_invalid_throws_exception(self): formkey = 'invalid_formkey' exception_thrown = False try: GForm(formkey) except GFormException: exception_thrown = True self.assertEquals(exception_thrown, True)
def test_valid_form(self): formkey = 'dG02c3hqdEZBaWZMN1NBdnBCZkVzdWc6MQ' gform = GForm(formkey) self.assertEquals(gform.__class__.__name__, 'GForm')