예제 #1
0
def test_serialize_date():
    """Testing datetime_utils.serialize_date
    We need to verify the following scenarios:
        * passing an unicode date, return the same date but str
        * passing a timedelta, return now plus the delta
        * passing an invalid object, should raise ValueError
    """
    ret = datetime_utils.serialize_date(u'Mon, 20 Nov 1995 19:12:08 GMT')
    assert type(ret) is (str)
    eq_(ret, 'Mon, 20 Nov 1995 19:12:08 GMT')
    dt = formatdate(
        calendar.timegm(
            (datetime.datetime.now()+datetime.timedelta(1)).timetuple()), usegmt=True)
    eq_(dt, datetime_utils.serialize_date(datetime.timedelta(1)))
    assert_raises(ValueError, datetime_utils.serialize_date, None)
예제 #2
0
def test_serialize_date():
    """Testing datetime_utils.serialize_date
    We need to verify the following scenarios:
        * passing an unicode date, return the same date but str
        * passing a timedelta, return now plus the delta
        * passing an invalid object, should raise ValueError
    """
    ret = datetime_utils.serialize_date(u'Mon, 20 Nov 1995 19:12:08 GMT')
    assert type(ret) is (str)
    eq_(ret, 'Mon, 20 Nov 1995 19:12:08 GMT')
    dt = formatdate(calendar.timegm(
        (datetime.datetime.now() + datetime.timedelta(1)).timetuple()),
                    usegmt=True)
    eq_(dt, datetime_utils.serialize_date(datetime.timedelta(1)))
    assert_raises(ValueError, datetime_utils.serialize_date, None)
예제 #3
0
def test_serialize_date():
    """Testing datetime_utils.serialize_date
    We need to verify the following scenarios:
        * on py3, passing an binary date, return the same date but str
        * on py2, passing an unicode date, return the same date but str
        * passing a timedelta, return now plus the delta
        * passing an invalid object, should raise ValueError
    """
    from webob.compat import text_
    ret = datetime_utils.serialize_date('Mon, 20 Nov 1995 19:12:08 GMT')
    assert isinstance(ret, str)
    assert ret == 'Mon, 20 Nov 1995 19:12:08 GMT'
    ret = datetime_utils.serialize_date(text_('Mon, 20 Nov 1995 19:12:08 GMT'))
    assert isinstance(ret, str)
    assert ret == 'Mon, 20 Nov 1995 19:12:08 GMT'
    dt = formatdate(calendar.timegm(
        (datetime.datetime.now() + datetime.timedelta(1)).timetuple()),
                    usegmt=True)
    assert dt == datetime_utils.serialize_date(datetime.timedelta(1))
    with pytest.raises(ValueError):
        datetime_utils.serialize_date(None)
def test_serialize_date():
    """Testing datetime_utils.serialize_date
    We need to verify the following scenarios:
        * on py3, passing an binary date, return the same date but str
        * on py2, passing an unicode date, return the same date but str
        * passing a timedelta, return now plus the delta
        * passing an invalid object, should raise ValueError
    """
    from webob.compat import text_
    ret = datetime_utils.serialize_date('Mon, 20 Nov 1995 19:12:08 GMT')
    assert isinstance(ret, str)
    eq_(ret, 'Mon, 20 Nov 1995 19:12:08 GMT')
    ret = datetime_utils.serialize_date(text_('Mon, 20 Nov 1995 19:12:08 GMT'))
    assert isinstance(ret, str)
    eq_(ret, 'Mon, 20 Nov 1995 19:12:08 GMT')
    dt = formatdate(
        calendar.timegm(
            (datetime.datetime.now()+datetime.timedelta(1)).timetuple()),
        usegmt=True)
    eq_(dt, datetime_utils.serialize_date(datetime.timedelta(1)))
    assert_raises(ValueError, datetime_utils.serialize_date, None)
