From: Diane Trout Date: Wed, 14 Sep 2016 23:59:12 +0000 (-0700) Subject: Adapt response.content for RDF and xhtml validator X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=0e1cb5faddc97abcc6a5509b4ea71e1d5013145e Adapt response.content for RDF and xhtml validator Irritatingly one wants bytes and one wants unicode under python3. --- diff --git a/experiments/test_experiments.py b/experiments/test_experiments.py index c89d7d4..253b5f7 100644 --- a/experiments/test_experiments.py +++ b/experiments/test_experiments.py @@ -13,7 +13,7 @@ from django.core import mail from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from django.test import TestCase -from django.utils.encoding import smart_text +from django.utils.encoding import smart_text, smart_bytes from .models import SequencingRun, Sequencer, FlowCell, FileType from samples.models import HTSUser @@ -605,13 +605,12 @@ class TestSequencer(TestCase): url = '/lane/{}'.format(self.lane.id) response = self.client.get(url) - rdfbody = smart_text(response.content) self.assertEqual(response.status_code, 200) - status = validate_xhtml(rdfbody) + status = validate_xhtml(smart_bytes(response.content)) if status is not None: self.assertTrue(status) - load_string_into_model(model, 'rdfa', rdfbody) + load_string_into_model(model, 'rdfa', smart_text(response.content)) errmsgs = list(inference.run_validation()) self.assertEqual(len(errmsgs), 0) diff --git a/samples/test_samples.py b/samples/test_samples.py index 7acae97..537e9cb 100644 --- a/samples/test_samples.py +++ b/samples/test_samples.py @@ -6,7 +6,7 @@ from unittest import skipUnless from django.core.exceptions import ValidationError from django.test import TestCase, RequestFactory -from django.utils.encoding import smart_text, smart_str +from django.utils.encoding import smart_text, smart_str, smart_bytes from .models import Affiliation, ExperimentType, Species, Library from .views import library_dict @@ -211,8 +211,7 @@ class SampleWebTestCase(TestCase): response = self.client.get(library.get_absolute_url()) self.assertEqual(response.status_code, 200) - content = smart_text(response.content) - load_string_into_model(model, 'rdfa', content) + load_string_into_model(model, 'rdfa', smart_text(response.content)) body = """prefix rdf: prefix libns: @@ -236,7 +235,7 @@ class SampleWebTestCase(TestCase): self.assertEqual(fromTypedNode(r['made_by']), library.made_by) - state = validate_xhtml(content) + state = validate_xhtml(smart_bytes(response.content)) if state is not None: self.assertTrue(state)