def test_similar(self): ctx = app.test_request_context() ctx.push() from engines import content_engine #content_engine.train('sample-data.csv') #content_engine.train('result.csv') data = {'item': 56753, 'num': NUM_DATA} headers = [('Content-Type', 'application/json'), ('X-API-TOKEN', current_app.config['API_TOKEN'])] json_data = json.dumps(data) json_data_length = len(json_data) headers.append(('Content-Length', str(json_data_length))) print json_data response = app.test_client().post('/predict', headers=headers, data=json_data) print response response = json.loads(response.data) #fp=open("data_test.csv",'r') #content = fp.read() #fp.close() #cdata = content.split('\n') #print response print "search:56753" num = 10 if num > len(response): num = len(response) for i in range(0, num): print response[i][0], response[i][1]
def requireHeartBeat(): with app.test_request_context(): url_for('pcHeartBeat', ip='172.21.14.35') # if __name__ == '__main__': # app.run()
def test_similar(self): ctx = app.test_request_context() ctx.push() from engines import content_engine #content_engine.train('sample-data.csv') content_engine.train('/home/ubuntu/teamHTTP/serverPHP/engine/tfidf-item/iroya_data.csv')
def test_similar(self): ctx = app.test_request_context() ctx.push() from engines import content_engine #content_engine.train('sample-data.csv') content_engine.train('result.csv') '''
def send(MessageClass, **kwargs): with app.test_request_context(): mailer = Mail(app) mailer.send(MessageClass(**kwargs)) if 'to' in kwargs: return "Mail type: %s, recipient: %s" % (MessageClass.desc(), kwargs['to']) return True
def test_similar(self): ctx = app.test_request_context() ctx.push() from engine import content_engine content_engine.train('sample-data.csv') data = {'item': 1, 'num': 10} headers = [('Content-Type', 'application/json'), ('X-API-TOKEN', current_app.config['API_TOKEN'])] json_data = json.dumps(data) json_data_length = len(json_data) headers.append(('Content-Length', str(json_data_length))) response = app.test_client().post('/score', headers=headers, data=json_data) response = json.loads(response.data) self.assertEqual(len(response), 10) self.assertEqual(response[0][0], "19")
def test_similar(self,item,NUM_DATA): ctx = app.test_request_context() ctx.push() from engines import content_engine #content_engine.train('sample-data.csv') #content_engine.train('result.csv') items=item.split('-') result=[] k={} for i in items: data = {'item': i, 'num': int(NUM_DATA)} headers = [('Content-Type', 'application/json'), ('X-API-TOKEN', current_app.config['API_TOKEN'])] json_data = json.dumps(data) json_data_length = len(json_data) headers.append(('Content-Length', str(json_data_length))) # print json_data response = app.test_client().post('/predict', headers=headers, data=json_data) # print response response = json.loads(response.data) result = result+response for i,j in result: if i not in k.keys(): k[i]=1 else: k[i]=k[i]+1 s=sorted(k.items(),key=lambda item:item[1],reverse=True) #print s result=[] num=0 for key in s: if key in items: continue result.append(int(key[0])) num = num +1 if (num > int(NUM_DATA)): break print result return result
def test_keyword(self): with app.test_request_context('/api/keyword/56'): print(keyword(_id=56))
def test_page(self): with app.test_request_context('/api/page/404'): print(page(_id=404))
def test_speciality(self): with app.test_request_context('/api/speciality/132'): print(speciality(_id=132))
def test_station(self): with app.test_request_context('/api/station/10'): print(station(_id=10))
def setUp(self): app.config['TESTING'] = True app.config['CSRF_ENABLED'] = False with app.test_request_context(): self.form = UserProfileForm()
def setUp(self): app.config['TESTING'] = True app.config['CSRF_ENABLED'] = False with app.test_request_context(): self.form = AccountSettingsForm()
from flask import render_template import codecs import csv from web import app def unicodeit(d): for k in list(d.keys()): d[k] = d[k] if isinstance(d[k], unicode) else unicode(d[k], 'utf-8') return d with app.test_request_context(''): app.preprocess_request() with open('data/organizations.csv') as infile: orgs = [unicodeit(r) for r in csv.DictReader(infile)] orgs = sorted(orgs, cmp=lambda x, y: cmp(x['country'] + x['name'], y['country'] + y['name'])) countries = sorted(set(o['country'] for o in orgs)) with codecs.open('templates/_orgs.html', 'w', 'utf-8') as outfile: outfile.write(render_template('_orgs-template.html', orgs=orgs, countries=countries))