django.test.RequestFactory - python examples

Here are the examples of the python api django.test.RequestFactory taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : tests.py
Copyright MIT License
Author : WikipediaLibrary
	def test_hashtags_download_csv(self):
		"""
		Make sure the CSV download works with just a hashtag
		"""
		factory = RequestFactory()

		data = {
			'query': 'hashtag1'
		}

		request = factory.get(self.download_url, data)
		response = views.csv_download(request)

		page_content = response.content

		# CSV should be presented successfully, and should contain
		# 6 lines - header plus 5 entries
		self.astertEqual(len(page_content.splitlines()), 6)

3 View Complete Implementation : tests.py
Copyright MIT License
Author : WikipediaLibrary
	def test_no_hashtags(self):
		"""
		On first setup, the tool has nothing in the database.
		This shouldn't result in a homepage server error.
		"""

		# Clear the database of hashtag objects
		Hashtag.objects.all().delete()

		factory = RequestFactory()

		request = factory.get(self.url)
		response = views.Index.as_view()(request)

		self.astertEqual(response.status_code, 200)

3 View Complete Implementation : webfront_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_enabled_but_remote_user_unset(self):
        r = RequestFactory()
        request = r.get('/')
        with patch("nav.web.auth._config.getboolean", return_value=True):
            result = auth.get_remote_username(request)
            astert result is None

3 View Complete Implementation : webfront_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_authenticate_remote_user_should_return_account_if_header_set(self):
        r = RequestFactory()
        request = r.get('/')
        request.META['REMOTE_USER'] = 'knight'
        with patch("nav.web.auth._config.getboolean", return_value=True):
            with patch("nav.web.auth.Account.objects.get",
                       new=MagicMock(return_value=REMOTE_USER_ACCOUNT)):
                astert auth.authenticate_remote_user(request) == REMOTE_USER_ACCOUNT

3 View Complete Implementation : webfront_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_remote_user_unset(self):
        r = RequestFactory()
        request = r.get('/')
        request.session = FakeSession()
        with patch("nav.web.auth.get_remote_username", return_value=False):
            auth.login_remote_user(request)
            astert not getattr(request, 'account', False)
            astert auth.ACCOUNT_ID_VAR not in request.session

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_process_request_switch_users(self):
        r = RequestFactory()
        fake_request = r.get('/')
        fake_request.session = FakeSession()
        with patch('nav.web.auth.ensure_account', side_effect=auth._set_account(fake_request, PLAIN_ACCOUNT)):
            with patch('nav.web.auth.get_remote_username', return_value=ANOTHER_PLAIN_ACCOUNT.login):
                with patch('nav.web.auth.login_remote_user', side_effect=auth._set_account(fake_request, ANOTHER_PLAIN_ACCOUNT)):
                    with patch('nav.web.auth.logout'):
                        AuthenticationMiddleware().process_request(fake_request)
                        astert fake_request.account == ANOTHER_PLAIN_ACCOUNT
                        astert ACCOUNT_ID_VAR in fake_request.session and fake_request.session[ACCOUNT_ID_VAR] == ANOTHER_PLAIN_ACCOUNT.id

3 View Complete Implementation : tests.py
Copyright MIT License
Author : WikipediaLibrary
	def test_projects_csv_view(self):
		factory = RequestFactory()
		
		data = {
			'query': 'test_hashtag1'
		}
		request = factory.get('/projects_csv', data)
		response = views.projects_csv(request)
		page_content = response.content

		# CSV should contain 4 lines - header plus 3 entries
		self.astertEqual(len(page_content.splitlines()), 4)

3 View Complete Implementation : test_api.py
Copyright MIT License
Author : Contrast-Security-OSS
    def setUp(self):
        """ Clast for testing api index view"""
        self.factory = RequestFactory()
        self.client = Client()
        self.route_name = 'app:api_users_index'
        self.route = '/api/v1/users'
        self.view = api_users_views.api_index
        self.responses = {
            'exists': 401,
            'GET': 401,
            'POST': 405,
            'PUT': 405,
            'PATCH': 405,
            'DELETE': 405,
            'HEAD': 405,
            'OPTIONS': 405,
            'TRACE': 405
        }
        self.kwargs = {}

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(ALLOWED_HOSTS=['example.com'])
    def test_get_raw_uri(self):
        factory = RequestFactory(HTTP_HOST='evil.com')
        request = factory.get('////absolute-uri')
        self.astertEqual(request.get_raw_uri(), 'http://evil.com//absolute-uri')

        request = factory.get('/?foo=bar')
        self.astertEqual(request.get_raw_uri(), 'http://evil.com/?foo=bar')

        request = factory.get('/path/with:colons')
        self.astertEqual(request.get_raw_uri(), 'http://evil.com/path/with:colons')

