def writeArticle(doc_id, _base64_content): """ >>> doc_id = '0706012057' >>> _base64_content = '열라 테스트' >>> #ma = MuseArticle('1201170413') >>> #ma.html >>> #dd = writeArticle('1201170413', ma.html) >>> #dd >>> #dd = writeArticle(doc_id, _base64_content) >>> #dd.read() >>> #'\\nOK\\n' """ data = Data() data.cmd = "writeArticle" data.doc_id = doc_id data._base64_content = _base64_content api = API(data) fd = api.send() result = fd.read() fd.close() return result
def updateServerFile(filename, _base64_content): """ Client side function for the updateServer api. """ data = Data() data.cmd = "updateServerFile" data.filename = filename data._base64_content = _base64_content api = API(data) fd = api.send() result = fd.read() fd.close() return result
def updateFile(filename, _base64_content): ''' Update files to the server. The file to be stored into config.files_d. ''' data = Data() data.cmd = "updateFile" data.filename = filename data._base64_content = _base64_content # The server api will not replace the file. Returns False when The # file is exists in the server. api = API(data) fd = api.send() result = fd.read() return result
def deleteComment(doc_id, comment_id): """ deleteComment("0706012057", "26") """ #libs.log(doc_id) #libs.log(comment_id) data = Data() data.cmd = "deleteComment" data.doc_id = doc_id data.comment_id = comment_id api = API(data) fd = api.send() result = fd.read() fd.close() return result
def __init__(self, data): self.required_data = Data() # Set secure key self.required_data.secure_key = config.SECURE_KEY self.data = data self.cmd = self._getCmd() self._setArgs()
def updateIndex(doc_id, _jsonBase64_dict): """ >>> doc_id = '0706012057' >>> _jsonBase64_dict = {'category': 'emacs planner', 'date': '1108170951', 'author': 'this is author', 'update': '1108170952', 'title': '가나다 우리는 사는 사람들 이 닫 다다. fjdksf kdsf ', 'doc_id': '0706012057'} >>> #dd = updateIndex(doc_id, _jsonBase64_dict) >>> #dd.read() >>> #'\\nOK\\n' """ data = Data() data.cmd = "updateIndex" data.doc_id = doc_id data._jsonBase64_dict = _jsonBase64_dict api = API(data) fd = api.send() result = fd.read() fd.close() return result
def test_basic(self): b = get_browser() query = Data() query.cmd = 'articles_length' url = config.url_root + 'api.py?' + query.urlencode() b.go(url) result = b.get_html() # For Secure key. server is using secure key? self.assertNotEqual(result.find('Error'), -1) # For articles_length query.secure_key = config.SECURE_KEY url = config.url_root + 'api.py?' + query.urlencode() b.go(url) result = b.get_html() self.assertEqual(libs.removeBlank(result), '2') # For comments_length query.cmd = 'comments_length' query.doc_id = Var.dummy_id url = config.url_root + 'api.py?' + query.urlencode() b.go(url) result = b.get_html() self.assertEqual(libs.removeBlank(result), '1') # For article_json query.cmd = 'article_json' url = config.url_root + 'api.py?' + query.urlencode() b.go(url) result = b.get_html() # Get the index of the local dummy article = Article() article.set(Var.dummy_id) result = json.loads(libs.removeBlank(result)) self.assertEqual(result['doc_id'], unicode(article.__dict__['doc_id']))
def test_writeArticle(self): base64_content = Data.encode_base64('content') data = {'cmd': 'writeArticle', 'doc_id': '9999999999', 'secure_key': config.SECURE_KEY, '_base64_content': base64_content} rv = tapp.post('api', data=data) self.assertEqual(rv.status_code, 200) self.assertTrue(rv.data, 'ok') dummy_path = config.article_filename('9999999999') filep = ope(dummy_path) self.assertTrue(filep) if filep: os.remove(dummy_path)
class API(object): """ The class is used like urllib2.urlopen function with the arguments. The arguments specifies the data argument of urllib2.Request class. To create the arguments we use the class Data. The returned result is the returned result of urllib2.urlopen. """ url = config.url_api def __init__(self, data): self.required_data = Data() # Set secure key self.required_data.secure_key = config.SECURE_KEY self.data = data self.cmd = self._getCmd() self._setArgs() #req = Request(self.url, self.required_data) #return urlopen(req) def _getCmd(self): try: return getattr(api, self.data.cmd) except AttributeError: raise AttributeError("'%s' requires data.cmd" % self.__class__.__name__) def _setArgs(self): # get the argument variable of self.cmd spec = inspect.getargspec(self.cmd) setattr(self.required_data, "cmd", self.data.cmd) for arg in spec.args: value = getattr(self.data, arg) setattr(self.required_data, arg, value) def send(self): data = self.required_data.urlencode() req = Request(self.url, data) #libs.log(req) return urlopen(req)
def writeComment(doc_id, _base64_content, _base64_name='', password=''): """ >>> doc_id = '0706012057' >>> _base64_content = '어찌하다가 우리가 이런일에\\n 아' >>> _base64_name = '달수' >>> password = '******' >>> #dd = writeComment(doc_id, _base64_content, _base64_name, password) >>> #dd.read() >>> #'\\nOK\\n' # This is output """ data = Data() data.cmd = "writeComment" data.doc_id = doc_id data._base64_content = _base64_content data._base64_name = _base64_name data.password = password api = API(data) fd = api.send() result = fd.read() fd.close() return result
def comment(self): comment_content = Data.encode_base64(u'comment_content')