Ejemplo n.º 1
0
def test_parse_object_location_true_content_type_xml():
    headers = {
        'Content-Type':
        'multipart/parallel; boundary=2ce97979.83bf.368b.86c2.cc9295f41e3d'
    }
    body = (b'\r\n--2ce97979.83bf.368b.86c2.cc9295f41e3d'
            b'\r\nContent-ID: 8240151'
            b'\r\nObject-ID: 1'
            b'\r\nLocation: http://cdn.rets.com/1.jpg'
            b'\r\nContent-Description: Welcome Home!'
            b'\r\nContent-Type: text/xml'
            b'\r\n'
            b'\r\n<RETS ReplyCode="0" ReplyText="SUCCESS" >\r\n</RETS>\r\n'
            b'\r\n--2ce97979.83bf.368b.86c2.cc9295f41e3d--'
            b'\r\n')
    response = make_response(200, body, headers)

    assert parse_object(response, CompactParser) == (Object(
        mime_type='image/jpeg',
        content_id='8240151',
        description='Welcome Home!',
        object_id='1',
        url='http://cdn.rets.com/1.jpg',
        preferred=False,
        data=None,
    ), )
Ejemplo n.º 2
0
    def get_object(
        self,
        resource: str,
        object_type: str,
        resource_keys: Union[str, Mapping[str, Any], Sequence[str]],
        media_types: Union[str, Sequence[str]] = '*/*',
        location: bool = False,
    ) -> Sequence[Object]:
        """
        The GetObject transaction is used to retrieve structured information related to known
        system entities. It can be used to retrieve multimedia files and other key-related
        information. Objects requested and returned from this transaction are requested and
        returned as MIME media types. The message body for successful retrievals contains only
        the objects in the specified MIME media type. Error responses follow the normal response
        format (section 3.9).

        :param resource: A resource defined in the metadata dictionary (see Section 11.2.2). The
            resource from which the object should be retrieved is specified by this entry. For
            more information see 5.9. The resource must be a resource defined in the metadata
            (section 11.4.1).

        :param object_type: The object type as defined in the metadata (see Section 11.4.1). The
            grouping category to which the object belongs. The type must be an ObjectType defined
            in the Object metadata for this Resource. For more information see section 11.4.1.

        :param resource_keys: A single value or a list-like or dict-like container specifying the
            entities of the resource to retrieve objects for, where the entity is given by the
            KeyField of the resource. If the resource_ids is a value or is list-like, then all
            objects corresponding to the entities are returned by default. If resource_ids is
            dict-like, then it is a mapping from the resource entity to an object_id_list.

            The object_id_list can take the values: '*', 0, or an array of positive ids. If it is
            '*', then all objects are returns. If it is 0, then the preferred object is returned.
            Otherwise, the ids will refer to the sequential index of the objects beginning with 1.

        :param media_types: A single or list-like container of acceptable media types for the
            server to return. If media_types is like-like, then the ordering specifies the
            preference of the media types to return, with the first being the most desirable. If
            the server is unable to provide the requested media type, it should return a 406
            Not Acceptable status, or if no objects exist for any media type then the server
            should return a 404 Not Found.

        :param location: Flag to indicate whether the object or a URL to the object should be
            returned. If location is set to True, it is up to the server to support this
            functionality and the lifetime of the returned URL is not given by the RETS
            specification.
        """
        headers = {
            'Accept': _build_accepted_media_types(media_types),
        }
        payload = {
            'Resource': resource,
            'Type': object_type,
            'ID': _build_entity_object_ids(resource_keys),
            'Location': int(location),
        }
        response = self._http_request(self._url_for('GetObject'),
                                      headers=headers,
                                      payload=payload)
        return parse_object(response)