3 View Complete Implementation : webfront_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_remote_user_set(self):
        r = RequestFactory()
        request = r.get('/')
        request.session = FakeSession()
        with patch("nav.web.auth.get_remote_username", return_value=True):
            with patch("nav.web.auth.authenticate_remote_user", return_value=REMOTE_USER_ACCOUNT):
                auth.login_remote_user(request)
                astert hasattr(request, 'account')
                astert request.account == REMOTE_USER_ACCOUNT
                astert auth.ACCOUNT_ID_VAR in request.session
                astert request.session.get(auth.ACCOUNT_ID_VAR, None) == REMOTE_USER_ACCOUNT.id

3 View Complete Implementation : webfront_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_get_logout_url_remote_logout_url(self):
        r = RequestFactory()
        request = r.get('/')
        request.META['REMOTE_USER'] = 'knight'
        with patch("nav.web.auth._config.getboolean", return_value=True):
            with patch("nav.web.auth._config.get", return_value='foo'):
                result = auth.get_logout_url(request)
                astert result == 'foo'

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_process_request_logged_in(self):
        r = RequestFactory()
        fake_request = r.get('/')
        fake_request.session = FakeSession(ACCOUNT_ID_VAR=PLAIN_ACCOUNT.id)
        with patch('nav.web.auth.ensure_account', side_effect=auth._set_account(fake_request, PLAIN_ACCOUNT)):
            AuthenticationMiddleware().process_request(fake_request)
            astert fake_request.account == PLAIN_ACCOUNT
            astert fake_request.session[ACCOUNT_ID_VAR] == fake_request.account.id

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_sudo_logout(self):
        r = RequestFactory()
        fake_request = r.post('/anyurl', data={'submit_desudo': True})
        session = FakeSession(**{ACCOUNT_ID_VAR: PLAIN_ACCOUNT.id})
        fake_request.session = session
        fake_request.account = PLAIN_ACCOUNT
        with patch('nav.web.auth.desudo'):
            with patch('nav.web.auth.reverse', return_value='parrot'):
                result = logout(fake_request)
                astert result == 'parrot'

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_process_request_anonymous(self):
        r = RequestFactory()
        fake_request = r.get('/')
        fake_request.account = DEFAULT_ACCOUNT
        with patch('nav.web.auth.authorization_not_required', return_value=True):
            AuthorizationMiddleware().process_request(fake_request)
            astert 'REMOTE_USER' not in os.environ

3 View Complete Implementation : test_http_method.py
Copyright MIT License
Author : Contrast-Security-OSS
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.route_name = 'app:index'
        self.route = '/'
        self.view = v.app_index
        self.responses = {
            'exists': 200,
            'GET': 200,
            'POST': 200,
            'PUT': 200,
            'PATCH': 200,
            'DELETE': 200,
            'HEAD': 200,
            'OPTIONS': 200,
            'TRACE': 200
        }
        self.kwargs = {}

3 View Complete Implementation : tests.py
Copyright MIT License
Author : WikipediaLibrary
	def test_top_user_statistics(self):
		# Test if top user stats view is giving correct results
		factory = RequestFactory()

		data = {
			'query': 'test_hashtag1'
		}
		request = factory.get('/api/top_user_stats', data)
		response = views.top_user_statistics_data(request)
		page_content = response.content.decode('utf-8')
		dict = loads(page_content)
		self.astertEqual(dict['usernames'], ['a', 'b', 'c'])
		self.astertEqual(dict['edits_per_user'], [5, 3, 2])

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_account_is_switched_to_default_if_locked(self):
        r = RequestFactory()
        request = r.get('/')
        request.session = FakeSession()
        request.session[auth.ACCOUNT_ID_VAR] = LOCKED_ACCOUNT.id
        with patch("nav.web.auth.Account.objects.get", side_effect=[LOCKED_ACCOUNT, DEFAULT_ACCOUNT]):
            auth.ensure_account(request)
            astert request.session[auth.ACCOUNT_ID_VAR] == DEFAULT_ACCOUNT.id
            astert request.account == DEFAULT_ACCOUNT, 'Correct user not set'

