def test_Invalid_OutOfRangeValues(self): """validate() of invalidOutOfRangeValues should always raise InvalidValueError.""" if TESTS_DEBUG==True: display_function_info() display_data_set("Invalid Out of Range Values Set:",self.invalidOutOfRangeValues) for i in self.invalidOutOfRangeValues: p=parseomhe() if TESTS_DEBUG==True: print "parseomhe result:" print p print "p.validate:" print p.validate d=p.split(i) if TESTS_DEBUG==True: print "output of split: [" + str(d) +"]" if TESTS_DEBUG==True: display_test_result(i,d) print "Error:" print InvalidValueError self.assertRaises(InvalidValueError, p.validate, splitdict=d)
def testInvalidMessageRaisesInvalidMessageError(self): """split() of invalidCommand should always raise InvalidMessageError.""" for i in self.invalidCommand: p=parseomhe() if TESTS_DEBUG==True: print "Testing Invalid Command:" + str(i) print p print "End of parsed result" self.assertRaises(InvalidMessageError, p.split, message=i)
def clean_text(self): #If OMHE, then validate OMHE. text = self.cleaned_data.get('text') transaction_type = self.cleaned_data.get('transaction_type') if transaction_type=="omhe": p = parseomhe() r=p.parse(text) if r.has_key('error'): msg="OMHE Parse Error: %s" % (r['error']) raise forms.ValidationError(msg) return text
def testValidValuesAlwayscontainsDiastolicValue(self): """parse() of validValues should always return bp_dia in dict.""" for i in self.validValues: p=parseomhe() result = p.parse(i) if TESTS_DEBUG==True: print " " print "Testing Value:" + str(i) print "parsed result:" print result print "end of Parsed Result" self.assertDictContains(result, self.valid_parse_val_2)
def testInvalidMessageRaisesInvalidMessageError(self): """split() of invalidCommand should always raise InvalidMessageError.""" if TESTS_DEBUG==True: display_function_info() display_data_set("Invalid Command Set:",self.invalidCommand) for i in self.invalidCommand: p=parseomhe() if TESTS_DEBUG==True: display_test_result(i,p) self.assertRaises(InvalidMessageError, p.split, message=i)
def testInvalidOutOfRangeValues(self): """validate() of invalidOutOfRangeValues should always raise InvalidValueError.""" for i in self.invalidOutOfRangeValues: p=parseomhe() d=p.split(i) if TESTS_DEBUG==True: print " " print "Testing Out of Range Value:" + str(i) print "parsed result(d):" print d print "end of Parsed Result" self.assertRaises(InvalidValueError, p.validate, splitdict=d)
def test_InvalidMessage_Raises_InvalidMessageError(self): """split() of invalidCommand should always raise InvalidMessageError.""" if TESTS_DEBUG == True: display_function_info() display_data_set("Invalid Command Set:", self.invalidCommand) for i in self.invalidCommand: p = parseomhe() if TESTS_DEBUG == True: display_test_result(i, p) self.assertRaises(InvalidMessageError, p.split, message=i)
def test_ValidValues_AlwaysContains_Mood_NumericValue(self): """parse() of validValues should always return md_numeric in dict.""" if TESTS_DEBUG==True: display_function_info() display_data_set("Valid Values Set:",self.validValues) for i in self.validValues: p=parseomhe() result = p.parse(i) if TESTS_DEBUG==True: display_test_result(i,result) self.assertDictContains(result, self.valid_parse_val_1)
def prepare_idTransaction_dict(model_instance): fields = SortedDict() for field in model_instance._meta.fields: try: if getattr(model_instance, field.name) not in (None, ''): newfieldname ="%s" % (field.name) value = getattr(model_instance, field.name) #if a datetime sting, then turn into a datetime try: value = time.strptime(value, "%Y-%m-%d %H:%M:%S") except: pass try: value = time.strptime(value, "%Y-%m-%d") except: pass try: value = time.strptime(value, "%H:%M:%S") except: pass fields[newfieldname] = str(value) except: pass fields.insert(0,'_id', model_instance.transaction_id) if fields.has_key('extra_fields'): ef =json.loads(fields['extra_fields']) fields.update(ef) del fields['extra_fields'] if fields.has_key('tags'): fields['tags'] = json.loads(fields['tags']) #print "The tx type is ", fields['transaction_type'] if fields['transaction_type']=="omhe": if fields['text'] != "": p = parseomhe() d = p.parse(fields['text']) del d['transaction_id'], d['transaction_datetime'] fields.update(d) #for k in fields.keys(): # print k,"= ",fields[k] return fields
def test_ValidValues_AlwaysContains_WeightNumericValue(self): """parse() of validValues should always return wt_numeric in dict.""" if TESTS_DEBUG == True: display_function_info() display_data_set("Valid Values Set:", self.validValues) for i in self.validValues: p = parseomhe() result = p.parse(i) if TESTS_DEBUG == True: display_test_result(i, result) self.assertDictContains(result, self.valid_parse_val_1)
def save(self, user): texti=self.cleaned_data['texti'] omhe_str= texti """ Instantiate an instance of the OMHE class""" o = parseomhe() """Parse it if valid, otherwise raise the appropriate error""" d=o.parse(omhe_str) u=User.objects.get(username=user) user_email=str(u.email) responsedict=uploadOMHE2restcatdict(d, settings.RESTCAT_USER, settings.RESTCAT_PASS, user_email, settings.RESTCAT_USER, user_email, 3) return responsedict
def save(self, user, text): ci=text omhe_str="ci=%s" % (ci) """ Instantiate an instance of the OMHE class""" o = parseomhe() """Parse it if valid, otherwise raise the appropriate error""" d=o.parse(omhe_str) u=User.objects.get(username=user) user_email=str(u.email) result=uploadOMHE2restcat(d, settings.RESTCAT_USER, settings.RESTCAT_PASS, user_email, settings.RESTCAT_USER, user_email, 3) #print "HTTP Response Code=%s" % (result.getinfo(result.HTTP_CODE),) code = result.getinfo(result.HTTP_CODE) return code
def test_Invalid_OutOfRangeValues(self): """validate() of invalidOutOfRangeValues should always raise InvalidValueError.""" if TESTS_DEBUG == True: display_function_info() display_data_set("Invalid Out of Range Values Set:", self.invalidOutOfRangeValues) for i in self.invalidOutOfRangeValues: p = parseomhe() d = p.split(i) if TESTS_DEBUG == True: display_test_result(i, d) self.assertRaises(InvalidValueError, p.validate, splitdict=d)
def save(self, user): wt=self.cleaned_data['wt'] omhe_str="wt=%sl" % (wt) """ Instantiate an instance of the OMHE class""" o = parseomhe() """Parse it if valid, otherwise raise the appropriate error""" d=o.parse(omhe_str) u=User.objects.get(username=user) user_email=str(u.email) result=uploadOMHE2restcat(d, settings.RESTCAT_USER, settings.RESTCAT_PASS, user_email, settings.RESTCAT_USER_EMAIL, user_email, 2) #print "HTTP Response Code=%s" % (result.getinfo(result.HTTP_CODE),) code = result.getinfo(result.HTTP_CODE) return code
def test_ValidBlankValues(self): """validate that blank values are also accepted. should return a dict.""" if TESTS_DEBUG==True: display_function_info() display_data_set("Invalid Out of Range Values Set:",self.validBlankValues) for i in self.validBlankValues: p=parseomhe() d=p.split(i) print "output of split: [" + str(d) +"]" if TESTS_DEBUG==True: display_test_result(i,d) self.assertDictContains(d, self.valid_parse_val_1)
def test_Invalid_OutOfRangeValues(self): """validate() of invalidOutOfRangeValues should always raise InvalidValueError.""" if TESTS_DEBUG==True: display_function_info() display_data_set("Invalid Out of Range Values Set:",self.invalidOutOfRangeValues) for i in self.invalidOutOfRangeValues: p=parseomhe() d=p.split(i) if TESTS_DEBUG==True: display_test_result(i,d) self.assertRaises(InvalidValueError, p.validate, splitdict=d)
def test_ValidBlankValues(self): """validate that blank values are also accepted. should return a dict.""" if TESTS_DEBUG == True: display_function_info() display_data_set("Invalid Out of Range Values Set:", self.validBlankValues) for i in self.validBlankValues: p = parseomhe() d = p.split(i) print "output of split: [" + str(d) + "]" if TESTS_DEBUG == True: display_test_result(i, d) self.assertDictContains(d, self.valid_parse_val_1)
def save(self, user): syst=self.cleaned_data['syst'] dia=self.cleaned_data['dia'] pulse=self.cleaned_data['pulse'] where=self.cleaned_data['where'] omhe_str="bp=%s/%sp%s" % (syst, dia, pulse) if where: omhe_str="%s#%s"% (omhe_str, where) """ Instantiate an instance of the OMHE class""" o = parseomhe() """Parse it if valid, otherwise raise the appropriate error""" d=o.parse(omhe_str) u=User.objects.get(username=user) user_email=str(u.email) result=uploadOMHE2restcat(d, settings.RESTCAT_USER, settings.RESTCAT_PASS, user_email, settings.RESTCAT_USER, user_email, 2) code = result.getinfo(result.HTTP_CODE) return code
if __name__ == "__main__": #h="302c312c37302e302c3136332e382c3437352c31362e302c32362e322c3133372e362c3130302e382c33352c32332e352c373239380d0a" h=getFromMeter() if len(h)>10: r= parse_values(process_string(h)) #print r email= raw_input("Please enter the user's email address: ") pin = raw_input("Please enter the user's PIN or PASSWORD: "******""" Instantaiate an instance of the OMHE class""" o = parseomhe() """Parse it if valid, otherwise raise the appropriate error""" try: omhe_str="wt=%s#tanita_body_scan" % (r['weight']) d=o.parse(omhe_str) """Send the OMHE dictionary to RESTCat""" except(): print "Failed to parse OMHE string" sys.exit(1) userpass="******" % (email, pin) sender=email receiver=email subject=email restcat_server=RESTCAT_SERVER out_file="out.json"
import os import json from bottle import run, route, request, response, HTTPResponse, HTTPError from omhe.core.parseomhe import parseomhe if 'BPM_SECRET_KEY' not in os.environ: raise ValueError('BPM_SECRET_KEY not set') if 'BPM_DATA_PATH' not in os.environ: raise ValueError('BPM_DATA_PATH not set') if 'BPM_HOST' not in os.environ: raise ValueError('BPM_HOST not set') secret = os.environ['BPM_SECRET_KEY'] persist_path = os.environ['BPM_DATA_PATH'] parser = parseomhe() # load previous data if any data = [] if os.path.exists(persist_path): with open(persist_path, 'r') as ip: for line in ip: data.append(json.loads(line)) def authorized(key): return key == secret @route('/update') def update():