def entry(client): """API exposes entries""" response = client.get("/api/1/entry/?id=donri") assert response.status_code == 200 assert response.content_type == "application/json" assert var(json.loads(response.data.obj)) == {"id": "donri", "type": "gismu", "affixes": ["dor", "do'i"]} response = client.get("/api/1/entry/?id=donri&locale=en") assert response.status_code == 200 assert var(json.loads(response.data.obj)) == { "id": "donri", "type": "gismu", "affixes": ["dor", "do'i"], "definition": "x1 is the daytime...", "notes": "See also {nicte}...", } response = client.get("/api/1/entry/") assert response.status_code == 400 assert response.content_type == "application/json" assert "error" in var(json.loads(response.data.obj)) response = client.get("/api/1/entry/?id=undef") assert response.status_code == 404 assert response.content_type == "application/json" assert "error" in var(json.loads(response.data.obj)) response = client.get("/api/1/entry/?id=donri&locale=zzz") assert response.status_code == 400 assert response.content_type == "application/json" assert "error" in var(json.loads(response.data.obj))
def local_proxy(): """current_db proxies to the ZODB instance""" assert var(current_db.app).is_(current_app._get_current_object()) assert var(current_app.extensions['zodb']) == current_db assert var(current_app.extensions['zodb']).is_( current_db._get_current_object())
def model_kwargs(): """Model init sets attributes with kwargs""" instance = var(TestModel(sequence=(1, 2, 3), mapping={'foo': 'bar'}, btree={'bar': 'foo'})) assert instance.sequence.__class__.is_(PersistentList) assert instance.mapping.__class__.is_(PersistentMapping) assert instance.btree.__class__.is_(OOBTree) assert instance.sequence == [1, 2, 3] assert instance.something_else.is_(None) instance = var(TestModel(other='foo', something_else=123)) assert instance.other == 'foo' assert instance.something_else == 123
def model_attributes(client): """Model instantiates factories when Model instantiated""" instance = var(TestModel()) assert instance.sequence.__class__.is_(PersistentList) assert instance.mapping.__class__.is_(PersistentMapping) assert instance.btree.__class__.is_(OOBTree) assert instance.timestamp.__class__.is_(datetime) assert instance.id.__class__.is_(UUID) assert instance.something_else.is_(None)
def write(client): """Views can write to the database""" @current_app.route('/_test/<value>') def write_value(value): db['_test'] = value client.get('/_test/Written!') with db() as root: assert var(root['_test']) == 'Written!'
def account(): """Accounts store passwords hashed and authenticates""" account = var(Account(username='******', password='******')) assert account.password != 'mipri' assert account.authenticate('mipri').is_(True) assert account.authenticate('toldra').is_(False) account.obj.password = '******' assert account.password != 'cnino' assert account.authenticate('mipri').is_(False) assert account.authenticate('cnino').is_(True)
def entries(): """Entries behave properly""" admin = Account(username='******') donri = var(Root(id='donri', affixes=['dor', "do'i"])) donri.history('en').revise( Definition( definition='x₁ is the daytime of day x₂ at location x₃.', notes='See also {nicte}, {djedi}, {tcika}.'), admin) assert donri.affixes == ['dor', "do'i"] assert donri.history('en').newest.object.definition == \ 'x₁ is the daytime of day x₂ at location x₃.' assert donri.history('en').newest.object.notes == \ 'See also {nicte}, {djedi}, {tcika}.' assert var(Root().type) == 'gismu' assert var(Root(experimental=True).type) == 'experimental gismu'
def history(): """Histories keep logs of Revisions with quick access to the newest""" history = var(History()) account = Account(username='******') first = history.revise((1, 2, 3), account, 'First!') assert history.newest.is_(first) assert history.newest.is_(history[len(history.obj)]) assert history.newest.object == (1, 2, 3) assert history.newest.author.is_(account) assert history.newest.comment == 'First!' second = history.revise((3, 2, 1), account, 'Reversed sequence') assert history.newest.is_(second) assert history.newest.object == (3, 2, 1) assert history.newest.comment == 'Reversed sequence' for revision in history.values(): assert revision.__class__.is_(Revision)
def users(): """Users have unique usernames, authenticates by username with password""" users = var(Users()) admin = users.new('admin', 'mipri') guest = users.new('guest', 'vitke') assert users['admin'].is_(admin) assert users['guest'].is_(guest) assert users.authenticate('admin', 'mipri').is_(True) assert users.authenticate('admin', 'toldra').is_(False) assert users.authenticate('guest', 'vitke').is_(True) assert users.authenticate('guest', 'srera').is_(False) with Assert.raises(ValueError): users.new('admin', 'ckiku') with Assert.raises(ValueError): users.new('guest', 'vitke') with Assert.raises(ValueError): users.authenticate('noda', 'da')
def entry(): with db() as root: root['entries']['donri'] = None assert var(schemata.Entry('donri').validate()).is_(True) assert var(schemata.Entry('claxu').validate()).is_(False)
def locale(): assert var(schemata.Locale('en').validate()).is_(True) assert var(schemata.Locale('eng').validate()).is_(False)
def tex(): text = '$x_{1}$ is not $x_2$' html = 'x<sub>1</sub> is not x<sub>2</sub>' assert var(unicode(Tex(text))) == text assert var(unicode(Markup(Tex(text)))) == html