Example #1
0
 def test_db_creation_1(self): 
     a=keyvalue()
     self.assertEqual( a.create("aber",'{"ab":123}'), "Data added to the Datastore Successfully")
Example #2
0
 def test_db_modify_1(self):
     a=keyvalue()
     a.create("ajskk",'{"ab":123123}')
     self.assertEqual(a.modify("ajskk",'{"ab":123123}'),"Data modified succesfully")
Example #3
0
 def test_db_modify_2(self):
     a=keyvalue()
     self.assertEqual(a.modify("wac",'{"ab":123123}'),"Error : Key doesn't exist")
Example #4
0
 def test_db_read_1(self):
     a=keyvalue()
     self.assertEqual(a.read("ajsk"),'{"ab":123}')
Example #5
0
 def test_db_read_2(self):
     a=keyvalue()
     self.assertEqual(a.read("wac"),"Error : Key doesn't exist")
Example #6
0
 def test_db_deletion_1(self):
     a=keyvalue()
     self.assertEqual(a.delete("aber"),"Key deleted Successfully")
Example #7
0
 def test_db_deletion_2(self):
     a=keyvalue()
     self.assertEqual(a.delete("wac"),"Error : Key doesn't exist")
Example #8
0
 def test_db_creation_6(self): 
     a=keyvalue()
     self.assertEqual( a.create("ajskajskajskajskajskajskajskajskajskajskajskajsk",'{"ab":123}'), "Error : Length of Key is more than 32 Characters")
Example #9
0
 def test_db_creation_4(self): 
     a=keyvalue()
     self.assertEqual( a.create("ajsk",23), "Value is not a JSON Object")
Example #10
0
 def test_db_creation_3(self): 
     a=keyvalue()
     self.assertEqual( a.create(12,'{"ab":123}'), "Error : Key contains unrecognised characters")
Example #11
0
 def test_db_creation_2(self): 
     a=keyvalue()
     self.assertEqual( a.create("aber",'{"ab":123}'), "Error : Key already exist")
Example #12
0
from keyvaluedb import keyvalue
#importing keyvalue class from keyvaluedb.py file

a=keyvalue()
#creating a object of the class type "keyvalue" without arguments
#So the path and filename are set to default ones
#We can do create, read, modify and delete operations to a key value data store 
#using this object

a=keyvalue(path)
#creating a object with passing one argument
#This argument is considered as path
#filename is not set here. Hence a default file name is used

a=keyvalue(path,filename)
#creating a object with passing two arguments
#Here first argument is the file path and second argument is the filename
#Since the datastore we create is of type JSON use a filename ending with ".json"


a.create(key,value,time-to-live)
#We created a New entry in our keyvalue database
#Here the first argument is the "key" that is of type string capped at 32 characters
#Key should not contain any characters other than a-z and A-Z
#Second argument is a "JSON object" limited at a maximum size of 16Kb 
#Use single quotes outside of the JSON object since JSON contains double quotes which leads to error.
#Third argument is the time-to-live property. This is optional.
#If this is set then that entry could be accessed only for the mentioned seconds from the time of creation
#If this is not set or set to zero then the lifetime of the entry is infinite.

a.read(key)