Python rest_framework.status.HTTP_302_FOUND Examples

The following are 26 code examples of rest_framework.status.HTTP_302_FOUND(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module rest_framework.status , or try the search function .
Example #1
Source File: test_forms.py    From ontask_b with MIT License 6 votes vote down vote up
def test_google_sheet_upload(self):
        """Test the Google Sheet upload."""
        # Get the regular form
        resp = self.get_response('dataops:googlesheetupload_start')
        self.assertTrue(status.is_success(resp.status_code))

        # POST the data
        filename = os.path.join(settings.ONTASK_FIXTURE_DIR, 'simple.csv')
        resp = self.get_response(
            'dataops:googlesheetupload_start',
            method='POST',
            req_params={
                'google_url': 'file://' + filename,
                'skip_lines_at_top': -1,
                'skip_lines_at_bottom': 0})
        self.assertNotEqual(resp.status_code, status.HTTP_302_FOUND)
        resp = self.get_response(
            'dataops:googlesheetupload_start',
            method='POST',
            req_params={
                'google_url': 'file://' + filename,
                'skip_lines_at_top': 0,
                'skip_lines_at_bottom': -1})
        self.assertNotEqual(resp.status_code, status.HTTP_302_FOUND) 
Example #2
Source File: test_views_run.py    From ontask_b with MIT License 6 votes vote down vote up
def test_run_canvas_email_action(self):
        """Test Canvas Email action execution."""
        action = self.workflow.actions.get(name='Initial motivation')
        column = action.workflow.columns.get(name='SID')
        resp = self.get_response('action:run', url_params={'pk': action.id})
        self.assertTrue(status.is_success(resp.status_code))

        # POST -> redirect to item filter
        resp = self.get_response(
            'action:run',
            url_params={'pk': action.id},
            method='POST',
            req_params={
                'subject': 'Email subject',
                'item_column': column.pk,
                'target_url': 'Server one',
            },
            session_payload={
                'item_column': column.pk,
                'action_id': action.id,
                'target_url': 'Server one',
                'prev_url': reverse('action:run', kwargs={'pk': action.id}),
                'post_url': reverse('action:run_done'),
            })
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND) 
Example #3
Source File: test_upload_logic.py    From ontask_b with MIT License 6 votes vote down vote up
def test_s3_upload(self):
        """Test the S3 upload."""
        # Get the regular form
        resp = self.get_response('dataops:s3upload_start')
        self.assertTrue(status.is_success(resp.status_code))

        # POST the data
        filepath = os.path.join(settings.ONTASK_FIXTURE_DIR, 'simple.csv')
        resp = self.get_response(
            'dataops:s3upload_start',
            method='POST',
            req_params={
                'aws_bucket_name': filepath.split('/')[1],
                'aws_file_key': '/'.join(filepath.split('/')[2:]),
                'skip_lines_at_top': 0,
                'skip_lines_at_bottom': 0,
                'domain': 'file:/'})
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)
        self.assertEqual(resp.url, reverse('dataops:upload_s2')) 
Example #4
Source File: test_upload_logic.py    From ontask_b with MIT License 6 votes vote down vote up
def test_google_sheet_upload(self):
        """Test the Google Sheet upload."""
        # Get the regular form
        resp = self.get_response('dataops:googlesheetupload_start')
        self.assertTrue(status.is_success(resp.status_code))

        # POST the data
        filename = os.path.join(settings.ONTASK_FIXTURE_DIR, 'simple.csv')
        resp = self.get_response(
            'dataops:googlesheetupload_start',
            method='POST',
            req_params={
                'google_url': 'file://' + filename,
                'skip_lines_at_top': 0,
                'skip_lines_at_bottom': 0})
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)
        self.assertEqual(resp.url, reverse('dataops:upload_s2')) 
Example #5
Source File: test_upload_logic.py    From ontask_b with MIT License 6 votes vote down vote up
def test_excel_upload(self):
        """Test the excel upload."""
        # Get the regular form
        resp = self.get_response('dataops:excelupload_start')
        self.assertTrue(status.is_success(resp.status_code))

        # POST the data
        filename = os.path.join(
            settings.ONTASK_FIXTURE_DIR,
            'excel_upload.xlsx')
        with open(filename, 'rb') as fp:
            resp = self.get_response(
                'dataops:excelupload_start',
                method='POST',
                req_params={'data_file': fp, 'sheet': 'results'})
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)
        self.assertEqual(resp.url, reverse('dataops:upload_s2')) 
