class MasterAdminTestCase(FunctionalTestCase): def setUp(self): super(MasterAdminTestCase, self).setUp() self.master_admin = UserFactory(email='*****@*****.**', is_superuser=True, is_staff=True) self.master_admin.set_password('neptune123') self.master_admin.save() def log_in_master_admin(self): master_admin_session = SessionStore() master_admin_session[SESSION_KEY] = self.master_admin.pk master_admin_session[ BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0] master_admin_session[ HASH_SESSION_KEY] = self.master_admin.get_session_auth_hash() master_admin_session.save() self.visit('') self.browser.add_cookie({ 'name': settings.SESSION_COOKIE_NAME, 'value': master_admin_session.session_key, 'path': '/' }) def wait_for_success_message(self, message): self.wait_for_element_contains_text('.messagelist .success', message) def wait_for_error_message(self, message=None): self.wait_for_element_contains_text( '.errornote', message or 'Please correct the errors below.')
def test_welcome_messages(self): user = UserFactory() resp = self.client.post('/fi/kayttaja/kirjaudu-sisaan/', { 'username': user.username, 'password': DEFAULT_PASSWORD }, follow=True) self.assertRedirects(resp, '/fi/kayttaja/{}/'.format(user.pk), target_status_code=200) self.assertNotContains(resp, 'Käytit palvelua viimeksi') self.assertContains(resp, 'Tervetuloa Nuortenideat.fi palveluun!') user.joined -= timedelta(seconds=5) user.save() resp = self.client.post('/fi/kayttaja/kirjaudu-sisaan/', { 'username': user.username, 'password': DEFAULT_PASSWORD }, follow=True) self.assertContains(resp, 'Käytit palvelua viimeksi') self.assertNotContains(resp, 'Tervetuloa Nuortenideat.fi palveluun!')