Skip to content

Commit

Permalink
indexes | fixing tests/pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Aug 6, 2021
1 parent e332bdf commit e18b8e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 0 additions & 3 deletions core/indexes/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,8 @@ def test_post_400(self):

def test_post_202(self):
concept = ConceptFactory()
old_updated_at = concept.updated_at
url = '/indexes/resources/concepts/'

response = self.client.post(url, dict(ids='{}'.format(concept.mnemonic)), HTTP_AUTHORIZATION=self.token_header)

self.assertEqual(response.status_code, 202)
concept.refresh_from_db()
self.assertNotEqual(old_updated_at, concept.updated_at)
15 changes: 11 additions & 4 deletions core/indexes/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf import settings
from drf_yasg.utils import swagger_auto_schema
from pydash import compact
from pydash import compact, get
from rest_framework import status
from rest_framework.parsers import MultiPartParser
from rest_framework.permissions import IsAdminUser
Expand Down Expand Up @@ -51,14 +52,20 @@ def post(self, _, resource):
ids = self.request.data.get('ids', None)
uri = self.request.data.get('uri', None)

filters = None

if ids:
ids = compact([i.strip() for i in compact(ids.split(','))])
filters = {"{}__in".format(model.mnemonic_attr): ids}
if ids:
filters = {"{}__in".format(model.mnemonic_attr): ids}
elif uri:
filters = dict(uri__icontains=uri)
else:
if not filters:
return Response(status=status.HTTP_400_BAD_REQUEST)

batch_index_resources.delay(resource, filters)
if get(settings, 'TEST_MODE', False):
batch_index_resources(resource, filters)
else:
batch_index_resources.delay(resource, filters)

return Response(status=status.HTTP_202_ACCEPTED)

0 comments on commit e18b8e1

Please sign in to comment.