Python rest_framework.status.HTTP_404_NOT_FOUND Examples
The following are 30
code examples of rest_framework.status.HTTP_404_NOT_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: views.py From django-puppy-store with MIT License | 7 votes |
def get_delete_update_puppy(request, pk): try: puppy = Puppy.objects.get(pk=pk) except Puppy.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) # get details of a single puppy if request.method == 'GET': serializer = PuppySerializer(puppy) return Response(serializer.data) # update details of a single puppy if request.method == 'PUT': serializer = PuppySerializer(puppy, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_204_NO_CONTENT) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) # delete a single puppy if request.method == 'DELETE': puppy.delete() return Response(status=status.HTTP_204_NO_CONTENT)
Example #2
Source File: __init__.py From wanggeService with MIT License | 6 votes |
def stockcode_detail(request, pk, format=None): """ Retrieve, update or delete a snippet instance. """ try: values = SC.objects.get(pk=pk) except SC.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = ListingSerializer(values) return Response(serializer.data) elif request.method == 'PUT': serializer = ListingSerializer(values, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) elif request.method == 'DELETE': values.delete() return Response(status=status.HTTP_204_NO_CONTENT)
Example #3
Source File: tests.py From REST-API with MIT License | 6 votes |
def test_status_delete(self): data = self.create_item() data_id = data.get("id") rud_url = api_reverse('api-status:detail', kwargs={"id": data_id}) rud_data = { 'content': "another new content" } ''' delete method / delete ''' del_response = self.client.delete(rud_url, format='json') self.assertEqual(del_response.status_code, status.HTTP_204_NO_CONTENT) ''' Not found ''' get_response = self.client.get(rud_url, format='json') self.assertEqual(get_response.status_code, status.HTTP_404_NOT_FOUND)
Example #4
Source File: test_views.py From safe-relay-service with MIT License | 6 votes |
def test_erc20_view(self): safe_address = Account().create().address SafeContractFactory(address=safe_address) response = self.client.get(reverse('v1:erc20-txs', args=(safe_address,))) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) ethereum_erc20_event = EthereumEventFactory(to=safe_address) response = self.client.get(reverse('v1:erc20-txs', args=(safe_address,))) self.assertEqual(response.status_code, status.HTTP_200_OK) response_ethereum_erc20_event = response.json()['results'][0] self.assertEqual(ethereum_erc20_event.token_address, response_ethereum_erc20_event['tokenAddress']) self.assertEqual(ethereum_erc20_event.arguments['to'], response_ethereum_erc20_event['to']) self.assertEqual(ethereum_erc20_event.arguments['from'], response_ethereum_erc20_event['from']) self.assertEqual(ethereum_erc20_event.arguments['value'], int(response_ethereum_erc20_event['value'])) self.assertEqual(ethereum_erc20_event.ethereum_tx.to, response_ethereum_erc20_event['ethereumTx']['to']) EthereumEventFactory(from_=safe_address) EthereumEventFactory() response = self.client.get(reverse('v1:erc20-txs', args=(safe_address,))) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()['count'], 2)
Example #5
Source File: test_views.py From safe-relay-service with MIT License | 6 votes |
def test_safe_balances(self): safe_address = Account.create().address response = self.client.get(reverse('v1:safe-balances', args=(safe_address, ))) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) SafeContractFactory(address=safe_address) value = 7 self.send_ether(safe_address, 7) response = self.client.get(reverse('v1:safe-balances', args=(safe_address, ))) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.json()), 1) self.assertIsNone(response.json()[0]['tokenAddress']) self.assertEqual(response.json()[0]['balance'], str(value)) tokens_value = 12 erc20 = self.deploy_example_erc20(tokens_value, safe_address) response = self.client.get(reverse('v1:safe-balances', args=(safe_address,))) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.json()), 1) EthereumEventFactory(token_address=erc20.address, to=safe_address) response = self.client.get(reverse('v1:safe-balances', args=(safe_address,))) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.json(), [{'tokenAddress': None, 'balance': str(value)}, {'tokenAddress': erc20.address, 'balance': str(tokens_value)}])
Example #6
Source File: test_long_refresh_token_views.py From django-rest-framework-jwt-refresh-token with MIT License | 6 votes |
def test_delete_refresth_token(self): self.client.credentials( HTTP_AUTHORIZATION='JWT ' + utils.jwt_encode_handler( utils.jwt_payload_handler(self.user))) response = self.client.delete(self.detail_url) self.assertEqual( response.status_code, status.HTTP_204_NO_CONTENT, (response.status_code, response.content) ) response = self.client.delete(self.detail_url1) self.assertEqual( response.status_code, status.HTTP_404_NOT_FOUND, (response.status_code, response.content) )
Example #7
Source File: test_long_refresh_token_views.py From django-rest-framework-jwt-refresh-token with MIT License | 6 votes |
def test_revoke_refresh_token(self): self.client.credentials( HTTP_AUTHORIZATION='JWT ' + utils.jwt_encode_handler( utils.jwt_payload_handler(self.user))) response = self.client.post(self.revoke_url) self.assertEqual( response.status_code, status.HTTP_201_CREATED, (response.status_code, response.content) ) new_rt = self.user.refresh_tokens.get() self.assertEqual( response.data, {'key': new_rt.key, 'app': new_rt.app, 'user': self.user.pk, 'created': new_rt.created.isoformat()[:-6] + 'Z', }) response = self.client.post(self.revoke_url) self.assertEqual( response.status_code, status.HTTP_404_NOT_FOUND, (response.status_code, response.content) )
Example #8
Source File: views.py From django-rest-passwordreset with BSD 3-Clause "New" or "Revised" License | 6 votes |
def post(self, request, *args, **kwargs): serializer = self.serializer_class(data=request.data) serializer.is_valid(raise_exception=True) token = serializer.validated_data['token'] # get token validation time password_reset_token_validation_time = get_password_reset_token_expiry_time() # find token reset_password_token = ResetPasswordToken.objects.filter(key=token).first() if reset_password_token is None: return Response({'status': 'notfound'}, status=status.HTTP_404_NOT_FOUND) # check expiry date expiry_date = reset_password_token.created_at + timedelta(hours=password_reset_token_validation_time) if timezone.now() > expiry_date: # delete expired token reset_password_token.delete() return Response({'status': 'expired'}, status=status.HTTP_404_NOT_FOUND) return Response({'status': 'OK'})
Example #9
Source File: views.py From safe-relay-service with MIT License | 6 votes |
def get(self, request, address, format=None): """ Get status of the safe """ if not Web3.isChecksumAddress(address): return Response(status=status.HTTP_422_UNPROCESSABLE_ENTITY) else: try: SafeContract.objects.get(address=address) except SafeContract.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) safe_balances = StatsServiceProvider().get_balances(address) serializer = self.serializer_class(data=safe_balances, many=True) # assert serializer.is_valid(), 'Safe Balance result not valid' serializer.is_valid() return Response(status=status.HTTP_200_OK, data=serializer.data)
Example #10
Source File: viewsets.py From django-celery-inspect with MIT License | 6 votes |
def active_status(self, request): """ This will only work if you have django-celery installed (for now). In case you only need to work with status codes to find out if the workers are up or not. This will only work if we assume our db only contains "active workers". To use this feature, you must ensure you use only named workers, For example: "-n worker1@localhost:8000". http://docs.celeryproject.org/en/latest/userguide/workers.html#starting-the-worker """ app_installed = "djcelery" in settings.INSTALLED_APPS if not app_installed: return Response(status=status.HTTP_501_NOT_IMPLEMENTED) from djcelery.models import WorkerState count_workers = WorkerState.objects.all().count() result = self.inspect.active() if result is not None and count_workers == len(result): return Response(status=status.HTTP_200_OK) return Response(status=status.HTTP_404_NOT_FOUND)
Example #11
Source File: __init__.py From wanggeService with MIT License | 6 votes |
def BK_detail(request, pk, format=None): """ Retrieve, update or delete a snippet instance. """ try: values = BlockDetail.objects.get(pk=pk) except BlockDetail.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = BKDetailSerializer(values) return Response(serializer.data) elif request.method == 'PUT': serializer = BKDetailSerializer(values, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) elif request.method == 'DELETE': values.delete() return Response(status=status.HTTP_204_NO_CONTENT) # from .hsgtcgholdview import HSGTCG
Example #12
Source File: __init__.py From wanggeService with MIT License | 6 votes |
def ZXG_detail(request, pk, format=None): """ Retrieve, update or delete a snippet instance. """ try: values = BlockDetail.objects.get(pk=pk) except BlockDetail.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = BKDetailSerializer(values) return Response(serializer.data) elif request.method == 'PUT': serializer = BKDetailSerializer(values, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) elif request.method == 'DELETE': values.delete() return Response(status=status.HTTP_204_NO_CONTENT)
Example #13
Source File: __init__.py From wanggeService with MIT License | 6 votes |
def stockcode_detail(request, pk, format=None): """ Retrieve, update or delete a snippet instance. """ try: values = SC.objects.get(pk=pk) except SC.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = ListingSerializer(values) return Response(serializer.data) elif request.method == 'PUT': serializer = ListingSerializer(values, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) elif request.method == 'DELETE': values.delete() return Response(status=status.HTTP_204_NO_CONTENT)
Example #14
Source File: FieldsightFcmViewset.py From kobo-predict with BSD 2-Clause "Simplified" License | 6 votes |
def perform_create(self, serializer): try: device = Device.objects.get(dev_id=serializer.data["dev_id"]) except Device.DoesNotExist: device = Device(dev_id=serializer.data["dev_id"]) device.is_active = True device.reg_id = serializer.data["reg_id"] user = User.objects.filter(email__iexact=serializer.data["name"]) if user: device.name = user[0].email else: user = User.objects.filter(username__iexact=serializer.data["name"]) if user: device.name = user[0].email else: return response.Response(status=status.HTTP_404_NOT_FOUND) device.save()
Example #15
Source File: test_views.py From safe-relay-service with MIT License | 6 votes |
def test_token_view(self): random_address = Account.create().address response = self.client.get(reverse('v1:token', args=(random_address,))) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data, {'detail': ErrorDetail(string='Not found.', code='not_found')}) token = TokenFactory(address=random_address) response = self.client.get(reverse('v1:token', args=(random_address,))) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data, {'address': token.address, 'logo_uri': token.get_full_logo_uri(), 'default': token.gas, 'name': token.name, 'symbol': token.symbol, 'description': token.description, 'decimals': token.decimals, 'website_uri': token.website_uri, 'gas': token.gas})
Example #16
Source File: test_views.py From safe-relay-service with MIT License | 6 votes |
def test_erc721_view(self): safe_address = Account().create().address SafeContractFactory(address=safe_address) response = self.client.get(reverse('v1:erc721-txs', args=(safe_address,))) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) ethereum_erc721_event = EthereumEventFactory(to=safe_address, erc721=True) response = self.client.get(reverse('v1:erc721-txs', args=(safe_address,))) self.assertEqual(response.status_code, status.HTTP_200_OK) response_ethereum_erc721_event = response.json()['results'][0] self.assertEqual(ethereum_erc721_event.token_address, response_ethereum_erc721_event['tokenAddress']) self.assertEqual(ethereum_erc721_event.arguments['to'], response_ethereum_erc721_event['to']) self.assertEqual(ethereum_erc721_event.arguments['from'], response_ethereum_erc721_event['from']) self.assertEqual(ethereum_erc721_event.arguments['tokenId'], int(response_ethereum_erc721_event['tokenId'])) self.assertEqual(ethereum_erc721_event.ethereum_tx.to, response_ethereum_erc721_event['ethereumTx']['to']) EthereumEventFactory(from_=safe_address, erc721=True) EthereumEventFactory(erc721=True) response = self.client.get(reverse('v1:erc721-txs', args=(safe_address,))) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()['count'], 2)
Example #17
Source File: test_api.py From django-channels-chat with MIT License | 6 votes |
def test_read_message(self): self.login_user1() url = reverse('message-api-list') message = {'recipient': 'u2', 'body': 'hello'} response = self.client.post(url, message, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.logout() # Change user self.login_user2() url = reverse('message-api-detail', kwargs={'pk': 1}) response = self.client.get(url, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['body'], 'hello') self.logout() # Change to another user (not in conversation) self.login_user3() response = self.client.get(url, format='json') self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.logout()
Example #18
Source File: test_long_refresh_token_views.py From django-rest-framework-jwt-refresh-token with MIT License | 6 votes |
def test_get_refresth_token_detail(self): self.client.credentials( HTTP_AUTHORIZATION='JWT ' + utils.jwt_encode_handler( utils.jwt_payload_handler(self.user))) response = self.client.get(self.detail_url) self.assertEqual( response.status_code, status.HTTP_200_OK, (response.status_code, response.content) ) response = self.client.get(self.detail_url1) self.assertEqual( response.status_code, status.HTTP_404_NOT_FOUND, (response.status_code, response.content) )
Example #19
Source File: data_viewset.py From kobo-predict with BSD 2-Clause "Simplified" License | 5 votes |
def labels(self, request, *args, **kwargs): http_status = status.HTTP_400_BAD_REQUEST instance = self.get_object() if request.method == 'POST': if add_tags_to_instance(request, instance): http_status = status.HTTP_201_CREATED tags = instance.tags label = kwargs.get('label', None) if request.method == 'GET' and label: data = [tag['name'] for tag in tags.filter(name=label).values('name')] elif request.method == 'DELETE' and label: count = tags.count() tags.remove(label) # Accepted, label does not exist hence nothing removed http_status = status.HTTP_200_OK if count == tags.count() \ else status.HTTP_404_NOT_FOUND data = list(tags.names()) else: data = list(tags.names()) if request.method == 'GET': http_status = status.HTTP_200_OK return Response(data, status=http_status)
Example #20
Source File: views.py From safe-relay-service with MIT License | 5 votes |
def get(self, request, address): if not Web3.isChecksumAddress(address): return Response(status=status.HTTP_422_UNPROCESSABLE_ENTITY) else: try: SafeContract.objects.get(address=address) except SafeContract.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) response = super().get(request, address) if response.data['count'] == 0: response.status_code = status.HTTP_404_NOT_FOUND return response
Example #21
Source File: test_api.py From karrot-backend with GNU Affero General Public License v3.0 | 5 votes |
def test_group_image_redirect_no_photo(self): # NOT logged in (as it needs to work in emails) group = GroupFactory(members=[self.member]) response = self.client.get('/api/groups-info/{}/photo/'.format(group.id)) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Example #22
Source File: test_api.py From karrot-backend with GNU Affero General Public License v3.0 | 5 votes |
def test_retrieve_group_as_nonmember(self): self.client.force_login(user=self.user) url = self.url + str(self.group.id) + '/' response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Example #23
Source File: test_api.py From karrot-backend with GNU Affero General Public License v3.0 | 5 votes |
def test_patch_group_as_user(self): self.client.force_login(user=self.user) url = self.url + str(self.group.id) + '/' response = self.client.patch(url, self.group_data, format='json') self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Example #24
Source File: tests_view.py From koku with GNU Affero General Public License v3.0 | 5 votes |
def test_delete_cost_model_success(self): """Test that we can delete an existing rate.""" cost_model = CostModel.objects.first() url = reverse("cost-models-detail", kwargs={"uuid": cost_model.uuid}) client = APIClient() with patch("masu.processor.tasks.update_cost_model_costs.delay"): response = client.delete(url, **self.headers) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) # verify the cost model no longer exists response = client.get(url, **self.headers) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Example #25
Source File: views.py From safe-relay-service with MIT License | 5 votes |
def get(self, request, address, format=None): """ Get status of the safe creation """ if not Web3.isChecksumAddress(address): return Response(status=status.HTTP_422_UNPROCESSABLE_ENTITY) else: try: safe_funding = SafeFunding.objects.get(safe=address) serializer = SafeFundingResponseSerializer(safe_funding) return Response(status=status.HTTP_200_OK, data=serializer.data) except SafeFunding.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND)
Example #26
Source File: views_v2.py From safe-relay-service with MIT License | 5 votes |
def put(self, request, address, format=None): """ Force check of a safe balance to start the safe creation """ if not Web3.isChecksumAddress(address): return Response(status=status.HTTP_422_UNPROCESSABLE_ENTITY) else: try: SafeCreation2.objects.get(safe=address) except SafeCreation2.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) deploy_create2_safe_task.delay(address) return Response(status=status.HTTP_202_ACCEPTED)
Example #27
Source File: views_v2.py From safe-relay-service with MIT License | 5 votes |
def get(self, request, address, format=None): """ Get status of the safe creation """ if not Web3.isChecksumAddress(address): return Response(status=status.HTTP_422_UNPROCESSABLE_ENTITY) else: try: safe_creation2 = SafeCreation2.objects.get(safe=address) serializer = self.serializer_class(safe_creation2) return Response(status=status.HTTP_200_OK, data=serializer.data) except SafeCreation2.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND)
Example #28
Source File: source_status.py From koku with GNU Affero General Public License v3.0 | 5 votes |
def source_status(request): """ Source availability status endpoint for Platform Sources to get cost management source status. Parameter: source_id corresponds to the table api_sources Returns: status (Dict): {'availability_status': 'unavailable/available', 'availability_status_error': ValidationError-detail} """ source_id = _get_source_id_from_request(request) if source_id is None: return Response(data="Missing query parameter source_id", status=status.HTTP_400_BAD_REQUEST) try: int(source_id) except ValueError: # source_id must be an integer return Response(data="source_id must be an integer", status=status.HTTP_400_BAD_REQUEST) try: source_status_obj = SourceStatus(request, source_id) except ObjectDoesNotExist: # Source isn't in our database, return 404. return Response(status=status.HTTP_404_NOT_FOUND) return _deliver_status(request, source_status_obj)
Example #29
Source File: tests_view.py From koku with GNU Affero General Public License v3.0 | 5 votes |
def test_delete_cost_model_invalid(self): """Test that deleting an invalid cost model returns an error.""" url = reverse("cost-models-detail", kwargs={"uuid": uuid4()}) client = APIClient() with patch("masu.processor.tasks.update_cost_model_costs.delay"): response = client.delete(url, **self.headers) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Example #30
Source File: tests_rbac.py From koku with GNU Affero General Public License v3.0 | 5 votes |
def mocked_requests_get_404_json(*args, **kwargs): """Mock invalid response that returns json.""" json_response = {"details": "Invalid path."} return MockResponse(json_response, status.HTTP_404_NOT_FOUND)