Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BeritJanssen committed Oct 26, 2023
1 parent 1369c43 commit da17816
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
11 changes: 2 additions & 9 deletions backend/download/create_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,13 @@ def format_field_value(value, unit):
}
return date.strftime(formats[unit])

def ngram_csv(results, parameters):
def ngram_csv(results, log_id):
rows = ngram_table(results)
fieldnames = ['date', 'N-gram', 'Frequency']
filename = ngram_filename(parameters)
filename = create_filename(log_id)
filepath = write_file(filename, fieldnames, rows)
return filepath

def ngram_filename(parameters):
query_string = get_query_text(parameters['es_query'])
timestamp = datetime.now().isoformat(sep='_', timespec='minutes') # ensure csv filenames are unique with timestamp
suffix = '_' + timestamp + '.csv'
description = 'ngram_{}_{}'.format(query_string, suffix)
return create_filename(description, suffix)

def ngram_table(results):
rows = []
for index, time_point in enumerate(results['time_points']):
Expand Down
6 changes: 3 additions & 3 deletions backend/download/tests/test_download_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from download import SEARCH_RESULTS_DIALECT
from addcorpus.models import Corpus
import io
from visualization.query import MATCH_ALL
from visualization import query
from es.search import hits
from tag.models import Tag, TaggedDocument

Expand Down Expand Up @@ -172,7 +172,7 @@ def test_csv_download_view(admin_client, finished_download):
def some_document_id(admin_client, small_mock_corpus, index_small_mock_corpus):
search_response = admin_client.post(
f'/api/es/{small_mock_corpus}/_search',
{'es_query': MATCH_ALL},
{'es_query': query.MATCH_ALL},
content_type='application/json'
)

Expand Down Expand Up @@ -200,7 +200,7 @@ def test_download_with_tag(db, admin_client, small_mock_corpus, index_small_mock
encoding = 'utf-8'
download_request_json = {
'corpus': small_mock_corpus,
'es_query': MATCH_ALL,
'es_query': query.MATCH_ALL,
'tags': [tag_on_some_document.id],
'fields': ['date','content'],
'size': 3,
Expand Down

0 comments on commit da17816

Please sign in to comment.