def test_serialize_with_extra_col_other_separator(): """Test JSON serialize.""" EXCLUDE_FIELDS = [ "related.1.pid", "related.1.label", ] INCLUDE_FIELDS = ["langs", "title.title", "title.subtitle"] pid = PersistentIdentifier(pid_type='recid', pid_value='2') rec = Record(RECORD_2) data = CSVSerializer(SimpleSchema, csv_excluded_fields=EXCLUDE_FIELDS, header_separator=".").serialize(pid, rec) headers, row_1 = list(data) assert "description,extra.key,extra.value,langs.0,langs.1,langs.2,number,"\ "related.0.label,related.0.pid,related.2.label,related.2.pid,"\ "related.3.label,related.3.pid,title.subtitle,"\ "title.title" == headers.rstrip() assert "\"A very, very 'long' description, with some \"\"quotes\"\".\",An"\ " extra value,\"And special chars:¥,§, Æ, ®,m²☯⊋\",en,fr,de,2," \ "Relation A,55," \ "Relation C,52,"\ "Relation D,78,The subtitle 2,A title 2" == row_1.rstrip() data = CSVSerializer(SimpleSchema, csv_included_fields=INCLUDE_FIELDS, header_separator=".").serialize(pid, rec) headers, row_1 = list(data) assert "langs.0,langs.1,langs.2," \ "title.subtitle,title.title" == headers.rstrip() assert "en,fr,de,The subtitle 2,A title 2" == row_1.rstrip()
def test_serialize(): """Test JSON serialize.""" EXCLUDE_FIELDS = [ "extra", "related_1_pid", "related_1_label", ] pid = PersistentIdentifier(pid_type='recid', pid_value='2') rec = Record(RECORD_1) data = CSVSerializer( SimpleSchema, csv_excluded_fields=EXCLUDE_FIELDS ).serialize(pid, rec) headers, row_1 = list(data) assert "description,langs_0,langs_1,langs_2,number,related_0_label,"\ "related_0_pid,related_2_label,related_2_pid,title_subtitle,"\ "title_title" == headers.rstrip() assert "\"A very, very 'long' description, with some \"\"quotes\"\".\","\ "en,fr,de,2,Relation A,55,Relation C,52,The subtitle,"\ "A title" == row_1.rstrip()
However, it looks like that browsers are not sending the If-Match/ETag headers on PUT requests. """ def view(pid, record, code=200, headers=None, links_factory=None): response = current_app.response_class( serializer.serialize(pid, record, links_factory=links_factory), mimetype=mimetype) response.status_code = code response.cache_control.no_cache = True # etag/last-modified headers removed if headers is not None: response.headers.extend(headers) if links_factory is not None: add_link_header(response, links_factory(pid)) return response return view csv_v1 = CSVSerializer(ILSRecordSchemaJSONV1, csv_excluded_fields=[]) csv_v1_response = record_responsify_no_etag(csv_v1, "text/csv") csv_v1_search = search_responsify(csv_v1, "text/csv") json_v1 = JSONSerializer(ILSRecordSchemaJSONV1, replace_refs=True) json_v1_response = record_responsify_no_etag(json_v1, "application/json") json_v1_search = search_responsify(json_v1, "application/json")
def test_serialize_search(): """Test CSV serialize.""" EXCLUDE_FIELDS = [ "extra", "related_1_pid", "related_1_label", ] def fetcher(obj_uuid, data): assert obj_uuid in ['a', 'b', 'c', 'd', 'e'] return PersistentIdentifier(pid_type='doi', pid_value='a') hits = [ { '_source': RECORD_1, '_id': 'a', '_version': 1, }, { '_source': RECORD_2, '_id': 'b', '_version': 1 }, { '_source': RECORD_2, '_id': 'c', '_version': 1, }, { '_source': RECORD_2, '_id': 'd', '_version': 1 }, { '_source': RECORD_2, '_id': 'e', '_version': 1 }, ] data = CSVSerializer( SimpleSchema, csv_excluded_fields=EXCLUDE_FIELDS).serialize_search( fetcher, dict( hits=dict( hits=hits, total=len(hits), ), aggregations={}, ) ) headers, row_1, row_2, row_3, row_4, row_5 = list(data) assert "description,langs_0,langs_1,langs_2,number,related_0_label,"\ "related_0_pid,related_2_label,related_2_pid,related_3_label,"\ "related_3_pid,title_subtitle,title_title" == headers.rstrip() expected_row_1 = "\"A very, very 'long' description, with "\ "some \"\"quotes\"\".\",en,fr,de,2,Relation A,55,"\ "Relation C,52,,,The subtitle,A title" assert expected_row_1 == row_1.rstrip() expected_next_rows = "\"A very, very 'long' description, with "\ "some \"\"quotes\"\".\",en,fr,de,2,Relation A,55,"\ "Relation C,52,Relation D,78,The subtitle 2,A title 2" assert expected_next_rows == row_2.rstrip() assert expected_next_rows == row_3.rstrip() assert expected_next_rows == row_4.rstrip() assert expected_next_rows == row_5.rstrip()