Example #6
Source File: test_upload_logic.py    From ontask_b with MIT License 6 votes vote down vote up
def test_csv_upload(self):
        """Test the CSV upload."""
        # Get the regular form
        resp = self.get_response('dataops:csvupload_start')
        self.assertTrue(status.is_success(resp.status_code))

        # POST the data
        filename = os.path.join(settings.ONTASK_FIXTURE_DIR, 'simple.csv')
        with open(filename) as fp:
            resp = self.get_response(
                'dataops:csvupload_start',
                method='POST',
                req_params={
                    'data_file': fp,
                    'skip_lines_at_top': 0,
                    'skip_lines_at_bottom': 0})
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)
        self.assertEqual(resp.url, reverse('dataops:upload_s2')) 
Example #7
Source File: test_auth.py    From notes with GNU General Public License v3.0 6 votes vote down vote up
def test_request_token_with_post_method_and_access_key_and_signdata_and_no_login(self):
        url = reverse_lazy('cas_app:cas-request-token')
        serializer = TimedSerializer(self.secret_key)
        data = serializer.dumps({'redirect_to': self.redirect_to})
        data_extra = {
            'HTTP_X_SERVICES_PUBLIC_KEY': self.access_key,
        }
        response = self.client.post(url, data, content_type='application/json', **data_extra)
        response_data = serializer.loads(response.content)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(self.cas_consumer.cas_tokens.count(), 1)
        self.assertIn('request_token', response_data)

        request_token = response_data['request_token']

        url = reverse_lazy('cas_app:cas-user-authentication')
        response = self.client.get(url, data={
            'request_token': request_token,
        })

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)

        print response 
Example #8
Source File: test_api.py    From doccano with MIT License 5 votes vote down vote up
def test_can_upload_with_redirect(self):
        self.upload_test_helper(project_id=self.classification_project.id,
                                filename='example.jsonl',
                                next='http://somewhere',
                                file_format='json',
                                expected_status=status.HTTP_302_FOUND) 
Example #9
Source File: test_activate.py    From doccano with MIT License 5 votes vote down vote up
def test_activate_valid(self):
        """we make sure code is for the /projects redirection"""
        response = self.client.get(reverse('activate', args=[self.uid, self.token]))
        # For some reason this get rejected by Travis CI
        # File "/usr/local/lib/python3.6/site-packages/webpack_loader/loader.py", line 26, in _load_assets with open(self.config['STATS_FILE'], encoding="utf-8") as f:
        # FileNotFoundError: [Errno 2] No such file or directory: '/doccano/app/server/static/webpack-stats.json'
        # self.assertRedirects(response, '/projects/')
        self.assertEqual(response.status_code, status.HTTP_302_FOUND) 
Example #10
Source File: test_sqlconn.py    From ontask_b with MIT License 5 votes vote down vote up
def test_sql_run(self):
        """Execute the RUN step."""

        sql_conn = models.SQLConnection.objects.get(pk=1)
        self.assertIsNotNone(sql_conn)

        # Modify the item so that it is able to access the DB
        sql_conn.conn_type = 'postgresql'
        sql_conn.db_name = settings.DATABASE_URL['NAME']
        sql_conn.db_user = settings.DATABASE_URL['USER']
        sql_conn.db_password = settings.DATABASE_URL['PASSWORD']
        sql_conn.db_port = settings.DATABASE_URL['PORT']
        sql_conn.db_host = settings.DATABASE_URL['HOST']
        sql_conn.db_table = '__ONTASK_WORKFLOW_TABLE_1'
        sql_conn.save()

        # Load the first step for the sql upload form (GET)
        resp = self.get_response(
            'dataops:sqlupload_start',
            {'pk': sql_conn.id})
        self.assertTrue(status.is_success(resp.status_code))
        self.assertIn('Establish a SQL connection', str(resp.content))

        # Load the first step for the sql upload form (POST)
        resp = self.get_response(
            'dataops:sqlupload_start',
            {'pk': sql_conn.id},
            method='POST',
            req_params={'db_password': 'boguspwd'})
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)
        self.assertEqual(resp.url, reverse('dataops:upload_s2')) 
