def create_user(agency=False, google=False, yahoo=False, facebook=False, linkedin=False, microsoft=False, edirsso=False): """Create a user of the specified type. Defaults to an anonymous user.""" from tests.lib.tools import create_user from app.constants.user_type_auth import (AGENCY_USER, PUBLIC_USER_NYC_ID, PUBLIC_USER_FACEBOOK, PUBLIC_USER_LINKEDIN, PUBLIC_USER_GOOGLE, PUBLIC_USER_YAHOO, PUBLIC_USER_MICROSOFT) if agency: user = create_user(AGENCY_USER) if edirsso: user = create_user(PUBLIC_USER_NYC_ID) if facebook: user = create_user(PUBLIC_USER_FACEBOOK) if linkedin: user = create_user(PUBLIC_USER_LINKEDIN) if google: user = create_user(PUBLIC_USER_GOOGLE) if yahoo: user = create_user(PUBLIC_USER_YAHOO) if microsoft: user = create_user(PUBLIC_USER_MICROSOFT) if not (facebook or google or linkedin or microsoft or yahoo or agency or edirsso): user = create_user() print(user, "created.")
def test_get_content(self): rf = RequestsFactory(self.request_id) response = rf.add_file() unassociated_user = create_user() path = '/response/' + str(response.id) redirect_url = urljoin( flask_request.url_root, url_for('auth.index', sso2=True, return_to=urljoin(flask_request.url_root, path))) # user not authenticated (redirect) resp = self.client.get(path) self.assertEqual(resp.location, redirect_url) # user authenticated but not associated with request (400) with self.client as client: with client.session_transaction() as session: session['user_id'] = unassociated_user.get_id() session['_fresh'] = True resp = self.client.get(path) self.assertEqual(resp.status_code, 400) # user authenticated and associated with request (success) with self.client as client: with client.session_transaction() as session: session['user_id'] = rf.requester.get_id() session['_fresh'] = True resp = self.client.get(path) self.assert_file_sent(resp, rf.request.id, response.name)
def create_users(): """Create a user from each of the allowed auth_user_types.""" from app.constants.user_type_auth import PUBLIC_USER_TYPES types = [type_ for type_ in PUBLIC_USER_TYPES] from tests.lib.tools import create_user for type_ in types: user = create_user(type_) print("Created User: {guid} - {name} ({email})".format( guid=user.guid, name=user.name, email=user.email))
def test_es_doc_not_created(self): try: create_user() # Users - model without 'es_create' method except AttributeError: self.fail('es_create() called when it should not have been.')
def test_object_created(self): self.assertFalse(Users.query.first()) create_user() self.assertTrue(Users.query.first())