示例#1
0
class PersonalBaseTest(TestCase):
    def setUp(self):
        self.personal = Personal()

    def tearDown(self):
        del self.personal

    def test_str(self):
        self.assertTrue(re.match(STR_REGEX, self.personal.__str__()))

    def test_age(self):
        result = self.personal.age(maximum=55)
        self.assertTrue(result <= 55)

    def test_age(self):
        result = self.personal.age(maximum=55)
        self.assertTrue(result <= 55)

    def test_age_store(self):
        result = self.personal._store['age']
        self.assertEqual(result, 0)

    def test_age_update(self):
        result = self.personal.age() - self.personal._store[
            'age']  # calling age() should go first
        self.assertEqual(result, 0)

    def test_child_count(self):
        result = self.personal.child_count(max_childs=10)
        self.assertTrue(result <= 10)

    def test_work_experience(self):
        result = self.personal.work_experience(
            working_start_age=0) - self.personal._store['age']
        self.assertEqual(result, 0)

    def test_work_experience_store(self):
        result = self.personal.work_experience(
        ) - self.personal.work_experience()
        self.assertEqual(result, 0)

    def test_work_experience_extreme(self):
        result = self.personal.work_experience(working_start_age=100000)
        self.assertEqual(result, 0)

    def test_paypal(self):
        result = self.personal.paypal()
        self.assertIsNotNone(result)

    def test_password(self):
        plain = self.personal.password(length=15)
        self.assertEqual(len(plain), 15)

        md5 = self.personal.password(algorithm='md5')
        self.assertEqual(len(md5), 32)

        sha1 = self.personal.password(algorithm='sha1')
        self.assertEqual(len(sha1), 40)

        sha256 = self.personal.password(algorithm='sha256')
        self.assertEqual(len(sha256), 64)

        sha512 = self.personal.password(algorithm='sha512')
        self.assertEqual(len(sha512), 128)

        with self.assertRaises(NotImplementedError):
            self.personal.password(algorithm='sha42')

    def test_username(self):
        result = self.personal.username()
        self.assertTrue(re.match(USERNAME_REGEX, result))

    def test_email(self):
        result = self.personal.email()
        self.assertTrue(re.match(EMAIL_REGEX, result))

    def test_bitcoin(self):
        result = self.personal.bitcoin()
        self.assertEqual(len(result), 34)

    def test_cvv(self):
        result = self.personal.cvv()
        self.assertTrue((100 <= result) and (result <= 999))

    def test_credit_card_number(self):
        result = self.personal.credit_card_number()
        self.assertTrue(re.match(CREDIT_CARD_REGEX, result))

        result_mc = self.personal.credit_card_number(card_type='master_card')
        self.assertTrue(re.match(CREDIT_CARD_REGEX, result_mc))

        result_ax = self.personal.credit_card_number(card_type='amex')
        self.assertTrue(re.match(CREDIT_CARD_REGEX, result_ax))

        with self.assertRaises(NotImplementedError):
            self.personal.credit_card_number(card_type="discover")

    def test_expiration_date(self):
        result = self.personal.credit_card_expiration_date(minimum=16,
                                                           maximum=25)

        year = result.split('/')[1]
        self.assertTrue((int(year) >= 16) and (int(year) <= 25))

    def test_cid(self):
        result = self.personal.cid()
        self.assertTrue((1000 <= result) and (result <= 9999))

    def test_height(self):
        result = self.personal.height(minimum=1.60, maximum=1.90)
        self.assertTrue(result.startswith('1'))
        self.assertIsInstance(result, str)

    def test_weight(self):
        result = self.personal.weight(minimum=40, maximum=60)
        self.assertTrue((result >= 40) and (result <= 60))

    def test_blood_type(self):
        result = self.personal.blood_type()
        self.assertIn(result, common.BLOOD_GROUPS)

    def test_favorite_movie(self):
        result = self.personal.favorite_movie()
        self.assertIn(result, self.personal.data['favorite_movie'])

    def test_favorite_music_genre(self):
        result = self.personal.favorite_music_genre()
        self.assertIn(result, common.FAVORITE_MUSIC_GENRE)

    def test_avatar(self):
        result = self.personal.avatar(size=512)
        img, size, _, _, _, _ = result.split('/')[::-1]
        self.assertEqual(int(size), 512)
        self.assertEqual(32, len(img.split('.')[0]))

    def test_identifier(self):
        result = self.personal.identifier()
        mask = '##-##/##'
        self.assertEqual(len(mask), len(result))

        result = self.personal.identifier(mask='##', suffix=True)
        lst = result.split()
        _id, sfx = lst[0], lst[1]
        self.assertEqual(len(_id), 2)
        self.assertEqual(len(sfx), 2)

        result = self.personal.identifier(suffix=True)
        suffix = result.split(' ')[1]
        self.assertTrue(suffix.isalpha())

    def test_level_of_english(self):
        result = self.personal.level_of_english()
        lvl_s = [
            'Beginner', 'Elementary', 'Pre - Intermediate', 'Intermediate',
            'Upper Intermediate', 'Advanced', 'Proficiency'
        ]
        self.assertIn(result, lvl_s)
