Esempio n. 1
0
def basic_creation():
    q = quantum.now()

    Assert(q.tz) == None
    Assert.isinstance(q.as_utc(), datetime)
    with Assert.raises(quantum.QuantumException):
        Assert.isinstance(q.as_local(), datetime)

    q = quantum.parse('2013-06-27T12:27:54', timezone='UTC')

    Assert(q.tz) == pytz.utc
    Assert.isinstance(q.as_utc(), datetime)
    Assert(q.as_utc()) == datetime(2013, 6, 27, 12, 27, 54)
    Assert(q.as_local()) == datetime(2013, 6, 27, 12, 27, 54)

    q = quantum.parse('2013-06-27T12:27:54', timezone='Pacific/Auckland')

    Assert(q.tz) == pytz.timezone('Pacific/Auckland')
    Assert.isinstance(q.dt, datetime)
    Assert(q.as_utc()) == datetime(2013, 6, 27, 0, 27, 54)
    Assert(q.as_local()) == datetime(2013, 6, 27, 12, 27, 54)

    q = quantum.parse('2013-06-26 3:27pm', timezone='UTC', relaxed=True)

    Assert(q.tz) == pytz.utc
    Assert.isinstance(q.dt, datetime)
    Assert(q.as_utc()) == datetime(2013, 6, 26, 15, 27, 0)
    Assert(q.as_local()) == datetime(2013, 6, 26, 15, 27, 0)

    q = quantum.parse('2013-06-26 3:27pm', relaxed=True, timezone='Pacific/Auckland')

    Assert(q.tz) == pytz.timezone('Pacific/Auckland')
    Assert.isinstance(q.dt, datetime)
    Assert(q.as_utc()) == datetime(2013, 6, 26, 3, 27, 0)
    Assert(q.as_local()) == datetime(2013, 6, 26, 15, 27, 0)
Esempio n. 2
0
def encoding():
    Assert(tjson.dumps({})) == '{}'
    Assert(tjson.dumps([])) == '[]'
    Assert(tjson.dumps('Hello')) == '"Hello"'

    with Assert.raises(quantum.QuantumException):
        Assert(tjson.dumps(quantum.now()))
Esempio n. 3
0
def import_begin():
    class Form(wtf.Form):
        title = wtf.StringField('Title')
        source = wtf.StringField('Source', description='e.g. Statistics New Zealand')
        data_file = wtf.FileField(
            'File to import',
            [wtf.validators.Required()],
            allow_clear = False,
        )

    form = Form()

    if form.validate_on_submit():
        m.Source(title=form.title.data,
                 source=form.source.data,
                 file=form.data_file.data,
                 created=quantum.now('Pacific/Auckland'),
                 creator=g.user,
                 filename=form.data_file.data.file.filename).save()
        flash('Source "%s" added' % form.title.data)
        return redirect(url_for('index.sources'))

    return dict(form=form)
Esempio n. 4
0
def formatting():
    with Assert.raises(quantum.QuantumException):
        quantum.now().format_date() == '1 Feb 2013'

    q = quantum.parse('2013-02-01', relaxed=True, timezone='UTC')
    assert q.format_date() == '1 Feb 2013'