Ejemplo n.º 3
0
def test_parse_object_no_encoding():
    # Note: there is no charset in the content-type
    headers = {
        'Content-Type':
        'multipart/parallel;boundary="FLEX1t7l9O45tdFUw2e92ASD3qKPxB0lf0Wo7atUz9qlAFoQdBGpDr"'
    }
    body = (b'\r\n--FLEX1t7l9O45tdFUw2e92ASD3qKPxB0lf0Wo7atUz9qlAFoQdBGpDr'
            b'\r\nContent-Type: image/jpeg'
            b'\r\nContent-ID: 20170817170218718581000000'
            b'\r\nObject-ID: 1'
            b'\r\nLocation: http://cdn.rets.com/1.jpg'
            b'\r\nContent-Description: anthem'
            b'\r\nPreferred: 1'
            b'\r\n\r\n'
            b'\r\n--FLEX1t7l9O45tdFUw2e92ASD3qKPxB0lf0Wo7atUz9qlAFoQdBGpDr--'
            b'\r\n')
    response = make_response(200, body, headers)

    assert parse_object(response, CompactParser) == (Object(
        mime_type='image/jpeg',
        content_id='20170817170218718581000000',
        description='anthem',
        object_id='1',
        url='http://cdn.rets.com/1.jpg',
        preferred=True,
        data=None,
    ), )
Ejemplo n.º 4
0
def test_parse_object_not_found():
    headers = {
        'Content-Type': 'text/xml;charset=US-ASCII',
        'Content-ID': '201708171702187185810000009999',
        'Object-ID': '1',
        'Location': '',
    }
    body = b'<RETS ReplyCode="20403" ReplyText="No such object available for this resource"/>'
    response = make_response(200, body, headers)

    assert parse_object(response, CompactParser) == ()
Ejemplo n.º 5
0
def test_parse_object_multi_location_false():
    headers = {
        'Content-Type':
        'multipart/parallel;boundary="FLEX1t7l9O45tdFUw2e92ASD3qKPxB0lf0Wo7atUz9qlAFoQdBGpDr";'
        'charset=US-ASCII'
    }
    body = (b'\r\n--FLEX1t7l9O45tdFUw2e92ASD3qKPxB0lf0Wo7atUz9qlAFoQdBGpDr'
            b'\r\nContent-Type: image/jpeg'
            b'\r\nContent-ID: 20170817170218718581000000'
            b'\r\nObject-ID: 1'
            b'\r\nContent-Description: anthem'
            b'\r\nPreferred: 1'
            b'\r\n'
            b'\r\nbinary content 1'
            b'\r\n--FLEX1t7l9O45tdFUw2e92ASD3qKPxB0lf0Wo7atUz9qlAFoQdBGpDr'
            b'\r\nContent-Type: image/jpeg'
            b'\r\nContent-ID: 20170817170218718581000000'
            b'\r\nObject-ID: 2'
            b'\r\nContent-Description: anthem2'
            b'\r\n'
            b'\r\nbinary content 2'
            b'\r\n--FLEX1t7l9O45tdFUw2e92ASD3qKPxB0lf0Wo7atUz9qlAFoQdBGpDr--'
            b'\r\n')
    response = make_response(200, body, headers)

    assert parse_object(response, CompactParser) == (
        Object(
            mime_type='image/jpeg',
            content_id='20170817170218718581000000',
            description='anthem',
            object_id='1',
            url=None,
            preferred=True,
            data=b'binary content 1',
        ),
        Object(
            mime_type='image/jpeg',
            content_id='20170817170218718581000000',
            description='anthem2',
            object_id='2',
            url=None,
            preferred=False,
            data=b'binary content 2',
        ),
    )
Ejemplo n.º 6
0
def test_parse_object_single_location_false():
    headers = {
        'Content-Type': 'image/jpeg;charset=US-ASCII',
        'Content-ID': '20170817170218718581000000',
        'Object-ID': '1',
        'Content-Description': 'anthem',
        'Preferred': '1',
    }
    body = b'binary content'
    response = make_response(200, body, headers)

    assert parse_object(response, CompactParser) == (Object(
        mime_type='image/jpeg',
        content_id='20170817170218718581000000',
        description='anthem',
        object_id='1',
        url=None,
        preferred=True,
        data=b'binary content',
    ), )
Ejemplo n.º 7
0
def test_parse_object_single_location_true():
    headers = {
        'Content-Type': 'image/jpeg;charset=US-ASCII',
        'Content-ID': '20170817170218718581000000',
        'Object-ID': '1',
        'Location': 'http://cdn.rets.com/1.jpg',
        'Content-Description': 'anthem',
        'Preferred': '1',
    }
    body = b''
    response = make_response(200, body, headers)

    assert parse_object(response) == (Object(
        mime_type='image/jpeg',
        content_id='20170817170218718581000000',
        description='anthem',
        object_id='1',
        url='http://cdn.rets.com/1.jpg',
        preferred=True,
        data=None,
    ), )