예제 #5
0
    def test_serves_signature_file(self, db_request):
        project = ProjectFactory.create()
        release = ReleaseFactory.create(project=project)
        file_ = FileFactory.create(
            release=release,
            filename="{}-{}.tar.gz".format(project.name, release.version),
            python_version="source",
            has_signature=True,
        )

        path = "/".join([
            file_.blake2_256_digest[:2],
            file_.blake2_256_digest[2:4],
            file_.blake2_256_digest[4:],
            file_.filename + ".asc",
        ])

        storage_service = pretend.stub(
            get=pretend.call_recorder(
                lambda path: io.BytesIO(b"some data for the fake file")
            )
        )

        db_request.matchdict["path"] = path
        db_request.find_service = pretend.call_recorder(
            lambda iface: storage_service
        )

        resp = views.packages(db_request)

        # We want to roundtrip our upload_time
        last_modified = datetime_utils.parse_date(
            datetime_utils.serialize_date(file_.upload_time)
        )

        assert db_request.find_service.calls == [pretend.call(IFileStorage)]
        assert storage_service.get.calls == [pretend.call(path)]

        assert resp.content_type == "application/octet-stream"
        assert resp.content_encoding is None
        assert resp.etag == file_.md5_digest
        assert resp.last_modified == last_modified
        assert resp.content_length is None
        # This needs to be last, as accessing resp.body sets the content_length
        assert resp.body == b"some data for the fake file"
예제 #6
0
    def test_serves_signature_file(self, db_request):
        project = ProjectFactory.create()
        release = ReleaseFactory.create(project=project)
        file_ = FileFactory.create(
            release=release,
            filename="{}-{}.tar.gz".format(project.name, release.version),
            python_version="source",
            has_signature=True,
        )

        path = "/".join([
            file_.blake2_256_digest[:2],
            file_.blake2_256_digest[2:4],
            file_.blake2_256_digest[4:],
            file_.filename + ".asc",
        ])

        storage_service = pretend.stub(get=pretend.call_recorder(
            lambda path: io.BytesIO(b"some data for the fake file")))

        db_request.matchdict["path"] = path
        db_request.find_service = pretend.call_recorder(
            lambda iface: storage_service)

        resp = views.packages(db_request)

        # We want to roundtrip our upload_time
        last_modified = datetime_utils.parse_date(
            datetime_utils.serialize_date(file_.upload_time))

        assert db_request.find_service.calls == [pretend.call(IFileStorage)]
        assert storage_service.get.calls == [pretend.call(path)]

        assert resp.content_type == "application/octet-stream"
        assert resp.content_encoding is None
        assert resp.etag == file_.md5_digest
        assert resp.last_modified == last_modified
        assert resp.content_length is None
        # This needs to be last, as accessing resp.body sets the content_length
        assert resp.body == b"some data for the fake file"
예제 #7
0
    def test_serves_signature_file(self, db_request, pyramid_config):
        memfs = fs.memoryfs.MemoryFS()

        pyramid_config.registry["filesystems"] = {"packages": memfs}

        project = ProjectFactory.create()
        release = ReleaseFactory.create(project=project)
        file_ = FileFactory.create(
            release=release,
            filename="{}-{}.tar.gz".format(project.name, release.version),
            python_version="source",
        )

        path = "source/{}/{}/{}.asc".format(
            project.name[0], project.name, file_.filename
        )

        memfs.makedir(os.path.dirname(path), recursive=True)
        memfs.setcontents(path, b"some data for the fake file")

        db_request.matchdict["path"] = path

        resp = views.packages(db_request)

        # We want to roundtrip our upload_time
        last_modified = datetime_utils.parse_date(
            datetime_utils.serialize_date(file_.upload_time)
        )

        assert resp.content_type == "application/octet-stream"
        assert resp.content_encoding is None
        assert resp.etag == file_.md5_digest
        assert resp.last_modified == last_modified
        assert resp.content_length is None
        # This needs to be last, as accessing resp.body sets the content_length
        assert resp.body == b"some data for the fake file"
예제 #8
0
def serialize_if_range(value):
    if isinstance(value, (datetime, date)):
        return serialize_date(value)
    value = str(value)
    return value or None
예제 #9
0
def serialize_if_range(value):
    if isinstance(value, (datetime, date)):
        return serialize_date(value)
    value = str(value)
    return value or None
예제 #10
0
 def __str__(self):
     return serialize_date(self.date)
예제 #11
0
파일: etag.py 프로젝트: Pylons/webob
 def __str__(self):
     return serialize_date(self.date)