def setup(self): self.api = API('091e43d72fe4466a0433', token=token)
def test_exception(): api = API('1333', token={}) try: api.user() except AuthException: assert True
class TestAPI(object): # def __init__(self): # 不能使用 __init__ 否则 py.test 会忽略这个类 # pass def setup(self): self.api = API('091e43d72fe4466a0433', token=token) def test_user(self): assert self.api.user()['username'] == 'mozillazg' def test_word(self): assert self.api.word('hello')['data']['id'] def test_add_word(self): word_id = self.api.word('hello')['data']['id'] assert self.api.add_word(word_id)['data']['id'] def test_examples(self): word_id = self.api.word('hello')['data']['id'] assert self.api.examples(word_id)['data'][0]['id'] assert self.api.examples(word_id, type='sys' )['data'][0]['id'] def test_add_example(self): word_id = self.api.word('hello')['data']['id'] data = self.api.add_example(word_id, 'hello', '你好') assert data['data']['id'] def test_favorite_example(self): word_id = self.api.word('hello')['data']['id'] data = self.api.add_example(word_id, 'hello', '你好') assert self.api.favorite_example(data['data']['id'] )['status_code'] == 0 def test_delete_example(self): word_id = self.api.word('hello')['data']['id'] data = self.api.add_example(word_id, 'hello', '你好') assert self.api.delete_example(data['data']['id'])['status_code'] == 0 def test_notes(self): word_id = self.api.word('hello')['data']['id'] assert self.api.notes(word_id)['status_code'] == 0 def test_add_note(self): word_id = self.api.word('hello')['data']['id'] assert self.api.add_note(word_id, '你好')['status_code'] == 0 def test_favorite_note(self): word_id = self.api.word('hello')['data']['id'] note_id = self.api.add_note(word_id, '你好')['data']['id'] assert self.api.favorite_note(note_id)['status_code'] == 0 def test_delete_note(self): word_id = self.api.word('hello')['data']['id'] note_id = self.api.add_note(word_id, '你好')['data']['id'] assert self.api.delete_note(note_id)['status_code'] == 0
class TestAPI(object): # def __init__(self): # 不能使用 __init__ 否则 py.test 会忽略这个类 # pass def setup(self): self.api = API(client_id, token=token) def test_user(self): assert self.api.user()['username'] == username def test_word(self): assert self.api.word('hello')['data']['id'] def test_add_word(self): word_id = self.api.word('hello')['data']['id'] assert self.api.add_word(word_id)['data']['id'] def test_examples(self): word_id = self.api.word('hello')['data']['id'] assert self.api.examples(word_id)['data'][0]['id'] assert self.api.examples(word_id, type='sys')['data'][0]['id'] def test_add_example(self): word_id = self.api.word('hello')['data']['id'] data = self.api.add_example(word_id, 'hello', '你好') assert data['data']['id'] def test_favorite_example(self): word_id = self.api.word('hello')['data']['id'] data = self.api.add_example(word_id, 'hello', '你好') assert self.api.favorite_example( data['data']['id'])['status_code'] == 0 def test_delete_example(self): word_id = self.api.word('hello')['data']['id'] data = self.api.add_example(word_id, 'hello', '你好') assert self.api.delete_example(data['data']['id'])['status_code'] == 0 def test_notes(self): word_id = self.api.word('hello')['data']['id'] assert self.api.notes(word_id)['status_code'] == 0 def test_add_note(self): word_id = self.api.word('hello')['data']['id'] assert self.api.add_note(word_id, '你好')['status_code'] == 0 def test_favorite_note(self): word_id = self.api.word('hello')['data']['id'] note_id = self.api.add_note(word_id, '你好')['data']['id'] assert self.api.favorite_note(note_id)['status_code'] == 0 def test_delete_note(self): word_id = self.api.word('hello')['data']['id'] note_id = self.api.add_note(word_id, '你好')['data']['id'] assert self.api.delete_note(note_id)['status_code'] == 0
def setup(self): self.api = API(client_id, token=token)
def setUp(self): self.api = API('091e43d72fe4466a0433', token=token)
class TestAPI(unittest.TestCase): # def __init__(self): # 不能使用 __init__ 否则 py.test 会忽略这个类 # pass def setUp(self): self.api = API('091e43d72fe4466a0433', token=token) def test_user(self): print(self.api.user()['username']) pass def test_word(self): assert self.api.word('hello')['data']['id'] def test_add_word(self): word_id = self.api.word('hello')['data']['id'] assert self.api.add_word(word_id)['data']['id'] def test_examples(self): word_id = self.api.word('hello')['data']['id'] assert self.api.examples(word_id)['data'][0]['id'] assert self.api.examples(word_id, type='sys')['data'][0]['id'] def test_add_example(self): word_id = self.api.word('hello')['data']['id'] data = self.api.add_example(word_id, 'hello', '你好') assert data['data']['id'] def test_favorite_example(self): word_id = self.api.word('hello')['data']['id'] data = self.api.add_example(word_id, 'hello', '你好') assert self.api.favorite_example( data['data']['id'])['status_code'] == 0 def test_delete_example(self): word_id = self.api.word('hello')['data']['id'] data = self.api.add_example(word_id, 'hello', '你好') assert self.api.delete_example(data['data']['id'])['status_code'] == 0 def test_notes(self): word_id = self.api.word('hello')['data']['id'] assert self.api.notes(word_id)['status_code'] == 0 def test_add_note(self): word_id = self.api.word('hello')['data']['id'] assert self.api.add_note(word_id, '你好')['status_code'] == 0 def test_favorite_note(self): word_id = self.api.word('hello')['data']['id'] note_id = self.api.add_note(word_id, '你好')['data']['id'] assert self.api.favorite_note(note_id)['status_code'] == 0 def test_delete_note(self): word_id = self.api.word('hello')['data']['id'] note_id = self.api.add_note(word_id, '你好')['data']['id'] assert self.api.delete_note(note_id)['status_code'] == 0
{ "token_type": "Bearer", "state": "PwoXRkUFNdcbeKeWSNVddLjN4beoUy", "access_token": "rsrLV1WaBpzzMYsrTZAjfRJmq8oKVz", "scope": [ "read", "write" ], "expires_in": "2592000", "expires_at": 1451613656.925714 } ''' DICT_FOLDER = '/Users/jingweigu/Google Drive/sync/' api = API('091e43d72fe4466a0433', token=json.loads(token)) def forgetAll(learning_id): print(api.forget(learning_id)) def loadDictFile(): dictFiles = [ f for f in listdir(DICT_FOLDER) if isfile(join(DICT_FOLDER, f)) and f.endswith('xml') ] wordList = [] for f in dictFiles: tree = ET.parse(join(DICT_FOLDER, f))