Esempio n. 1
0
 def test_unexpected_document_fields(self):
     '''
     Tests that the parser rejects documents with unexpected fields.
     '''
     testkey = 'testkey'
     assert testkey not in JSON10ParserXMLContent.FIELDS_REQUIRED
     assert testkey not in JSON10ParserXMLContent.FIELDS_OPTIONAL
     xmldict_ = dict(self.test_xmlcontent_minimal_dict)
     xmldict_[testkey] = 'random'
     with pytest.raises(UnexpectedFieldException):
         JSON10ParserXMLContent.from_json_string(json.dumps(xmldict_))
Esempio n. 2
0
 def test_required_document_fields(self):
     '''
     Test for checking that all required document fields are present in the JSON.
     '''
     for key in self.test_xmlcontent_minimal_dict:
         xmldict_ = dict(self.test_xmlcontent_minimal_dict)
         del xmldict_[key]
         with pytest.raises(MissingFieldException):
             JSON10ParserXMLContent.from_json_string(json.dumps(xmldict_))
     assert JSON10ParserXMLContent.from_json_string(
         json.dumps(self.test_xmlcontent_minimal_dict)) is not None
Esempio n. 3
0
 def test_required_document_fields(self):
     '''
     Test for checking that all required document fields are present in the JSON.
     '''
     for key in self.test_xmlcontent_minimal_dict:
         xmldict_ = dict(self.test_xmlcontent_minimal_dict)
         del xmldict_[key]
         with pytest.raises(MissingFieldException):
             JSON10ParserXMLContent.from_json_string(json.dumps(xmldict_))
     assert JSON10ParserXMLContent.from_json_string(
         json.dumps(self.test_xmlcontent_minimal_dict)) is not None
Esempio n. 4
0
 def test_unexpected_document_fields(self):
     '''
     Tests that the parser rejects documents with unexpected fields.
     '''
     testkey = 'testkey'
     assert testkey not in JSON10ParserXMLContent.FIELDS_REQUIRED
     assert testkey not in JSON10ParserXMLContent.FIELDS_OPTIONAL
     xmldict_ = dict(self.test_xmlcontent_minimal_dict)
     xmldict_[testkey] = 'random'
     with pytest.raises(UnexpectedFieldException):
         JSON10ParserXMLContent.from_json_string(
             json.dumps(xmldict_))
Esempio n. 5
0
    def test_document_to_json(self):
        '''
        Tests for the correct serialization as JSON of a XMLContent
        object.
        '''
        result = json.loads(
            JSON10ParserXMLContent.from_json_string(
                json.dumps(
                    self.test_xmlcontent_minimal_dict)).to_json(version=1.0))

        assert self.test_xmlcontent_minimal_dict == result
        assert self.test_xmlcontent_maximal_dict == json.loads(
            JSON10ParserXMLContent.from_json_string(
                json.dumps(
                    self.test_xmlcontent_maximal_dict)).to_json(version=1.0))
Esempio n. 6
0
    def test_document_to_json(self):
        '''
        Tests for the correct serialization as JSON of a XMLContent
        object.
        '''
        result = json.loads(
            JSON10ParserXMLContent.from_json_string(
                json.dumps(self.test_xmlcontent_minimal_dict)
            ).to_json(version=1.0))

        assert self.test_xmlcontent_minimal_dict == result
        assert self.test_xmlcontent_maximal_dict == json.loads(
            JSON10ParserXMLContent.from_json_string(
                json.dumps(self.test_xmlcontent_maximal_dict)
            ).to_json(version=1.0))
Esempio n. 7
0
 def test_incoherent_title(self):
     '''
     Tests that we raise exception if a sentence marked as
     title and the title attribute mismatch.
     '''
     xml_content = XMLContent(self.xml_content_string)
     api_dict = xml_content.to_api_dict(version=1.0)
     api_dict['title'] = 'wrongtitle'
     try:
         xml_content = JSON10ParserXMLContent.from_api_dict(api_dict)
         assert xml_content == False
     except MalformedJSONException as e:
         assert 'is_title' in e.message
Esempio n. 8
0
 def test_minimal_xmlcontent_from_json(self):
     '''
     Tests for the correct conversion from a JSON string.
     '''
     xmlcontent = JSON10ParserXMLContent.from_json_string(
         json.dumps(self.test_xmlcontent_minimal_dict))
Esempio n. 9
0
 def test_minimal_xmlcontent_from_json(self):
     '''
     Tests for the correct conversion from a JSON string.
     '''
     xmlcontent = JSON10ParserXMLContent.from_json_string(
         json.dumps(self.test_xmlcontent_minimal_dict))