Skip to content

Commit

Permalink
update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
daveminer committed Jul 28, 2024
1 parent dcdbf65 commit cab6ac1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sentiment/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_run_sentiment(mocker):
mock_finbert().__getitem__().detach().numpy.return_value = fake_finbert_return

mock_results = run_sentiment.s(
["Stonks go up.", "For great justice."]
["Stonks go up.", "For great justice."], ["test-tag", "another-tag"]
).apply().get()

assert mock_results == json.dumps({'ids': [1, 2]})
Expand Down
17 changes: 12 additions & 5 deletions sentiment/views/listview.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@

class SentimentList(ListView):
model = Sentiment

queryset: QuerySet[Sentiment] = Sentiment.objects.all().order_by('-created_at')[:100]

template_name: str = '../templates/list.html'
paginate_by: int = 10 # Number of items per page

def get_queryset(self) -> QuerySet[Sentiment]:
queryset = Sentiment.objects.all().order_by('-created_at')
tag = self.request.GET.get('tag')
if tag:
queryset = queryset.filter(tags__icontains=tag)
return queryset

def get(self, request, *args, **kwargs) -> HttpResponse | JsonResponse:
if 'application/json' in request.META.get('HTTP_ACCEPT'):
self.object_list = self.get_queryset()
context = self.get_context_data()
return JsonResponse(list(
self.get_queryset().values('created_at', 'label', 'score', 'tags', 'text')
context['object_list'].values('created_at', 'label', 'score', 'tags', 'text')
), safe=False)

return super().get(request, *args, **kwargs)
return super().get(request, *args, **kwargs)

0 comments on commit cab6ac1

Please sign in to comment.