def testBasics(self): server = Server('test.wididit.net') self.assertEqual(repr(server), "wididit.server.Server('test.wididit.net')") self.assertEqual(server.get('foobar'), '->foobar<-') server2 = Server('test.wididit.net') server3 = Server('test2.wididit.net') self.assertEqual(server, server2) self.assertNotEqual(server, server3)
def get(self, url, **kwargs): response = requests.Response() if url.startswith('/people/'): userid = url.split('/')[2] username, hostname = userid.split('@') response.status_code = requests.codes.ok response._content = json.dumps( {'username': username, 'biography': 'biography of user %s' % userid, 'server': {'hostname': hostname}}) elif url.startswith('/entry/'): # The server is free to set whatever it wants whenever it wants; # the library should allow that. data = { 'id': 1, 'content': 'the content', 'author': { 'username': '******', 'server': { 'hostname': 'test.wididit.net', }, }, 'category': '', 'contributors': [], 'generator': 'the generator', 'published': '2011-12-30 15:54:00', 'rights': '', 'source': '', 'subtitle': '', 'summary': '', 'title': 'the title', 'updated': '2011-12-30 15:55:05', } response.status_code = requests.codes.ok if len(url) == len('/entry/'): data = [data] if 'data' in kwargs and 'author' in kwargs['data']: if '*****@*****.**' not in kwargs['data']['author']: data = [] response._content = Server.serialize(data) else: response.status_code = requests.codes.forbidden return response
def get_server(): people = get_people() if people: return people.server else: return Server('wididit.net')