예제 #1
0
def build_request(repository, post_data, auth):
    files = []
    for key in ('content', 'gpg_signature'):
        if key in post_data:
            filename_, value = post_data.pop(key)
            files.append((key, filename_, value))
    content_type, body = encode_multipart(post_data.items(), files)

    headers = {'Content-type': content_type,
               'Content-length': str(len(body)),
               'Authorization': auth}

    return Request(repository, data=body, headers=headers)
예제 #2
0
def build_request(repository, post_data, auth):
    files = []
    for key in ('content', 'gpg_signature'):
        if key in post_data:
            filename_, value = post_data.pop(key)
            files.append((key, filename_, value))
    content_type, body = encode_multipart(post_data.items(), files)

    headers = {
        'Content-type': content_type,
        'Content-length': str(len(body)),
        'Authorization': auth
    }

    return Request(repository, data=body, headers=headers)
예제 #3
0
    def test_build_post_data(self):
        r_content = six.b(
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n"""
            """Content-Disposition: form-data; name="maintainer"\r\n\r\n\r\n"""
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n"""
            """Content-Disposition: form-data; name="name"\r\n\r\n"""
            """foo\r\n"""
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n"""
            """Content-Disposition: form-data; name="license"\r\n\r\n\r\n"""
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n"""
            """Content-Disposition: form-data; name="author"\r\n\r\n"""
            """John Doe\r\n"""
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n"""
            """Content-Disposition: form-data; name="url"\r\n\r\n\r\n"""
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n"""
            """Content-Disposition: form-data; name=":action"\r\n\r\n"""
            """submit\r\n"""
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n"""
            """Content-Disposition: form-data; name="download_url"\r\n\r\n\r\n"""
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n"""
            """Content-Disposition: form-data; name="maintainer_email"\r\n\r\n\r\n"""
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n"""
            """Content-Disposition: form-data; name="author_email"\r\n\r\n\r\n"""
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n"""
            """Content-Disposition: form-data; name="version"\r\n\r\n"""
            """1.0\r\n"""
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n"""
            """Content-Disposition: form-data; name="long_description"\r\n\r\n\r\n"""
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n"""
            """Content-Disposition: form-data; name="description"\r\n\r\n\r\n"""
            """----------------GHSKFJDLGDS7543FJKLFHRE75642756743254--\r\n"""
            """"""
        )
        bento_info = """\
Name: foo
Version: 1.0
Author: John Doe
"""
        package = PackageDescription.from_string(bento_info)
        post_data = build_post_data(package, "submit")
        content_type, body = encode_multipart(post_data.items(), [])
        self.assertEqual(r_content, body)
예제 #4
0
    def test_build_post_data(self):
        r_content = six.b("""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n""" \
"""Content-Disposition: form-data; name="maintainer"\r\n\r\n\r\n""" \
"""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n""" \
"""Content-Disposition: form-data; name="name"\r\n\r\n""" \
"""foo\r\n""" \
"""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n""" \
"""Content-Disposition: form-data; name="license"\r\n\r\n\r\n""" \
"""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n""" \
"""Content-Disposition: form-data; name="author"\r\n\r\n""" \
"""John Doe\r\n""" \
"""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n""" \
"""Content-Disposition: form-data; name="url"\r\n\r\n\r\n""" \
"""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n""" \
"""Content-Disposition: form-data; name=":action"\r\n\r\n""" \
"""submit\r\n""" \
"""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n""" \
"""Content-Disposition: form-data; name="download_url"\r\n\r\n\r\n""" \
"""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n""" \
"""Content-Disposition: form-data; name="maintainer_email"\r\n\r\n\r\n""" \
"""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n""" \
"""Content-Disposition: form-data; name="author_email"\r\n\r\n\r\n""" \
"""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n""" \
"""Content-Disposition: form-data; name="version"\r\n\r\n""" \
"""1.0\r\n""" \
"""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n""" \
"""Content-Disposition: form-data; name="long_description"\r\n\r\n\r\n""" \
"""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254\r\n""" \
"""Content-Disposition: form-data; name="description"\r\n\r\n\r\n""" \
"""----------------GHSKFJDLGDS7543FJKLFHRE75642756743254--\r\n""" \
"""""")
        bento_info = """\
Name: foo
Version: 1.0
Author: John Doe
"""
        package = PackageDescription.from_string(bento_info)
        post_data = build_post_data(package, "submit")
        content_type, body = encode_multipart(list(post_data.items()), [])
        self.assertEqual(r_content, body)