# DRF Rack # Библиотека классов расширений для Django REST Framework # # Автор: Николай В. Анохин # Все права защищены. Лицензия: MIT """ Описание класса CryptoTests """ from net.xeaf.rack.core import CoreTestCase from net.xeaf.rack.util import Crypto class CryptoTests(CoreTestCase): """ Тесты для Crypto """ def test_gen_token(self): """ Тест генерации токена """ token = Crypto.gen_token() self.assertEqual(len(token), Crypto.DEFAULT_TOKEN_LENGTH) self.assertLowerHex(token) def test_gen_token_length(self): """ Тест генерации токена с указанием длины """ token = Crypto.gen_token(length=15) self.assertEqual(len(token), 15) def test_gen_token_different(self): """ Тест генерации разных токенов """ token1 = Crypto.gen_token() token2 = Crypto.gen_token() self.assertNotEqual(token1, token2) def test_gen_pin_code(self): """ Тест генерации PIN-кода """ pin_code = Crypto.gen_pin_code() self.assertEqual(len(pin_code), Crypto.DEFAULT_PIN_CODE_LENGTH) self.assertTrue(all(c in Crypto.DEFAULT_PIN_CODE_ALPHABET for c in pin_code)) def test_gen_pin_code_length(self): """ Тест генерации PIN-кода с указанием длины """ pin_code = Crypto.gen_pin_code(length=8) self.assertEqual(len(pin_code), 8) self.assertTrue(all(c in Crypto.DEFAULT_PIN_CODE_ALPHABET for c in pin_code)) def test_gen_pin_code_alphabet(self): """ Тест генерации PIN-кода с указанием алфавита """ letters = 'ABCD' pin_code = Crypto.gen_pin_code(alphabet=letters) self.assertEqual(len(pin_code), Crypto.DEFAULT_PIN_CODE_LENGTH) self.assertTrue(all(c in letters for c in pin_code)) def test_gen_pin_code_different(self): """ Тест генерации разных PIN-кодов """ pin_code_1 = Crypto.gen_pin_code() pin_code_2 = Crypto.gen_pin_code() self.assertNotEqual(pin_code_1, pin_code_2)