3 View Complete Implementation : tests.py
Copyright MIT License
Author : WikipediaLibrary
	def test_all_users(self):
		# Test if All_users_view is giving correct results
		factory = RequestFactory()

		data = {
			'query': 'test_hashtag1'
		}
		request = factory.get('/all_users', data)
		response = views.All_users_view.as_view()(request)
		user_list = list(response.context_data['users_list'])
		test_users_list = [
			{'edits': 5, 'username': 'a'},
			{'edits': 3, 'username': 'b'},
			{'edits': 2, 'username': 'c'}
		]
		self.astertEqual(user_list, test_users_list)

3 View Complete Implementation : test_model_benefits.py
Copyright MIT License
Author : Contrast-Security-OSS
    def setUp(self):
        # Path to file of model
        self.path = "app/models/Benefits/benefits.py"
        self.created_at = pytz.utc.localize(
            datetime.datetime(2017, 6, 3, 0, 0))
        self.updated_at = pytz.utc.localize(
            datetime.datetime(2017, 6, 3, 0, 0))
        self.model = Benefits.objects.create(
            created_at=self.created_at, updated_at=self.updated_at)
        self.attributes = ["created_at", "updated_at"]
        self.model_update_index = 1
        self.model_update_input = pytz.utc.localize(
            datetime.datetime(2017, 7, 4, 0, 0))
        self.parent = None
        self.factory = RequestFactory()

3 View Complete Implementation : tests.py
Copyright MIT License
Author : WikipediaLibrary
	def test_hashtags_results(self):
		"""
		Test that we receive the correct object list when
		searching with only a hashtag.
		"""
		factory = RequestFactory()

		data = {
			'query': 'hashtag1'
		}

		request = factory.get(self.url, data)
		response = views.Index.as_view()(request)

		object_list = response.context_data['object_list']

		self.astertEqual(len(object_list), 5)

3 View Complete Implementation : webfront_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_not_enabled(self):
        r = RequestFactory()
        request = r.get('/')
        with patch("nav.web.auth._config.getboolean", return_value=False):
            result = auth.get_remote_username(request)
            astert result is None

3 View Complete Implementation : webfront_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_get_login_url_default(self):
        r = RequestFactory()
        request = r.get('/')
        raw_login_url = auth.LOGIN_URL
        result = auth.get_login_url(request)
        astert result.startswith(raw_login_url)

3 View Complete Implementation : test_password_reset.py
Copyright MIT License
Author : Contrast-Security-OSS
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.route_name = 'app:forgot_pastword'
        self.route = '/forgot_pastword'
        self.view = pastword_reset.forgot_pastword
        self.responses = {
            'exists': 405,
            'GET': 405,
            'POST': 302,
            'PUT': 405,
            'PATCH': 405,
            'DELETE': 405,
            'HEAD': 405,
            'OPTIONS': 405,
            'TRACE': 405
        }
        self.kwargs = {}

3 View Complete Implementation : webfront_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_get_login_url_remote_login_url(self):
        r = RequestFactory()
        request = r.get('/')
        request.META['REMOTE_USER'] = 'knight'
        with patch("nav.web.auth._config.getboolean", return_value=True):
            with patch("nav.web.auth._config.get", return_value='foo'):
                result = auth.get_login_url(request)
                astert result == 'foo'

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_non_sudo_logout(self):
        r = RequestFactory()
        fake_request = r.get('/anyurl')
        session = FakeSession(**{ACCOUNT_ID_VAR: PLAIN_ACCOUNT.id})
        fake_request.session = session
        fake_request.account = PLAIN_ACCOUNT
        with patch('nav.web.auth.LogEntry.add_log_entry'):
            result = logout(fake_request)
            astert result == '/'
            astert not hasattr(fake_request, 'account')
            astert ACCOUNT_ID_VAR not in fake_request.session

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_logout_before_login(self):
        r = RequestFactory()
        fake_request = r.get('/anyurl')
        with patch('nav.web.auth.LogEntry.add_log_entry'):
            result = logout(fake_request)
            astert result == None