示例#2
0
class PersonalBaseTest(TestCase):
    def setUp(self):
        self.personal = Personal()

    def tearDown(self):
        del self.personal

    def test_age(self):
        result = self.personal.age(maximum=55)
        self.assertTrue(result <= 55)

    def test_paypal(self):
        result = self.personal.paypal()
        self.assertIsNotNone(result)

    def test_password(self):
        plain = self.personal.password(length=15)
        self.assertEqual(len(plain), 15)

        md5 = self.personal.password(algorithm='md5')
        self.assertEqual(len(md5), 32)

        sha1 = self.personal.password(algorithm='sha1')
        self.assertEqual(len(sha1), 40)

        sha256 = self.personal.password(algorithm='sha256')
        self.assertEqual(len(sha256), 64)

        sha512 = self.personal.password(algorithm='sha512')
        self.assertEqual(len(sha512), 128)

    def test_username(self):
        result = self.personal.username()
        self.assertTrue(re.match(USERNAME_REGEX, result))

    def test_email(self):
        result = self.personal.email()
        self.assertTrue(re.match(EMAIL_REGEX, result))

    def test_bitcoin(self):
        result = self.personal.bitcoin()
        self.assertEqual(len(result), 34)

    def test_cvv(self):
        result = self.personal.cvv()
        self.assertTrue((100 <= result) and (result <= 999))

    def test_credit_card_number(self):
        result = self.personal.credit_card_number()
        self.assertTrue(re.match(CREDIT_CARD_REGEX, result))

    def test_expiration_date(self):
        result = self.personal.credit_card_expiration_date(minimum=16,
                                                           maximum=25)

        year = result.split('/')[1]
        self.assertTrue((int(year) >= 16) and (int(year) <= 25))

    def test_cid(self):
        result = self.personal.cid()
        self.assertTrue((1000 <= result) and (result <= 9999))

    def test_height(self):
        result = self.personal.height(minimum=1.60, maximum=1.90)
        self.assertTrue(result.startswith('1'))
        self.assertIsInstance(result, str)

    def test_weight(self):
        result = self.personal.weight(minimum=40, maximum=60)
        self.assertTrue((result >= 40) and (result <= 60))

    def test_blood_type(self):
        result = self.personal.blood_type()
        self.assertIn(result, common.BLOOD_GROUPS)

    def test_favorite_movie(self):
        result = self.personal.favorite_movie()
        self.assertIn(result, self.personal.data['favorite_movie'])

    def test_favorite_music_genre(self):
        result = self.personal.favorite_music_genre()
        self.assertIn(result, common.FAVORITE_MUSIC_GENRE)

    def test_avatar(self):
        result = self.personal.avatar()
        self.assertTrue(len(result) > 20)

    def test_identifier(self):
        result = self.personal.identifier()
        mask = '##-##/##'
        self.assertEqual(len(mask), len(result))

        result = self.personal.identifier(mask='##', suffix=True)
        lst = result.split()
        _id, sfx = lst[0], lst[1]
        self.assertEqual(len(_id), 2)
        self.assertEqual(len(sfx), 2)

        result = self.personal.identifier(suffix=True)
        suffix = result.split(' ')[1]
        self.assertTrue(suffix.isalpha())