Exemple #1
0
 def test_is_using_existing_file(self):
     
     self.dataname = 'db_names_2.txt'
     self.myfile = open('db_names_2.txt', 'tw', encoding='utf-8')
     self.myfile.close()
     self.user3 = auth()
     self.user3.create_db(self.dataname,1)
     self.assertEqual(self.dataname, self.user3.dataname)
Exemple #2
0
 def test_is_right_password(self):
     self.name = 'Manya'
     self.password = '******'
     self.fake_password = '******'
             
     self.user11 = auth()
     self.user11.add_user(self.name, self.password)
     self.assertEqual(self.user11.check_user(self.name, self.fake_password),'Неверно указан пароль')
Exemple #3
0
 def test_is_right_name(self):
     self.name = 'Senya'
     self.fake_name = 'Ssenya'
     self.password = '******'
             
     self.user10 = auth()
     self.user10.add_user(self.name, self.password)
             self.assertEqual(self.user10.check_user(self.fake_name, self.password),'Неверно указано имя')
Exemple #4
0
 def test_data_load(self):
     self.names = {'Kolya':'123456'}
     self.dataname = 'db_names.txt'
     self.myfile = open(self.dataname, mode='w')
     json.dump(self.names, self.myfile)
     self.myfile.close()
     self.user1 = auth()
     self.assertEqual(self.names, self.user1.names)
Exemple #5
0
 def test_is_authentificated(self):
     self.name = 'Slava'
     self.right_name = 'Slava'
     self.password = '******'
     self.right_password = '******'
             
     self.user11 = auth()
     self.user11.add_user(self.name, self.password)
     self.assertEqual(self.user11.check_user(self.right_name, self.right_password),'Пользователь аутентифицирован')
Exemple #6
0
 def test_is_user_existing(self):
     self.name = 'Misha'
     self.password = '******'
     self.names = {self.name:self.password}
     self.dataname = 'db_names.txt'
     self.myfile = open(self.dataname, mode='w')
     json.dump(self.names, self.myfile)
     self.myfile.close()
     self.user6 = auth()
     self.assertRaises(ValueError, self.user6.add_user, self.name, self.password)
Exemple #7
0
 def test_is_user_in_memory(self):
     self.name = 'Petya'
     self.password = '******'
     self.passwd_hash = hashlib.md5(bytes(self.password, "UTF-8")).hexdigest()
     self.user8 = auth()
     self.user8.add_user(self.name, self.password)
     if self.name in self.user8.names:
         self.assertTrue(True)
     else:
         self.assertTrue(False)
     self.assertEqual(self.user8.names[self.name], self.passwd_hash)
Exemple #8
0
 def test_is_password_secured(self):
     self.name = 'Vasya'
     self.password = '******'
     self.names = {self.name:self.password}
     self.dataname = 'db_names.txt'
     self.myfile = open(self.dataname, mode='w')
     json.dump(self.names, self.myfile)
     self.myfile.close()
     self.user7 = auth()
     self.user7.add_user(self.name, self.password)
     self.assertNotEqual(self.password, self.user7.passwd_hash)
Exemple #9
0
 def test_is_user_deleted_from_memory(self):
     self.name = 'Senya'
     self.password = '******'
     self.user12 = auth()
     self.user12.add_user(self.name, self.password)
     self.user12.delete_user(self.name, self.password)
     
     if self.name not in self.user12.names:
         self.assertTrue(True)
     else:
         self.assertTrue(False)
Exemple #10
0
 def test_empty_file(self):
     self.names = {}
     self.dataname = 'db_names.txt'
     self.myfile = open('db_names.txt', 'tw', encoding='utf-8')
     self.myfile.close()
     self.myfile = open(self.dataname, mode='r')
     try:
         json_data = json.load(self.myfile)
     except json.decoder.JSONDecodeError as err:
         json_data = {}
     self.names = json_data
     self.myfile.close()
     self.user2 = auth()
     self.assertEqual(self.names, self.user2.names)
Exemple #11
0
 def test_is_user_deleted_from_file(self):
     self.name = 'Klara'
     self.password = '******'
     self.user13 = auth()
     self.user13.add_user(self.name, self.password)
     self.user13.delete_user(self.name, self.password)
     self.dataname = 'db_names.txt'
     self.myfile = open(self.dataname, mode='r')
     try:
         json_data = json.load(self.myfile)
     except json.decoder.JSONDecodeError as err:
         json_data = {}
     
     self.names2 = json_data
     self.myfile.close()
     if self.name not in self.names2: 
         self.assertTrue(True)
     else:
         self.assertTrue(False)
Exemple #12
0
    def test_is_user_in_file(self):
        self.name = 'Zhenya'
        self.password = '******'
        self.passwd_hash = hashlib.md5(bytes(self.password, "UTF-8")).hexdigest()
        self.names = {self.name:self.passwd_hash}
        
        self.user9 = auth()
        self.user9.add_user(self.name, self.password)
        
        self.dataname = 'db_names.txt'
        self.myfile = open(self.dataname, mode='r')
        try:
            json_data = json.load(self.myfile)
        except json.decoder.JSONDecodeError as err:
            json_data = {}
        
        self.names2 = json_data
        self.myfile.close()

        if self.name in self.names2 and self.names2[self.name]==self.passwd_hash:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
Exemple #13
0
 def test_is_using_default_file(self):
     self.dataname = 'db_names_8.txt'
     self.user5 = auth()
     self.user5.create_db(self.dataname,0)
     self.assertEqual('db_names.txt', self.user5.dataname)
Exemple #14
0
 def test_is_creating_new_file(self):
     self.dataname = 'db_names_3.txt'
     self.user4 = auth()
     self.user4.create_db(self.dataname)
     self.assertEqual(self.dataname, self.user4.dataname)