示例#1
0
def get_user_data(test_locale='en'):
    person = {}
    user = Personal(test_locale)
    address = Address(test_locale)

    person['first_name'], person['last_name'] = user.full_name(gender='male').split()
    common.success("Generated user name '%s %s'" % (person['first_name'], person['last_name']))
    person['email'] = user.email(gender='male')
    common.success("Generated email '%s'" % person['email'])
    person['street'] = address.address()
    person['city'] = address.city()
    person['state'] = address.state()
    person['postcode'] = address.postal_code()
    common.success("Generated address '%s %s, %s, %s'" % (person['postcode'], person['state'], person['city'], person['street']))
    person['password'] = ''.join(random.SystemRandom().choice(string.digits + string.ascii_letters) for _ in range(10))
    common.success("Generated password '%s'" % person['password'])
    if (test_locale == 'en'):
        person['country_code'] = 'US'
        person['country'] = 'United States'
        person['state_code'] = 'IA'
        person['state'] = 'Iowa'
    elif (test_locale == 'ru'):
        person['country_code'] = 'RU'
        person['country'] = 'Russian Federation'
        person['state_code'] = None
        person['state'] = None
    else:
        person['country_code'] = None
        person['country'] = None
        person['state_code'] = None
        person['state'] = None
    common.success("Generated country '%s' and state '%s'" % (person['country'], person['state']))
    return person
示例#2
0
    def init(count=2000, locale='en'):
        from elizabeth import Personal, Text
        gen = Personal(locale)
        text = Text(locale)

        for _ in range(count):
            gen_post = Contact(name=gen.name(),
                               num=gen.credit_card_number(),
                               some_blank=text.text(3),
                               some_null=gen.email())
            gen_post.save()
示例#3
0
    def setUp(self):
        self.app = create_app("testing")
        self.client = self.app.test_client()
        self.context = self.app.app_context()
        self.context.push()
        db.create_all()
        person = Personal()
        text = Text()
        kwargs = {
            "username": person.username(),
            "email": person.email(),
            "password": person.password(16)
        }
        user = User(**kwargs)
        user.save()

        def __auth():
            response = self.client.post("/api/auth",
                                        data=json.dumps(kwargs),
                                        content_type="application/json")
            self.assertEqual(response.status_code, 200)

        def __post():
            post = Post(title=self.text.title(),
                        summary=text.text(3),
                        body=text.text(6),
                        author=user)
            category = Category(name=text.word())
            category.save()
            post.category = category
            tag = Tag(name=text.word())
            tag.save()
            post.tags.append(tag)
            post.save()
            return post

        self.login = __auth
        self.new_post = __post
        del kwargs["email"]
        self.data = {"kwargs": kwargs, "user": user}
        self.text = text
        self.person = person
示例#4
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)
示例#5
0
 def mail():
     personal = Personal('ru')
     login = personal.email(gender='female')
     password = personal.password(length=15)
     b = 'login: '******'\n' + 'pass: '******'\n \n Enjoy, sweety...'
     return b
示例#6
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())