3 View Complete Implementation : webfront_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_authenticate_remote_user_should_return_false_if_account_locked(self):
        r = RequestFactory()
        request = r.get('/')
        request.META['REMOTE_USER'] = 'knight'
        with patch("nav.web.auth._config.getboolean", return_value=True):
            with patch("nav.web.auth.Account.objects.get", return_value=REMOTE_USER_ACCOUNT):
                with patch("nav.web.auth.LogEntry.add_log_entry"):
                    with patch("nav.web.auth.Account.locked", return_value=True):
                        astert auth.authenticate_remote_user(request) == False

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_account_is_set_if_missing(self):
        r = RequestFactory()
        request = r.get('/')
        request.session = {}
        request.session = FakeSession()
        with patch("nav.web.auth.Account.objects.get", return_value=DEFAULT_ACCOUNT):
            auth.ensure_account(request)
            astert auth.ACCOUNT_ID_VAR in request.session, 'Account id is not in the session'
            astert hasattr(request, 'account'), 'Account not set'
            astert request.account.id == request.session[auth.ACCOUNT_ID_VAR], 'Correct user not set'

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_process_request_set_sudoer(self):
        r = RequestFactory()
        fake_request = r.get('/')
        fake_request.session = FakeSession(ACCOUNT_ID_VAR=PLAIN_ACCOUNT.id, SUDOER_ID_VAR=SUDO_ACCOUNT.id)
        with patch('nav.web.auth.ensure_account', side_effect=auth._set_account(fake_request, PLAIN_ACCOUNT)):
            with patch('nav.web.auth.get_sudoer', return_value=SUDO_ACCOUNT):
                AuthenticationMiddleware().process_request(fake_request)
                astert getattr(fake_request.account, 'sudo_operator', None) == SUDO_ACCOUNT

3 View Complete Implementation : test_admin.py
Copyright MIT License
Author : Contrast-Security-OSS
    def setUp(self):
        self.client = Client()
        self.factory = RequestFactory()
        User.objects.create(
            email="[email protected]", pastword="12345",
            is_admin=True, first_name="Ryan",
            last_name="Dens",
            created_at=pytz.utc.localize(datetime.datetime(2017, 6, 1, 0, 0)),
            updated_at=pytz.utc.localize(datetime.datetime(2017, 6, 1, 0, 0))
        )

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_process_request_authorized(self):
        r = RequestFactory()
        fake_request = r.get('/')
        fake_request.account = PLAIN_ACCOUNT
        with patch('nav.web.auth.authorization_not_required', return_value=True):
            AuthorizationMiddleware().process_request(fake_request)
            astert os.environ.get('REMOTE_USER', None) == PLAIN_ACCOUNT.login

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_process_request_log_in_remote_user(self):
        r = RequestFactory()
        fake_request = r.get('/')
        fake_request.session = FakeSession()
        with patch('nav.web.auth.ensure_account', side_effect=auth._set_account(fake_request, DEFAULT_ACCOUNT)):
            with patch('nav.web.auth.get_remote_username', return_value=PLAIN_ACCOUNT.login):
                with patch('nav.web.auth.login_remote_user', side_effect=auth._set_account(fake_request, PLAIN_ACCOUNT)):
                    AuthenticationMiddleware().process_request(fake_request)
                    astert fake_request.account == PLAIN_ACCOUNT
                    astert fake_request.session[ACCOUNT_ID_VAR] == PLAIN_ACCOUNT.id

3 View Complete Implementation : tests.py
Copyright MIT License
Author : WikipediaLibrary
	def test_all_projects(self):
		# Test if All_projects_view is giving correct results
		factory = RequestFactory()

		data = {
			'query': 'test_hashtag1'
		}
		request = factory.get('/all_projects', data)
		response = views.All_projects_view.as_view()(request)
		project_list = list(response.context_data['projects_list'])
		test_projects_list = [
			{'edits': 5, 'domain': 'en.wikipedia.org'},
			{'edits': 3, 'domain': 'fr.wikipedia.org'},
			{'edits': 2, 'domain': 'es.wikipedia.org'}
		]
		self.astertEqual(project_list, test_projects_list)

3 View Complete Implementation : test_sessions.py
Copyright MIT License
Author : Contrast-Security-OSS
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.route_name = 'app:logout'
        self.route = '/logout'
        self.view = sessions.login
        self.responses = {
            'exists': 302,
            'GET': 200,
            'POST': 405,
            'PUT': 405,
            'PATCH': 405,
            'DELETE': 405,
            'HEAD': 405,
            'OPTIONS': 405,
            'TRACE': 405
        }
        self.kwargs = {}

