forked from threatify/arango-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_code.py
42 lines (30 loc) · 1.08 KB
/
test_code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from datetime import date
from arango import ArangoClient
from arango_orm.database import Database
from arango_orm.collections import Collection
from marshmallow.fields import List, String, UUID, Integer, Boolean, DateTime, Date
from marshmallow import (
Schema, pre_load, pre_dump, post_load, validates_schema,
validates, fields, ValidationError
)
client = ArangoClient(username='test', password='test')
test_db = client.db('test')
db = Database(test_db)
class Person(Collection):
__collection__ = 'persons'
class _Schema(Schema):
cnic = String(required=True)
name = String(required=True, allow_none=False)
dob = Date()
_key_field = 'cnic'
db.query(Person).count()
db.query(Person).all()
p = Person(name='test', cnic='12312', dob=date(year=2016, month=9, day=12))
db.add(p)
db.query(Person).count()
pd = {'cnic': '37405-4564665-7', 'dob': '2016-09-12', 'name': 'Kashif Iftikhar'}
data, errors = Person._Schema().load(pd)
new_person = Person._load(pd)
new_col = Collection('new_collection')
db.create_collection(new_col)
db.drop_collection(new_col)