Example #11
Source File: views_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_success(self):
        """
        Test /pearson/success URL
        """
        response = self.client.get('/pearson/success/')
        assert response.status_code == status.HTTP_302_FOUND
        assert response.url == "/dashboard?exam=success" 
Example #12
Source File: views_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_error(self):
        """
        Test /pearson/error URL
        """
        response = self.client.get('/pearson/error/')
        assert response.status_code == status.HTTP_302_FOUND
        assert response.url == "/dashboard?exam=error" 
Example #13
Source File: views_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_timeout(self):
        """
        Test /pearson/error URL
        """
        response = self.client.get('/pearson/timeout/')
        assert response.status_code == status.HTTP_302_FOUND
        assert response.url == "/dashboard?exam=timeout" 
Example #14
Source File: test_utils.py    From sal with Apache License 2.0 5 votes vote down vote up
def test_ro_access(self):
        """Test that ro requests are rejected.

        RO users should not have access to the admin site (unless they have
        `is_staff = True`.
        """
        self.client.force_login(self.user)

        for path in self.admin_endpoints:
            url = reverse('admin:{}_{}_changelist'.format(self.app(), path))
            response = self.client.get(url)
            msg = 'Failed for path: "{}"'.format(path)
            self.assertEqual(response.status_code, status.HTTP_302_FOUND, msg=msg)
            self.assertEqual(response.url, '{}?next={}'.format(reverse('admin:login'), url),
                             msg=msg) 
Example #15
Source File: test_utils.py    From sal with Apache License 2.0 5 votes vote down vote up
def test_no_access(self):
        """Test that unauthenticated requests redirected to login."""
        for path in self.admin_endpoints:
            url = reverse('admin:{}_{}_changelist'.format(self.app(), path))
            response = self.client.get(url)
            # Redirect to login page.
            self.assertEqual(response.status_code, status.HTTP_302_FOUND)
            self.assertEqual(response.url, '{}?next={}'.format(reverse('admin:login'), url)) 
Example #16
Source File: test_views_importexport.py    From ontask_b with MIT License 5 votes vote down vote up
def test_action_import(self):
        """Test the import ."""
        # Get request
        resp = self.get_response(
            'action:import')
        self.assertTrue(status.is_success(resp.status_code))
        self.assertTrue('File containing a previously' in str(resp.content))

        file_obj = open(
            os.path.join(
                settings.BASE_DIR(),
                'lib',
                'surveys',
                'spq_survey.gz'),
            'rb')

        # Post request
        req = self.factory.post(
            reverse('action:import'),
            {'upload_file': file_obj})
        req.META['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate'
        req.FILES['upload_file'].content_type = 'application/x-gzip'
        req = self.add_middleware(req)
        resp = action_import(req)

        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)
        # Fails if the action is not there
        self.workflow.actions.get(name='SPQ') 
Example #17
Source File: views_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_logout(self):
        """
        Test /pearson/logout URL
        """
        response = self.client.get('/pearson/logout/')
        assert response.status_code == status.HTTP_302_FOUND
        assert response.url == "/dashboard?exam=logout" 
Example #18
Source File: test_views_run.py    From ontask_b with MIT License 5 votes vote down vote up
def test_run_action_item_filter(self):
        """Test the view to filter items."""
        action = self.workflow.actions.get(name='Midterm comments')
        column = action.workflow.columns.get(name='email')
        payload = {
            'item_column': column.pk,
            'action_id': action.id,
            'button_label': 'Send',
            'valuerange': 2,
            'step': 2,
            'prev_url': reverse('action:run', kwargs={'pk': action.id}),
            'post_url': reverse('action:run_done')}
        resp = self.get_response(
            'action:item_filter',
            session_payload=payload)
        self.assertTrue(status.is_success(resp.status_code))

        # POST
        resp = self.get_response(
            'action:item_filter',
            method='POST',
            req_params={
                'exclude_values': ['ctfh9946@bogus.com'],
            },
            session_payload=payload)
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)
        self.assertEqual(resp.url, reverse('action:run_done')) 
