def post(request): serializer = BackupSerializer(data=request.data, context={'request': request}) if serializer.is_valid(): serializer.save() account = Account.get_by_pk(request.user.username) backups = Backup.objects.all().order_by('timestamp') if len(backups) > account.max_backups: Backup.remove(backups[0].digest) return Response({'detail': 'backup has been created'}, status=status.HTTP_201_CREATED) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(request, pk_hash): if pk_hash is None: return Response({'details': 'primary key is not provided'}, status=status.HTTP_400_BAD_REQUEST) backup = Backup.remove(pk_hash) if backup is None: return Response(status=status.HTTP_404_NOT_FOUND) return Response( {'detail': 'backup {} has been deleted'.format(backup.digest)}, status=status.HTTP_201_CREATED)
def test_remove_does_not_exist(self): backup = Backup.remove('super_hash1') self.assertIsNone(backup)
def test_remove_exists(self): backup = Backup.remove('super_hash') self.assertIsNotNone(backup)