def test_signup_page_flow(self): # Check that things are empty self.assertLength(0, Profile.all()) # Sign up with the form response = self.app.post(self.uri_for('signup'), self.SIGNUP_DATA) self.assertRedirects(response, self.uri_for('dashboard', tour='')) # Check that we are actually logged in response = self.app.get(response.location) self.assertLoggedIn() # Check that one of everything was created self.assertLength(1, Profile.all()) profile = Profile.all().get() # Check the basic data self.assertEqual(self.SIGNUP_DATA['email'], profile.email) self.assertEqual(self.SIGNUP_DATA['name'], profile.name) # Logout and log back in to test that the password works self.logout() response = self.login(self.SIGNUP_DATA['email'], self.SIGNUP_DATA['password']) self.assertRedirects(response, self.uri_for('dashboard'))
def test_signup_with_existing_email(self): response = self.app.post(self.uri_for('signup'), self.SIGNUP_DATA) self.assertRedirects(response) self.assertLength(1, Profile.all()) response = self.app.post(self.uri_for('signup'), self.SIGNUP_DATA) self.assertOk(response) self.assertLength(1, Profile.all()) email_field = response.pyquery('input#email') self.assertLength(1, email_field) self.assertNotEqual('', email_field.attr['data-error'])
def test_signup_sends_welcome_email(self): # Sign up successfully response = self.app.post(self.uri_for('signup'), self.SIGNUP_DATA) self.assertRedirects(response, self.uri_for('dashboard', tour='')) # Check that a profile was created profile = Profile.get_by_email(self.SIGNUP_DATA['email']) self.assertIsNotNone(profile) # Check that a mail-sending task is in the queue tasks = self.taskqueue_stub.GetTasks('mail') self.assertLength(1, tasks) # Run the task (it should be a deferred call) and check that an e-mail # is sent task, = tasks deferred.run(base64.b64decode(task['body'])) messages = self.mail_stub.get_sent_messages() self.assertLength(1, messages) message, = messages self.assertEqual('"%s" <%s>' % (profile.name, profile.email), message.to) self.assertEqual('Welcome to Daily Meeting!', message.subject) self.assertEqual('"Daily Meeting" <*****@*****.**>', message.sender) self.assertEqual( '"Daily Meeting Support" <*****@*****.**>', message.reply_to) activation_key = Profile.all().get().activation_key activation_url = self.uri_for('profile.activate', k=activation_key) self.assertIn(activation_url, message.body.decode()) self.assertIn(activation_url, message.html.decode())
def test_signup_sends_welcome_email(self): # Sign up successfully response = self.app.post(self.uri_for('signup'), self.SIGNUP_DATA) self.assertRedirects(response, self.uri_for('dashboard', tour='')) # Check that a profile was created profile = Profile.get_by_email(self.SIGNUP_DATA['email']) self.assertIsNotNone(profile) # Check that a mail-sending task is in the queue tasks = self.taskqueue_stub.GetTasks('mail') self.assertLength(1, tasks) # Run the task (it should be a deferred call) and check that an e-mail # is sent task, = tasks deferred.run(base64.b64decode(task['body'])) messages = self.mail_stub.get_sent_messages() self.assertLength(1, messages) message, = messages self.assertEqual('"%s" <%s>' % (profile.name, profile.email), message.to) self.assertEqual('Welcome to Daily Meeting!', message.subject) self.assertEqual('"Daily Meeting" <*****@*****.**>', message.sender) self.assertEqual('"Daily Meeting Support" <*****@*****.**>', message.reply_to) activation_key = Profile.all().get().activation_key activation_url = self.uri_for('profile.activate', k=activation_key) self.assertIn(activation_url, message.body.decode()) self.assertIn(activation_url, message.html.decode())
def get(self): path = os.path.join(os.path.dirname(__file__), '../views/admin/index.html') template_values = { 'name': self.__class__.__name__, 'profiles': Profile.all(), } self.response.out.write(template.render(path, template_values))
def list(self): editors = Profile.all().filter('is_editor = ', True) return self.render_to_response('editors/list.haml', {'editors': editors})
def get_profiles(self): return Profile.all().ancestor(self)