Example #19
Source File: test_user_management.py    From desec-stack with MIT License 5 votes vote down vote up
def assertConfirmationLinkRedirect(self, confirmation_link):
        response = self.client.get(confirmation_link)
        self.assertResponse(response, status.HTTP_406_NOT_ACCEPTABLE)
        response = self.client.get(confirmation_link, HTTP_ACCEPT='text/html')
        self.assertResponse(response, status.HTTP_302_FOUND)
        self.assertNoEmailSent() 
Example #20
Source File: test_forms.py    From ontask_b with MIT License 5 votes vote down vote up
def test_csv_upload(self):
        """Test the CSV upload."""
        # Get the regular form
        resp = self.get_response('dataops:csvupload_start')
        self.assertTrue(status.is_success(resp.status_code))

        # POST the data
        filename = os.path.join(settings.ONTASK_FIXTURE_DIR, 'simple.csv')
        with open(filename) as fp:
            resp = self.get_response(
                'dataops:csvupload_start',
                method='POST',
                req_params={
                    'data_file': fp,
                    'skip_lines_at_top': -1,
                    'skip_lines_at_bottom': 0})
            self.assertNotEqual(resp.status_code, status.HTTP_302_FOUND)

            resp = self.get_response(
                'dataops:csvupload_start',
                method='POST',
                req_params={
                    'data_file': fp,
                    'skip_lines_at_top': 0,
                    'skip_lines_at_bottom': -1})
            self.assertNotEqual(resp.status_code, status.HTTP_302_FOUND) 
Example #21
Source File: test_view_row.py    From ontask_b with MIT License 5 votes vote down vote up
def test_row_edit(self):
        """Test the view to filter items."""
        # Row edit (GET)
        resp = self.get_response(
            'dataops:rowupdate',
            req_params={'k': 'key', 'v': '8'})
        self.assertTrue(status.is_success(resp.status_code))
        self.assertTrue('Edit learner data' in str(resp.content))

        # Get the GET URL with the paramegters
        request = self.factory.get(
            reverse('dataops:rowupdate'),
            {'k': 'key', 'v': '8'})

        request = self.factory.post(
            request.get_full_path(),
            {
                '___ontask___upload_0': '8',
                '___ontask___upload_1': 'NEW TEXT 1',
                '___ontask___upload_2': 'NEW TEXT 2',
                '___ontask___upload_3': '111',
                '___ontask___upload_4': '222',
                '___ontask___upload_5': 'on',
                '___ontask___upload_6': '',
                '___ontask___upload_7': '06/07/2019 19:32',
                '___ontask___upload_8': '06/05/2019 19:23'}
        )
        request = self.add_middleware(request)
        resp = views.row_update(request)
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)

        row_val = sql.get_row(
            self.workflow.get_data_frame_table_name(),
            key_name='key',
            key_value=8)

        self.assertEqual(row_val['text1'], 'NEW TEXT 1')
        self.assertEqual(row_val['text2'], 'NEW TEXT 2')
        self.assertEqual(row_val['double1'], 111)
        self.assertEqual(row_val['double2'], 222) 
Example #22
Source File: tests.py    From ontask_b with MIT License 5 votes vote down vote up
def test_home_page_exists(self):
        url = reverse('home')
        r = self.client.get(url)
        self.assertEqual(r.status_code, status.HTTP_302_FOUND) 
Example #23
Source File: test_api.py    From karrot-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_offer_image_redirect(self):
        # NOT logged in (as it needs to work in emails)
        response = self.client.get('/api/offers/{}/image/'.format(self.offer.id))
        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response.url, self.offer.images.first().image.url) 
Example #24
Source File: test_api.py    From karrot-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_group_image_redirect(self):
        # NOT logged in (as it needs to work in emails)
        photo_file = os.path.join(os.path.dirname(__file__), './photo.jpg')
        group = GroupFactory(photo=photo_file, members=[self.member])
        response = self.client.get('/api/groups-info/{}/photo/'.format(group.id))
        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response.url, group.photo.url) 
