-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
597ce55
commit 0af1845
Showing
3 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import unittest | ||
|
||
from django.core.files.uploadedfile import SimpleUploadedFile | ||
from django.core.management import call_command | ||
from django.test import RequestFactory | ||
|
||
from general import filters | ||
from general.models import DocumentFile, Institution, Language, Subject | ||
|
||
|
||
class TestDocumentFileFilter(unittest.TestCase): | ||
def setUp(self): | ||
# call_command("flush", "--noinput") | ||
|
||
pass | ||
|
||
# self.subject = Subject.objects.create(name="Test Subject") | ||
# self.language = Language.objects.create(name="Test Language", iso_code="TL") | ||
# self.institution = Institution.objects.create(name="Test Institution") | ||
# | ||
# self.title = "Some document" | ||
# self.url = "https://example.com" | ||
# self.uploaded_file = SimpleUploadedFile( | ||
# "example.pdf", b"file_content", content_type="application/pdf" | ||
# ) | ||
# self.license = "MIT" | ||
# self.mime_type = "pdf" | ||
# self.document_type = "Glossary" | ||
# self.institution = self.institution | ||
# | ||
# self.document = DocumentFile.objects.create( | ||
# title=self.title, | ||
# url=self.url, | ||
# uploaded_file=self.uploaded_file, | ||
# license=self.license, | ||
# mime_type=self.mime_type, | ||
# document_type=self.document_type, | ||
# institution=self.institution, | ||
# ) | ||
# | ||
# # pprint(self.document) | ||
# # self.factory = RequestFactory() | ||
# self.doc_filter = filters.DocumentFileFilter() | ||
# | ||
# def test_filter_search_empty_query(self): | ||
# value = "" | ||
# result = self.doc_filter.filter_search(self.document, value) | ||
# | ||
# print(result) | ||
# self.assertEqual(result, self.document) | ||
|
||
# def test_filter_search_no_result(self): | ||
# queryset = [] | ||
# name = '' | ||
# value = 'some search term' | ||
# result = self.doc_filter.filter_search(queryset, value) | ||
# self.assertEqual(result, []) | ||
# | ||
# def test_filter_search_with_result(self): | ||
# queryset = [{'title': 'Test Document', 'description': 'This is a test document', 'document_data': 'Test data'}] | ||
# name = 'title' | ||
# value = 'Test Document' | ||
# result = self.doc_filter.filter_search(queryset, name, value) | ||
# self.assertEqual(result, queryset) | ||
# | ||
# def test_filter_search_order_rank(self): | ||
# queryset = [ | ||
# {'title': 'Test Document 1', 'description': 'This is a test document 1', 'document_data': 'Test data 1'}, | ||
# {'title': 'Test Document 2', 'description': 'This is a test document 2', 'document_data': 'Test data 2'}, | ||
# {'title': 'Test Document 3', 'description': 'This is a test document 3', 'document_data': 'Test data 3'} | ||
# ] | ||
# name = 'title' | ||
# value = 'Test Document' | ||
# result = self.doc_filter.filter_search(queryset, name, value) | ||
# self.assertGreater(result[0]['rank'], result[1]['rank']) | ||
|
||
# def tearDown(self): | ||
# if self.document.uploaded_file: | ||
# self.document.uploaded_file.delete() | ||
|
||
|
||
# if __name__ == "__main__": | ||
# unittest.main() |