def ensure_imager_profile(sender, **kwargs): if kwargs.get('created', False): try: new_profile = ImagerProfile(user=kwargs['instance']) new_profile.save() except (KeyError, ValueError): msg = 'Unable to create ImagerProfile for {}' logger.error(msg.format(kwargs['instance']))
def ensure_imager_profile(sender, **kwargs): """Create and save an ImagerProfile after every new User is created.""" if kwargs.get('created', False): try: new_profile = ImagerProfile(user=kwargs['instance']) new_profile.save() except (KeyError, ValueError): logger.error('Unable to create ImagerProfile for User instance.')
def ensure_imager_profile(sender, **kwargs): if kwargs.get('created', False): try: new_profile = ImagerProfile(user=kwargs['instance']) new_profile.save() except(KeyError, ValueError): msg = 'Unable to create Imager Profile for {}' logger.error(msg.format(kwargs['instance']))
def confirm_profile_creation(sender, **kwargs): """Post save signal.""" if kwargs.get('created', False): try: new_profile = ImagerProfile(user=kwargs['instance']) new_profile.save() except (KeyError, ValueError): message = 'Could not create profile for {}' logger.error(message.format(kwargs['instance']))
def setUp(self): """Create a user for testing purposes.""" user = User(username='******', email='*****@*****.**') user.set_password('password') user.save() profile = ImagerProfile(website='www.pics4you.com', location='Seattle', fee=500, camera='Nikon Pro 3500', services='Weddings', bio='I will take picutres for any occasion.', phone='206-555-1212', photo_style='Matte Finish', user=user ) profile.save() user = UserFactory.create() user.set_password(factory.Faker('password')) user.save() profile = ProfileFactory.create(user=user, is_active=False) profile.save() for _ in range(10): user = UserFactory.create() user.set_password(factory.Faker('password')) user.save() profile = ProfileFactory.create(user=user) profile.save()
def test_imager_profile_camera_styles_services_default_values(self): """Test default values for camera, photo_styles, and services are given to new ImagerProfile if no values entered.""" bob = User('bobdude', password='******') profile = ImagerProfile(user=bob, website='google.com', location='seattle', commission=100.00, bio='I am a person', phone='2062427983') self.assertEquals(profile.camera, 'CanonT6i') self.assertEquals(profile.services, 'Mega-Service Pack') self.assertEquals(profile.photo_styles, 'Standard')
def new_profile(username, password): """Custom function to create ImagerProfile with given user.""" user = User(username=username, password=password) user.save() return ImagerProfile(user=user, website='google.com', location='seattle', commission=50.00, camera='Nikon', services='I do stuff', bio='I am a person', phone='2062427983', photo_styles='all the styles')
def test_every_profile_must_have_a_user(self): """Test that every profile has a user.""" with self.assertRaises(Exception): imager = ImagerProfile() imager.save()
def create_profile(sender, instance, **kwargs): if kwargs.get('created', False): profile = ImagerProfile(user=instance) profile.save()
def test_create_user_profile(self): """Test saving user creates a user profile.""" george_pr = ImagerProfile(user=self.user_0) self.assertIs(george_pr, self.user_0.profile)
def test_users_have_profiles_raises_an_exception(self): """The function says it all.""" with self.assertRaises(Exception): profile = ImagerProfile() profile.save()
def test_imager_profiles_have_user(self): """Test imager profiles are associated with a user.""" with self.assertRaises(Exception): imager_user = ImagerProfile() imager_user.save()