Example #25
Source File: test_views_run.py    From ontask_b with MIT License 4 votes vote down vote up
def test_json_action_with_filter(self):
        """Test JSON action without using the filter execution."""
        OnTaskSharedState.json_outbox = None
        action = self.workflow.actions.get(name='Send JSON to remote server')
        column = action.workflow.columns.get(name='email')
        exclude_values = ['pzaz8370@bogus.com', 'tdrv2640@bogus.com']

        # Step 1 invoke the form
        resp = self.get_response(
            'action:run',
            url_params={'pk': action.id})
        payload = SessionPayload.get_session_payload(self.last_request)
        self.assertTrue(action.id == payload['action_id'])
        self.assertTrue(
            payload['prev_url'] == reverse(
                'action:run',
                kwargs={'pk': action.id}))
        self.assertTrue(payload['post_url'] == reverse('action:run_done'))
        self.assertTrue('post_url' in payload.keys())
        self.assertTrue(status.is_success(resp.status_code))

        # Step 2 send POST
        resp = self.get_response(
            'action:run',
            url_params={'pk': action.id},
            method='POST',
            req_params={
                'item_column': column.pk,
                'confirm_items': True,
                'token': 'fake token'})
        payload = SessionPayload.get_session_payload(self.last_request)
        self.assertTrue(payload['confirm_items'])
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)

        # Load the Filter page with a GET
        resp = self.get_response(
            'action:item_filter',
            session_payload=payload)
        self.assertTrue(status.is_success(resp.status_code))

        # Emulate the filter page with a POST
        resp = self.get_response(
            'action:item_filter',
            method='POST',
            req_params={'exclude_values': exclude_values})
        payload = SessionPayload.get_session_payload(self.last_request)
        self.assertTrue(payload['exclude_values'] == exclude_values)
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)
        self.assertEqual(resp.url, payload['post_url'])

        # Emulate the redirection to run_done
        resp = self.get_response('action:run_done')
        payload = SessionPayload.get_session_payload(self.last_request)
        self.assertTrue(payload == {})
        self.assertTrue(
            len(OnTaskSharedState.json_outbox) == (
                action.get_rows_selected() - len(exclude_values)))
        self.assertTrue(status.is_success(resp.status_code)) 
Example #26
Source File: test_view_row.py    From ontask_b with MIT License 4 votes vote down vote up
def test_row_create(self):
        """Test the view to filter items."""
        nrows = self.workflow.nrows

        # Row create (GET)
        resp = self.get_response('dataops:rowcreate')
        self.assertTrue(status.is_success(resp.status_code))

        # Row create POST
        resp = self.get_response(
            'dataops:rowcreate',
            method='POST',
            req_params={
                '___ontask___upload_0': '8',
                '___ontask___upload_1': 'text1',
                '___ontask___upload_2': 'text2',
                '___ontask___upload_3': '12.1',
                '___ontask___upload_4': '12.2',
                '___ontask___upload_5': 'on',
                '___ontask___upload_6': '',
                '___ontask___upload_7': '06/07/2019 19:32',
                '___ontask___upload_8': '06/05/2019 19:23'})
        self.assertTrue(status.is_success(resp.status_code))

        # Update the workflow
        self.workflow.refresh_from_db()
        self.assertEqual(nrows, self.workflow.nrows)

        # Row create POST
        resp = self.get_response(
            'dataops:rowcreate',
            method='POST',
            req_params={
                '___ontask___upload_0': '9',
                '___ontask___upload_1': 'text add 1',
                '___ontask___upload_2': 'text add 2',
                '___ontask___upload_3': '22',
                '___ontask___upload_4': '23',
                '___ontask___upload_5': 'on',
                '___ontask___upload_7': '06/07/2019 19:32',
                '___ontask___upload_8': '06/05/2019 19:23'})
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)

        # Update the workflow
        self.workflow.refresh_from_db()
        self.assertEqual(nrows + 1, self.workflow.nrows)

        row_val = sql.get_row(
            self.workflow.get_data_frame_table_name(),
            key_name='key',
            key_value=9)
        self.assertEqual(row_val['text1'], 'text add 1')
        self.assertEqual(row_val['text2'], 'text add 2')
        self.assertEqual(row_val['double1'], 22)
        self.assertEqual(row_val['double2'], 23)