Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create unit_test.py #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions unit_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import unittest
from hashlib import md5
from cashier import Cashier ,cache

class cashier_tests(unittest.TestCase):
"""class for running unit tests on Cashier"""
def setUp(self):
self.cache_inst = Cashier(file_name="unit_testing")
self.cache_inst.clear()

def test_CRUD_operation(self):
"""objective :to perform CRUD operations using cashier"""

test_set_1=['test_string_1','special_char_str ^@#$%&#*#%$^',\
"big string jksaldjflkjlkjgn,zmnc,vmn,msnfm,mn,mn"]
test_set_2=['test_string_2','special_char_str^@#$%&#*#%$^',\
"big string jksaldjflkjlkjgn,zmnc,mn,msnfm,mn,mn"]
try :
"""create and read operations"""
for val in test_set_1 :
key=md5(val.encode('utf8')).hexdigest()
self.cache_inst.set(key,val)
assert self.cache_inst.get(key) in test_set_1,"missing value "

"""update operation"""
for val in test_set_1:
index_val=test_set_1.index(val)
key=md5(val.encode('utf8')).hexdigest()
self.cache_inst.set(key,test_set_2[index_val])
assert self.cache_inst.get(key) in test_set_2,"missing value"

"""delete operation """
for val in test_set_1:
key=md5(val.encode('utf8')).hexdigest()
self.cache_inst.delete(key)

except Exception as e:
print("something went wrong :",str(e))


if __name__ =="__main__" :
unittest.main()