def test_profile_bad_pk(self): from pyramid_signup.views import ProfileController self.config.add_route('index', '/') self.config.include('pyramid_signup') from pyramid_signup.models import User user = User(username='******', password='******', email='*****@*****.**', activated=True) self.session.add(user) self.session.flush() request = testing.DummyRequest() request.user = Mock() flash = Mock() request.session.flash = flash request.matchdict = Mock() get = Mock() get.return_value = 99 request.matchdict.get = get view = ProfileController(request) response = view.profile() assert response.status_int == 404
def test_profile_update_profile_invalid(self): from pyramid_signup.views import ProfileController self.config.add_route('index', '/') self.config.include('pyramid_signup') from pyramid_signup.models import User user = User(username='******', password='******', email='*****@*****.**', activated=True) self.session.add(user) self.session.flush() request = self.get_csrf_request(request_method='POST') request.user = user request.matchdict = Mock() get = Mock() get.return_value = user.pk request.matchdict.get = get flash = Mock() request.session.flash = flash view = ProfileController(request) response = view.profile() assert len(response['errors']) == 3
def test_profile_update_password(self): from pyramid_signup.views import ProfileController from pyramid_signup.managers import UserManager from pyramid_signup.interfaces import ISUSession from pyramid_signup.events import ProfileUpdatedEvent from pyramid_signup.models import crypt self.config.add_route('index', '/') self.config.include('pyramid_signup') from pyramid_signup.models import User user = User(username='******', password='******', email='*****@*****.**', activated=True) self.session.add(user) self.session.flush() def handle_profile_updated(event): request = event.request session = request.registry.getUtility(ISUSession) session.commit() self.config.add_subscriber(handle_profile_updated, ProfileUpdatedEvent) request = self.get_csrf_request(post={ 'First_Name': 'John', 'Last_Name': 'Anderson', 'Email': '*****@*****.**', 'Password': { 'value': 'test123', 'confirm': 'test123', }, }, request_method='POST') request.user = user request.matchdict = Mock() get = Mock() get.return_value = user.pk request.matchdict.get = get flash = Mock() request.session.flash = flash view = ProfileController(request) view.profile() mgr = UserManager(request) new_user = mgr.get_by_pk(user.pk) assert new_user.first_name == 'John' assert new_user.last_name == 'Anderson' assert new_user.email == '*****@*****.**' assert not crypt.check(user.password, 'temp' + user.salt)