def test_remove_safe(self): POST("http://localhost:27080/test/mongoose/_insert", params={"docs": '[{"x" : 1},{"x" : 1},{"x" : 1},{"y" : 1}]'}, async=False) str = POST("http://localhost:27080/test/mongoose/_remove", params={ "criteria": '{"x" : 1}', "safe": 1 }, async=False) obj = json.loads(str) self.assertEquals(obj['ok'], 1, str) self.assertEquals(obj['n'], 3, str) str = POST("http://localhost:27080/test/mongoose/_remove", params={"safe": "1"}, async=False) obj = json.loads(str) self.assertEquals(obj['ok'], 1, str) self.assertEquals(obj['n'], 1, str)
def test_multi(self): POST("http://localhost:27080/test/mongoose/_insert", params = {"docs" : '[{"x" : 1},{"x" : 1},{"x" : 1},{"y" : 1}]'}, async = False ) str = POST("http://localhost:27080/test/mongoose/_update", params = {"criteria" : '{"x" : 1}', "newobj" : '{"$set" : {"x" : 2}}', "multi" : "1", "safe" : "1"}, async = False ) obj = json.loads(str) self.assertEquals(obj['ok'], 1, str) self.assertEquals(obj['n'], 3, str)
def send2(self, gateway='None', name='None', contract='None', detail='无内容', users=None): if self.__class__.expires_time < time.time(): access_token, expires_in = self.get_token_info() self.__class__.expires_time = time.time() + expires_in - 200 self.__class__.access_token = access_token post_url_freshing = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s' % self.__class__.access_token usersinfo = [] if users is None: usersinfo.append(self.allusers['zls']) # elif users == "All": # return ','.join(set(self.allusers.values())) else: if isinstance(users, list): for user in users: usersinfo.append(self.allusers[user]) for user in usersinfo: post_data = self.strategy_notification(touser=user, gateway=gateway, name=name, contract=contract, detail=detail) # print(post_data) result = POST(post_url_freshing, params=post_data, async=False, headers={ 'Content-Type': 'application/json', 'charset': 'utf-8' })
def send_ding_msg(self, msg): from restclient import GET, POST import json import urllib from urllib import quote from datetime import datetime content = { "content": msg + "\n" + datetime.now().strftime('%Y-%m-%d %H:%M:%S') } r = GET( 'https://oapi.dingtalk.com/gettoken?corpid=ding04bb33ecbbcad5f535c2f4657eb6378f&corpsecret=MorKrE3_R8owWfhF62_4dFW3SeV_wmclDAMRZ_lOt2PAZZcx35XF5uAluCL7NzqV' ) access_token = json.loads(r)['access_token'] params = { 'format': 'json', 'method': 'dingtalk.corp.message.corpconversation.asyncsend', 'v': '2.0', 'agent_id': '153447248', 'msgtype': 'text', 'to_all_user': '******' } params['timestamp'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') params['session'] = access_token params['userid_list'] = 'manager1879' params['msgcontent'] = json.dumps(content) POST("https://eco.taobao.com/router/rest", params=params, headers={ 'Content-Type': 'application/x-www-form-urlencoded', 'charset': 'utf-8' })
def test_update(self): str = POST("http://localhost:27080/test/mongoose/_update", params = {"criteria" : "{}", "newobj" : '{"$set" : {"x" : 1}}'}, async = False ) self.assertEquals(type(str).__name__, "str") obj = json.loads(str) self.assertEquals(obj['ok'], 1, str)
def test_insert(self): str = POST("http://localhost:27080/test/mongoose/_insert", params={'docs': '[{"foo" : "bar"}]'}, async=False) self.assertEquals(type(str).__name__, "str") obj = json.loads(str) self.assertEquals(type(obj['oids'][0]['$oid']).__name__, "unicode")
def test_update_err4(self): str = POST("http://localhost:27080/test/mongoose/_update", params={"criteria": "{}"}, async=False) self.assertEquals(type(str).__name__, "str") obj = json.loads(str) self.assertEquals(obj['ok'], 0) self.assertEquals(obj['errmsg'], 'missing newobj')
def test_safe_insert_err1(self): str = POST("http://localhost:27080/test/mongoose/_insert", params = {'docs' : '[{"_id" : "bar"}, {"_id" : "bar"}]', 'safe' : 1}, async = False ) self.assertEquals(type(str).__name__, "str") obj = json.loads(str) self.assertEquals(obj['status']['ok'], 1) self.assertEquals(obj['status']['code'], 11000)
def test_insert_err2(self): str = POST("http://localhost:27080/test/_insert", params={'docs': '[{"foo" : "bar"}]'}, async=False) self.assertEquals(type(str).__name__, "str") obj = json.loads(str) self.assertEquals(obj['ok'], 0) self.assertEquals(obj['errmsg'], 'db and collection must be defined')
def test_post(): HTTPretty.register_uri(HTTPretty.POST, test_url, body=default_body, content_type="text/html") r = POST(test_url, params={'value': 'store this'}, accept=["text/plain", "text/html"], async=False) assert r == default_body assert HTTPretty.last_request.method == "POST" assert HTTPretty.last_request.headers['accept'] == "text/plain,text/html"
def test_find(self): POST("http://localhost:27080/test/mongoose/_insert", params={'docs': '[{"x" : 1},{"x" : 2},{"x" : 3}]'}, async=False) str = GET("http://localhost:27080/test/mongoose/_find") self.assertEquals(type(str).__name__, "str") obj = json.loads(str) self.assertEquals(obj['ok'], 1, str) self.assertEquals(type(obj['id']).__name__, "int", str) self.assertEquals(len(obj['results']), 3, str)
def test_find_sort(self): POST("http://localhost:27080/test/mongoose/_insert", params={'docs': '[{"x" : 1},{"x" : 2},{"x" : 3}]'}, async=False) str = GET("http://localhost:27080/test/mongoose/_find", {"sort": '{"x" : -1}'}) self.assertEquals(type(str).__name__, "str") obj = json.loads(str) self.assertEquals(obj['results'][0]['x'], 3, str) self.assertEquals(obj['results'][1]['x'], 2, str) self.assertEquals(obj['results'][2]['x'], 1, str)
def ping_url(url): try: myinfo = settings.CLUSTER r = POST(url + "announce/",params=myinfo,async=False) n = simplejson.loads(r) nuuid = n['uuid'] r = Node.objects.filter(uuid=nuuid) if r.count(): # we've met this neighbor before. just update. neighbor = r[0] neighbor.last_seen = datetime.now() neighbor.writeable = n['writeable'] neighbor.save() else: # hello new neighbor! neighbor = Node.objects.create(uuid=nuuid, nickname=n['nickname'], base_url=n['base_url'], location=n['location'], writeable=n['writeable'], last_seen=datetime.now(), ) except Exception, e: pass
def handle(self, *app_labels, **options): mediathread_base = "http://localhost:8000" params = { 'set_course' : 'tlc.cunix.local:columbia.edu', 'as' : 'sld2131', 'secret' : 'mediathread_secret', 'title' : "A Test Video", "metadata-wardenclyffe-id" : str(4321), "metadata-tag": "upload", 'mp4': "http://h.i.j/kl", "mp4-metadata": "200%200%200", "thumb": "http://ccnmtl.columbia.edu/broadcast/posters/vidthumb_480x360.jpg" } resp,content = POST(mediathread_base + "/save/", params=params,async=False,resp=True)
def test_upsert(self): str = POST("http://localhost:27080/test/mongoose/_update", params = {"criteria" : "{}", "newobj" : '{"$set" : {"x" : 1}}', "upsert" : "1", "safe" : "1"}, async = False ) self.assertEquals(type(str).__name__, "str") obj = json.loads(str) self.assertEquals(obj['ok'], 1, str) self.assertEquals(obj['n'], 1, str) str = GET("http://localhost:27080/test/mongoose/_find") obj = json.loads(str) self.assertEquals(obj['ok'], 1, str) self.assertEquals(obj['results'][0]['x'], 1, str)
def form_valid(self, form): form_data = form.cleaned_data form_data.pop('captcha') form_data['title'] = 'Mediathread Course Request' form_data['pid'] = "514" form_data['mid'] = "3596" form_data['type'] = 'action item' form_data['owner'] = 'ellenm' form_data['assigned_to'] = 'ellenm' form_data['assigned_to'] = 'ellenm' template = loader.get_template('main/course_request_description.txt') form_data['description'] = template.render(Context(form_data)) POST("http://pmt.ccnmtl.columbia.edu/external_add_item.pl", params=form_data, async=True) return super(RequestCourseView, self).form_valid(form)
def setUp(self): POST("http://localhost:27080/_connect") self._drop_collection()
def _drop_collection(self): str = POST("http://localhost:27080/test/_cmd", params={'cmd': '{"drop" : "mongoose"}'})
def setUp(self): POST("http://localhost:27080/_connect", params={'server': 'localhost:27017'}) self._drop_collection()