コード例 #1
0
ファイル: fixtures.py プロジェクト: LilJohny/FriendsRenting
def generate_profiles(session):
    from faker import Faker
    from models.profile import Profile
    from password_generator import PasswordGenerator
    faker = Faker()
    pwo = PasswordGenerator()
    usernames = []
    mails = []
    for i in range(0, 8000):
        profile = faker.simple_profile()
        while profile['username'] in usernames or profile['mail'] in mails:
            print('generating profile')
            profile = faker.simple_profile()
        username, name, surname, mail, address, sex, birth_date = parse_profile(
            profile)
        profile = Profile()
        profile.username = username
        profile.name = name
        profile.surname = surname
        profile.mail = mail
        profile.address = address
        profile.sex = sex
        profile.birth_date = birth_date
        profile.password = pwo.generate()
        profile.profile_id = i + 1
        session.add(profile)
        usernames.append(username)
        mails.append(mail)
    session.commit()
コード例 #2
0
def register():
    logging.debug('add profile form : %s', str(request.form))
    logging.info('receive socket from /register-data -> profile: %s', request.form['profile-name'])
    form = request.form
    if form['profile-password'] != form['profile-repassword']:
        return render_template('v3-login.html', error=_('Your confirmation password does not match the password you entered'))
    profile = Profile()
    profile.name = form['profile-name']
    profile.firstname = form['profile-firstname']
    profile.address = form['profile-address']
    profile.comp_address = form['profile-comp_address']
    profile.city = form['profile-city']
    profile.zipcode = form['profile-zipcode']
    profile.country = form['profile-country']
    profile.phone = form['profile-phone']
    profile.email = form['profile-email']
    profile.siret = form['profile-siret']
    profile.password = form['profile-password']
    pdao = ProfileDAO()
    if pdao.insert(profile):
        logging.info('add profile %s OK', profile.name)
        session['logged_in'] = pdao.field(pdao.where('email', profile.email), 'id')[0][0]
    else:
        logging.info('add profile %s FAILED', profile.name)
        return render_template('v3-login.html', error=_('Impossible to create new user, please contact an admin !'))

    return redirect('/')
コード例 #3
0
    def test_init_method(self):
        """
        tests the __init__ method for instantiating new objects
        both new and from kwargs
        __init__ method calls on inherited BaseModel with super()
        """
        # creates new instance of Profile
        new_obj1 = Profile()
        # tests that the new object is of type Profile
        self.assertIs(type(new_obj1), Profile)
        # adds all attributes for testing
        # (id should be set by primary key)
        # (created_at, updated_at should be set by datetime)
        new_obj1.name = "test_name"
        new_obj1.email = "*****@*****.**"
        new_obj1.password = "******"
        new_obj1.company_school_name = "123"
        new_obj1.about_me = "This is for testing purposes"
        new_obj1.linkedin = "https://www.linkedin.com/in/test"
        new_obj1.social_media = "Social media links would go here"
        # attributes_dict sets up dictionary of attribute names and types
        attributes_dict = {
            "id": str,
            "created_at": datetime,
            "updated_at": datetime,
            "name": str,
            "email": str,
            "password": str,
            "company_school_name": str,
            "about_me": str,
            "linkedin": str,
            "social_media": str
        }
        # loops through attributes_dict as subTests to check each attribute
        for attr, attr_type in attributes_dict.items():
            with self.subTest(attr=attr, attr_type=attr_type):
                # tests the expected attribute is in the object's dict
                self.assertIn(attr, new_obj1.__dict__)
                # tests the attribute is the expected type
                self.assertIs(type(new_obj1.__dict__[attr]), attr_type)
        # sets kwargs using object's dict and uses to create new object
        kwargs = new_obj1.__dict__
        new_obj2 = Profile(**kwargs)
        # tests that the new object is of type Profile
        self.assertIs(type(new_obj2), Profile)
        # loops through attributes_dict as subTests to check each attribute
        for attr, attr_type in attributes_dict.items():
            with self.subTest(attr=attr, attr_type=attr_type):
                # tests the expected attribute is in the object's dict
                self.assertIn(attr, new_obj2.__dict__)
                # tests the attribute is the expected type
                self.assertIs(type(new_obj2.__dict__[attr]), attr_type)
                # tests the value of name attribute matches the original object
                self.assertEqual(new_obj1.__dict__[attr],
                                 new_obj2.__dict__[attr])

        # tests that __class__ is not set in object 2
        self.assertNotIn('__class__', new_obj2.__dict__)
コード例 #4
0
 def test_attribute_types(self):
     """
     tests the class attributes exist and are of correct type
     also tests instantiation of new object
     """
     # creates new instance of Profile
     new_obj = Profile()
     # adds name and email as required attribute for database
     # adds optional attributes for testing
     # (id should be set by primary key)
     # (created_at, updated_at should be set by datetime)
     new_obj.name = "test_name"
     new_obj.email = "*****@*****.**"
     new_obj.password = "******"
     new_obj.company_school_name = "123"
     new_obj.about_me = "This is for testing purposes"
     new_obj.linkedin = "https://www.linkedin.com/in/test"
     new_obj.social_media = "Social media links would go here"
     # attributes_dict sets up dictionary of attribute names and types
     attributes_dict = {
         "id": str,
         "created_at": datetime,
         "updated_at": datetime,
         "name": str,
         "email": str,
         "password": str,
         "company_school_name": str,
         "about_me": str,
         "linkedin": str,
         "social_media": str
     }
     # loops through attributes_dict as subTests to check each attribute
     for attr, attr_type in attributes_dict.items():
         with self.subTest(attr=attr, attr_type=attr_type):
             # tests the expected attribute is in the instance's dict
             self.assertIn(attr, new_obj.__dict__)
             # tests the attribute is the expected type
             self.assertIs(type(new_obj.__dict__[attr]), attr_type)