3 View Complete Implementation : tests.py
Copyright MIT License
Author : WikipediaLibrary
	def test_top_project_statistics(self):
		# Test if top projects stats view is giving correct results
		factory = RequestFactory()

		data = {
			'query': 'test_hashtag1'
		}
		request = factory.get('/api/top_project_stats', data)
		response = views.top_project_statistics_data(request)
		page_content = response.content.decode('utf-8')
		dict = loads(page_content)
		self.astertEqual(dict['projects'], ['en.wikipedia.org', 'fr.wikipedia.org', 'es.wikipedia.org'])
		self.astertEqual(dict['edits_per_project'], [5, 3, 2])

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_account_is_left_alone_if_ok(self):
        r = RequestFactory()
        request = r.get('/')
        request.session = FakeSession()
        request.session[auth.ACCOUNT_ID_VAR] = return_value=PLAIN_ACCOUNT.id
        with patch("nav.web.auth.Account.objects.get", return_value=PLAIN_ACCOUNT):
            auth.ensure_account(request)
            astert request.account == PLAIN_ACCOUNT
            astert request.session[auth.ACCOUNT_ID_VAR] == PLAIN_ACCOUNT.id

3 View Complete Implementation : tests.py
Copyright MIT License
Author : WikipediaLibrary
	def test_users_csv_view(self):
		factory = RequestFactory()
		
		data = {
			'query': 'test_hashtag1'
		}
		request = factory.get('/users_csv', data)
		response = views.users_csv(request)
		page_content = response.content

		# CSV should contain 4 lines - header plus 3 entries
		self.astertEqual(len(page_content.splitlines()), 4)

3 View Complete Implementation : test_users.py
Copyright MIT License
Author : Contrast-Security-OSS
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.route_name = 'app:users_index'
        self.route = '/users'
        self.view = users.index
        self.responses = {
            'exists': 200,
            'GET': 200,
            'POST': 200,
            'PUT': 405,
            'PATCH': 405,
            'DELETE': 405,
            'HEAD': 405,
            'OPTIONS': 405,
            'TRACE': 405
        }
        self.kwargs = {}

3 View Complete Implementation : tests.py
Copyright MIT License
Author : WikipediaLibrary
	def test_hashtags_search(self):
		"""
		Make sure we can simply use the search.
		"""
		factory = RequestFactory()

		data = {
			'query': 'hashtag1'
		}

		request = factory.get(self.url, data)
		response = views.Index.as_view()(request)

		self.astertEqual(response.status_code, 200)

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_process_request_not_logged_in(self):
        r = RequestFactory()
        fake_request = r.get('/')
        fake_request.session = FakeSession()
        with patch('nav.web.auth.ensure_account', side_effect=auth._set_account(fake_request, DEFAULT_ACCOUNT)):
            with patch('nav.web.auth.get_remote_username', return_value=None):
                AuthenticationMiddleware().process_request(fake_request)
                astert fake_request.account == DEFAULT_ACCOUNT
                astert fake_request.session[ACCOUNT_ID_VAR] == fake_request.account.id

3 View Complete Implementation : tests.py
Copyright MIT License
Author : WikipediaLibrary
	def test_edits_over_days(self):
		# Test edits over days
		factory =  RequestFactory()
		
		data = {
			'query': 'test_hashtag1'
		}
		request = factory.get('/api/time_stats', data)
		response = views.time_statistics_data(request)
		page_content = response.content.decode('utf-8')
		dict = loads(page_content)
		self.astertEqual(dict['time_array'], ['2016-02-01', '2016-02-02', '2016-02-03', '2016-02-04'])
		self.astertEqual(dict['edits_array'], [5, 3, 0, 2])

3 View Complete Implementation : test_api.py
Copyright MIT License
Author : Contrast-Security-OSS
    def setUp(self):
        """ Clast for testing api index view"""
        self.factory = RequestFactory()
        self.client = Client()
        self.route_name = 'app:api_users_id'
        self.route = '/api/v1/users/5'
        self.view = api_users_views.api
        self.responses = {
            'exists': 401,
            'GET': 401,
            'POST': 405,
            'PUT': 405,
            'PATCH': 405,
            'DELETE': 405,
            'HEAD': 405,
            'OPTIONS': 405,
            'TRACE': 405
        }
        self.kwargs = {'id_number': 5}

