def test_json(self): from notaliens.people.models import UserProfile profile = UserProfile(latitude=1, longitude=2) json = profile.__json__(None) assert json['location'] == {'lat': 1, 'lon': 2}
def test_json(self): from notaliens.people.models import UserProfile profile = UserProfile(latitude=1, longitude=2) json = profile.__json__(None) assert json['location'] == { 'lat': 1, 'lon': 2 }
def test_display_name(self): from notaliens.people.models import UserProfile from notaliens.identity.models import User user = User(username='******') profile = UserProfile(user=user) assert profile.display_name == 'sontek' profile.first_name = 'John' assert profile.display_name == 'John' profile.last_name = 'Anderson' assert profile.display_name == 'John Anderson'
def test_location(self): from notaliens.people.models import UserProfile from notaliens.core.models.meta import Country profile = UserProfile() assert profile.location == "" profile.city = "Sometown" assert profile.location == "Sometown" profile.state = "California" assert profile.location == "Sometown, California" country = Country(alpha2="US") profile.country = country assert profile.location == "Sometown, California, US"
def generate_default_data(session): from notaliens.identity.models import User from notaliens.people.models import UserProfile from notaliens.sites.models import Site global_data = setup_global_data(session) username = input("What is your username?: ") email = input("What is your email?: ") password = getpass("What is your password?: ") first_name = input("What is your first name?: ") last_name = input("What is your last name?: ") one_liner = input("Please provide a max of 140 char description: ") postal_code = input("What is your postal code? ") skill_strings = input("Do you have any skills (comma separated)? ") skill_strings = set([s.strip().lower() for s in skill_strings.split(',')]) site = Site( url='http://docs.pylonsproject.org/projects/pyramid/en/1.4-branch/', description='Pyramid homepage', title='Pyramid Project') admin = User( username=username, email=email, password=password, ) profile = UserProfile(user=admin, first_name=first_name, last_name=last_name, one_liner=one_liner, postal=postal_code) for skill in skill_strings: profile.skills.append(SkillTag(name=skill)) session.add(site) session.add(admin) session.add(profile) session.flush() user_names = ['sontek', 'kober', 'housewifehacker', 'ketnos', 'rusty'] users = [admin] for x in range(0, 50): username = '******' % (random.choice(user_names), x) user = User(username=username, email='*****@*****.**' % (username), password='******') first_names = [ 'John', 'Robert', 'Ashley', 'Jessica', 'Alex', 'Greg', 'Morgan', 'Graham', 'Fred', 'Mike', 'Ted', 'Melissa' ] last_names = [ 'Anderson', 'Smith', 'Henderson', 'Jones', 'Doe', 'Davis', 'White', 'Garcia' ] postal_codes = [ 69008, 94061, 32571, 90210, 13010, 50304, 78748, '02627', 94160, 95062, 36675, 75017, 92050 ] skill_sets = [ 'pyramid', 'python', 'redis', 'elasticsearch', 'zodb', 'mako', 'postgresql', 'docker', 'openstack', 'zope', 'plone' ] skill_objects = [] for skill in skill_sets: obj = session.query(SkillTag).filter( SkillTag.name == skill).first() if obj is None: obj = SkillTag(name=skill) session.add(obj) skill_objects.append(obj) profile = UserProfile( user=user, first_name=random.choice(first_names), last_name=random.choice(last_names), one_liner='', postal=random.choice(postal_codes), ) amount_of_skills = random.randint(1, 8) new_skills = set() for i in range(0, amount_of_skills): new_skill = random.choice(skill_objects) new_skills.add(new_skill) for new_skill in new_skills: profile.skills.append(new_skill) users.append(user) session.add(user) session.add(profile) global_data['users'] = users return global_data