def test_from_dict(self): r = {"start": "/html/body/p[2]/strong", "end": "/html/body/p[2]/strong", "startOffset": 22, "endOffset": 27} anno = Annotation.from_dict({"id": 456, "text": "Hello", "ranges": [r]}) assertProp(anno, "id", 456) assertProp(anno, "text", "Hello") assertProp(anno, "ranges", [r])
def create(self): if 'json' in self.request.params: params = json.loads(self.request.params['json']) else: params = dict(self.request.params) if isinstance(params, list): for objdict in params: anno = Annotation.from_dict(objdict) else: anno = Annotation.from_dict(params) self.session.add(anno) self.session.commit() self.response.status = 303 self.response.headers['Location'] = self.url('annotation', id=anno.id) return None
def test_from_dict(self): r = { "start": "/html/body/p[2]/strong", "end": "/html/body/p[2]/strong", "startOffset": 22, "endOffset": 27 } anno = Annotation.from_dict({ 'id': 456, 'text': "Hello", 'ranges': [r] }) assertProp(anno, 'id', 456) assertProp(anno, 'text', 'Hello') assertProp(anno, 'ranges', [r])
def test_extras_in(self): ann = Annotation() ann.from_dict({'foo':1, 'bar':2}) print ann.extras assert ann.extras == '{"foo": 1, "bar": 2}', "extras weren't serialized properly"
def test_from_dict_with_range(self): ann = Annotation() ann.from_dict({'ranges': [{}]}) assert len(ann.ranges) == 1, "annotation ranges weren't updated from dict"
def test_from_dict(self): ann = Annotation() ann.from_dict({'text': 'Baz'}) assert ann.text == "Baz", "annotation wasn't updated from dict"