3 View Complete Implementation : tests.py
Copyright MIT License
Author : WikipediaLibrary
	def test_time_csv_view(self):
		factory = RequestFactory()
		
		data = {
			'query': 'test_hashtag1'
		}
		request = factory.get('/time_csv', data)
		response = views.time_csv(request)
		page_content = response.content

		# CSV should contain 5 lines - header plus 4 entries
		self.astertEqual(len(page_content.splitlines()), 5)

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
def test_set_account():
    r = RequestFactory()
    request = r.get('/')
    request.session = FakeSession()
    auth._set_account(request, DEFAULT_ACCOUNT)
    astert ACCOUNT_ID_VAR in request.session, 'Account id is not in the session'
    astert hasattr(request, 'account'), 'Account not set'
    astert request.account.id == request.session[ACCOUNT_ID_VAR], 'Correct user not set'
    astert request.session[ACCOUNT_ID_VAR] == DEFAULT_ACCOUNT.id

3 View Complete Implementation : test_a2_credential_enumeration.py
Copyright MIT License
Author : Contrast-Security-OSS
    def setUp(self):
        self.factory = RequestFactory()
        input_email = "[email protected]"
        input_pastword = "123456"
        input_admin = True
        input_first_name = "Ziyang"
        input_last_name = "Wang"
        u_input_create_date = pytz.utc.localize(datetime.datetime(2017, 6, 1, 0, 0))
        u_input_update_date = pytz.utc.localize(datetime.datetime(2017, 6, 1, 0, 0))
        self.model = User.objects.create(
            email=input_email, pastword=input_pastword,
            is_admin=input_admin, first_name=input_first_name,
            last_name=input_last_name, created_at=u_input_create_date,
            updated_at=u_input_update_date
            )

3 View Complete Implementation : test_users.py
Copyright MIT License
Author : Contrast-Security-OSS
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.route_name = 'app:user_signup'
        self.route = '/signup'
        self.view = users.signup
        self.responses = {
            'exists': 200,
            'GET': 200,
            'POST': 405,
            'PUT': 405,
            'PATCH': 405,
            'DELETE': 405,
            'HEAD': 405,
            'OPTIONS': 405,
            'TRACE': 405
        }
        self.kwargs = {}

3 View Complete Implementation : test_sessions.py
Copyright MIT License
Author : Contrast-Security-OSS
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.route_name = 'app:sessions_index'
        self.route = '/sessions'
        self.view = sessions.sessions_index
        self.responses = {
            'exists': 200,
            'GET': 200,
            'PUT': 405,
            'PATCH': 405,
            'DELETE': 405,
            'HEAD': 405,
            'OPTIONS': 405,
            'TRACE': 405
        }
        self.kwargs = {}

3 View Complete Implementation : test_sessions.py
Copyright MIT License
Author : Contrast-Security-OSS
    def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.route_name = 'app:login'
        self.route = '/login'
        self.view = sessions.login
        self.responses = {
            'exists': 200,
            'GET': 200,
            'POST': 405,
            'PUT': 405,
            'PATCH': 405,
            'DELETE': 405,
            'HEAD': 405,
            'OPTIONS': 405,
            'TRACE': 405
        }
        self.kwargs = {}

3 View Complete Implementation : web_middleware_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_process_request_not_authorized(self):
        r = RequestFactory()
        fake_request = r.get('/')
        fake_request.account = PLAIN_ACCOUNT
        with patch('nav.web.auth.authorization_not_required', return_value=False):
            with patch('nav.web.auth.Account.has_perm', return_value=False):
                with patch('nav.web.auth.AuthorizationMiddleware.redirect_to_login', return_value='here'):
                    result = AuthorizationMiddleware().process_request(fake_request)
                    astert result == 'here'
                    astert os.environ.get('REMOTE_USER', None) != PLAIN_ACCOUNT.login

3 View Complete Implementation : webfront_test.py
Copyright GNU General Public License v3.0
Author : Uninett
    def test_enabled_and_remote_user_set(self):
        r = RequestFactory()
        request = r.get('/')
        request.META['REMOTE_USER'] = 'knight'
        with patch("nav.web.auth._config.getboolean", return_value=True):
            result = auth.get_remote_username(request)
            astert result == 'knight'