def it_can_unmarshal_relationships(self): # test data -------------------- reltype = 'http://reltype' # mockery ---------------------- pkg_reader = Mock(name='pkg_reader') pkg_reader.iter_srels.return_value = ( ('/', Mock(name='srel1', rId='rId1', reltype=reltype, target_partname='partname1', is_external=False)), ('/', Mock(name='srel2', rId='rId2', reltype=reltype, target_ref='target_ref_1', is_external=True)), ('partname1', Mock(name='srel3', rId='rId3', reltype=reltype, target_partname='partname2', is_external=False)), ('partname2', Mock(name='srel4', rId='rId4', reltype=reltype, target_ref='target_ref_2', is_external=True)), ) pkg = Mock(name='pkg') parts = {} for num in range(1, 3): name = 'part%d' % num part = Mock(name=name) parts['partname%d' % num] = part pkg.attach_mock(part, name) # exercise --------------------- Unmarshaller._unmarshal_relationships(pkg_reader, pkg, parts) # verify ----------------------- expected_pkg_calls = [ call.load_rel(reltype, parts['partname1'], 'rId1', False), call.load_rel(reltype, 'target_ref_1', 'rId2', True), call.part1.load_rel(reltype, parts['partname2'], 'rId3', False), call.part2.load_rel(reltype, 'target_ref_2', 'rId4', True), ] assert pkg.mock_calls == expected_pkg_calls
def it_can_unmarshal_relationships(self): # test data -------------------- reltype = "http://reltype" # mockery ---------------------- pkg_reader = Mock(name="pkg_reader") pkg_reader.iter_srels.return_value = ( ("/", Mock(name="srel1", rId="rId1", reltype=reltype, target_partname="partname1", is_external=False)), ("/", Mock(name="srel2", rId="rId2", reltype=reltype, target_ref="target_ref_1", is_external=True)), ( "partname1", Mock(name="srel3", rId="rId3", reltype=reltype, target_partname="partname2", is_external=False), ), ("partname2", Mock(name="srel4", rId="rId4", reltype=reltype, target_ref="target_ref_2", is_external=True)), ) pkg = Mock(name="pkg") parts = {} for num in range(1, 3): name = "part%d" % num part = Mock(name=name) parts["partname%d" % num] = part pkg.attach_mock(part, name) # exercise --------------------- Unmarshaller._unmarshal_relationships(pkg_reader, pkg, parts) # verify ----------------------- expected_pkg_calls = [ call.load_rel(reltype, parts["partname1"], "rId1", False), call.load_rel(reltype, "target_ref_1", "rId2", True), call.part1.load_rel(reltype, parts["partname2"], "rId3", False), call.part2.load_rel(reltype, "target_ref_2", "rId4", True), ] assert pkg.mock_calls == expected_pkg_calls
def it_can_unmarshal_from_a_pkg_reader( self, pkg_reader_, pkg_, part_factory_, _unmarshal_parts, _unmarshal_relationships, parts_dict_ ): # exercise --------------------- Unmarshaller.unmarshal(pkg_reader_, pkg_, part_factory_) # verify ----------------------- _unmarshal_parts.assert_called_once_with(pkg_reader_, pkg_, part_factory_) _unmarshal_relationships.assert_called_once_with(pkg_reader_, pkg_, parts_dict_) for part in parts_dict_.values(): part.after_unmarshal.assert_called_once_with() pkg_.after_unmarshal.assert_called_once_with()
def it_can_unmarshal_from_a_pkg_reader(self, pkg_reader_, pkg_, part_factory_, _unmarshal_parts, _unmarshal_relationships, parts_dict_): # exercise --------------------- Unmarshaller.unmarshal(pkg_reader_, pkg_, part_factory_) # verify ----------------------- _unmarshal_parts.assert_called_once_with(pkg_reader_, pkg_, part_factory_) _unmarshal_relationships.assert_called_once_with( pkg_reader_, pkg_, parts_dict_) for part in parts_dict_.values(): part.after_unmarshal.assert_called_once_with() pkg_.after_unmarshal.assert_called_once_with()
def it_can_unmarshal_parts(self, pkg_reader_, pkg_, part_factory_, parts_dict_, partnames_, content_types_, blobs_): # fixture ---------------------- partname_, partname_2_ = partnames_ content_type_, content_type_2_ = content_types_ blob_, blob_2_ = blobs_ # exercise --------------------- parts = Unmarshaller._unmarshal_parts(pkg_reader_, pkg_, part_factory_) # verify ----------------------- assert part_factory_.call_args_list == [ call(partname_, content_type_, blob_, pkg_), call(partname_2_, content_type_2_, blob_2_, pkg_), ] assert parts == parts_dict_
def it_can_unmarshal_parts(self, pkg_reader_, pkg_, part_factory_, parts_dict_, partnames_, content_types_, blobs_): # fixture ---------------------- partname_, partname_2_ = partnames_ content_type_, content_type_2_ = content_types_ blob_, blob_2_ = blobs_ # exercise --------------------- parts = Unmarshaller._unmarshal_parts(pkg_reader_, pkg_, part_factory_) # verify ----------------------- assert (part_factory_.call_args_list == [ call(partname_, content_type_, blob_, pkg_), call(partname_2_, content_type_2_, blob_2_, pkg_) ]) assert parts == parts_dict_
def it_can_unmarshal_relationships(self): # test data -------------------- reltype = "http://reltype" # mockery ---------------------- pkg_reader = Mock(name="pkg_reader") pkg_reader.iter_srels.return_value = ( ( "/", Mock( name="srel1", rId="rId1", reltype=reltype, target_partname="partname1", is_external=False, ), ), ( "/", Mock( name="srel2", rId="rId2", reltype=reltype, target_ref="target_ref_1", is_external=True, ), ), ( "partname1", Mock( name="srel3", rId="rId3", reltype=reltype, target_partname="partname2", is_external=False, ), ), ( "partname2", Mock( name="srel4", rId="rId4", reltype=reltype, target_ref="target_ref_2", is_external=True, ), ), ) pkg = Mock(name="pkg") parts = {} for num in range(1, 3): name = "part%d" % num part = Mock(name=name) parts["partname%d" % num] = part pkg.attach_mock(part, name) # exercise --------------------- Unmarshaller._unmarshal_relationships(pkg_reader, pkg, parts) # verify ----------------------- expected_pkg_calls = [ call.load_rel(reltype, parts["partname1"], "rId1", False), call.load_rel(reltype, "target_ref_1", "rId2", True), call.part1.load_rel(reltype, parts["partname2"], "rId3", False), call.part2.load_rel(reltype, "target_ref_2", "rId4", True), ] assert pkg.mock_calls == expected_pkg_calls