def signup(request): from utils.mailer import EmailHelper email = request.data.get('email', False) password = request.data.get('password', False) password_confirm = request.data.get('password_confirm', False) if len(User.objects.filter(email=email)) > 0: return Response(data={'error': 'User already exist'}, status=401) if not password or password != password_confirm: return Response(data={'error': 'Password and password confirm don\'t match'}, status=401) user = User.create(**request.data) profile = Profile.create(user=user, **request.data) # Send email confirmation_link = request.build_absolute_uri('/onboarding/confirmation/{TOKEN}'.format(TOKEN=profile.reset_token)) EmailHelper.email( template_name='onboarding_email_template', title='OpenMaker Nomination done!', vars={ 'FIRST_NAME': user.first_name.encode('utf-8'), 'LAST_NAME': user.last_name.encode('utf-8'), 'CONFIRMATION_LINK': confirmation_link, }, receiver_email=user.email ) return Response({'success': True}) if profile else Response(data={'error': 'error creating user'}, status=403)
def setUpClass(cls): cls.user_data = { 'email': '*****@*****.**', 'first_name': 'aaa_unit_test', 'last_name': 'aaa_test_unit', 'picture': '', 'password': '******', 'gender': 'Female', 'birthdate': '1980-01-12', 'city': 'Torreon', 'occupation': 'tester', 'twitter_username': '', 'place': '{"city":"Torreon","state":"Coah.","country_short":"MX","country":"Messico","lat":25.5428443,"long":-103.40678609999998}', } cls.user = User.create(**cls.user_data) profile = Profile.create(user=cls.user, **cls.user_data) # Extra fields # cls.user.profile.types_of_innovation = 'Product innovation,Technological innovation,Business model innovation' cls.user.profile.organization = 'aaa_unit_test_organization' cls.user.profile.statement = 'Hi im a test user generated from unit test suite' ## SOP cls.user.profile.source_of_inspiration.add(SourceOfInspiration.create('Apple')) cls.user.profile.source_of_inspiration.add(SourceOfInspiration.create('Microsoft')) cls.user.profile.source_of_inspiration.add(SourceOfInspiration.create('Samsung')) ## Tags cls.user.profile.tags.add(Tag.create('Innovation')) cls.user.profile.tags.add(Tag.create('Social')) cls.user.profile.tags.add(Tag.create('Design')) cls.user.profile.sector = 'ICT' cls.user.profile.technical_expertise = 'Digital fabrication - Digitalization of analog and traditional technologies' cls.user.profile.size = 'A small enterprise (<50 staff)' cls.user.profile.socialLinks = json.dumps([ {"link": "top_ix", "name": "twitter"}, {"link": "www.google.it", "name": "google-plus"}, {"link": "https://www.facebook.com/topixconsortium/", "name": "facebook"} ]) cls.user.profile.save() # Create Party cls.party = Party(cls.user) cls.party.get()
def test_1_create(self): user = User.create(**self.userdata) profile = Profile.create(user=user, **self.userdata) self.assertIsInstance(profile, Profile, Colorizer.Red('Error during profile creation'))
def test_2_check_reset_token(self): user = User.create(**self.userdata) profile = Profile.create(user=user, **self.userdata) print profile.reset_token self.assertIsNot(profile.reset_token, None, Colorizer.Red('Error during profile creation'))
def create_test_user(): password = '******' user_data = { 'email': '*****@*****.**', 'first_name': 'aaa_unit_test', 'last_name': 'aaa_test_unit', 'picture': 'images/profile/default_user_icon.png', 'password': password, 'gender': 'Female', 'birthdate': '1980-01-12', 'city': 'Torreon', 'occupation': 'tester', 'twitter_username': '', 'place': '{"city":"Torreon","state":"Coah.","country_short":"MX","country":"Messico","lat":25.5428443,"long":-103.40678609999998}', } user = User.create(**user_data) Profile.create(user=user, **user_data) user = User.objects.filter(email=user_data['email'])[0] user.is_active = True # Extra fields # cls.user.profile.types_of_innovation = 'Product innovation,Technological innovation,Business model innovation' user.profile.organization = 'aaa_unit_test_organization' user.profile.statement = 'Hi im a test user generated from unit test suite' ## SOP user.profile.source_of_inspiration.add(SourceOfInspiration.create('Apple')) user.profile.source_of_inspiration.add( SourceOfInspiration.create('Microsoft')) user.profile.source_of_inspiration.add( SourceOfInspiration.create('Samsung')) ## Tags user.profile.tags.add(Tag.create('Innovation')) user.profile.tags.add(Tag.create('Social')) user.profile.tags.add(Tag.create('Design')) user.profile.sector = 'ICT' user.profile.technical_expertise = 'Digital fabrication - Digitalization of analog and traditional technologies' user.profile.size = 'A small enterprise (<50 staff)' user.profile.socialLinks = json.dumps([{ "link": "top_ix", "name": "twitter" }, { "link": "www.google.it", "name": "google-plus" }, { "link": "https://www.facebook.com/topixconsortium/", "name": "facebook" }]) user.save() user.profile.save() return user