Last active
June 18, 2019 16:10
-
-
Save glassresistor/50185e536a7eefca4cc2c488cef822e6 to your computer and use it in GitHub Desktop.
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
==================================================================================================== FAILURES ===================================================================================================== | |
_________________________________________________________________________________________ test_custom_view_with_ordering __________________________________________________________________________________________ | |
token = <Token: 5502f6196a82da5016b0c5b58ee83cd02968c6d9> | |
examplefortesting = [<ExampleForTesting: ExampleForTesting object (150)>, <ExampleForTesting: ExampleForTesting object (151)>, <ExampleFor...bject (152)>, <ExampleForTesting: ExampleForTesting object (153)>, <ExampleForTesting: ExampleForTesting object (154)>] | |
@pytest.mark.django_db | |
def test_custom_view_with_ordering(token, examplefortesting): | |
"""Test ordering query returns csv with specified order""" | |
kwargs = {'app_label': 'bulk_importer', | |
'model_name': 'examplefortesting', } | |
data = {'ordering': 'text', } | |
url = reverse_lazy('api-dataframe', kwargs=kwargs) | |
factory = APIRequestFactory() | |
request = factory.get(url, data) | |
force_authenticate(request, user=token.user, token=token) | |
response = views.CustomPandasView.as_view()( | |
request, app_label='bulk_importer', model_name='examplefortesting') | |
response.render() | |
csv_file = csv.reader(io.StringIO( | |
response.content.decode('utf-8')), delimiter=',') | |
rows = [] | |
for row in csv_file: | |
rows.append(row) | |
assert response.status_code == 200 | |
sorted_texts = sorted([x.text for x in examplefortesting]) | |
text_index = rows[0].index('text') | |
texts = [x[text_index] for x in rows[1:]] | |
> assert texts == sorted_texts | |
E AssertionError: assert ['BMeXuGDkjJv...kpQQpclLCswp'] == ['BMeXuGDkjJvc...ZmeercQMCHEO'] | |
E At index 2 diff: 'hlJHDsnEWVJTFhSJcZmeercQMCHEO' != 'KSbYMNHYojauyObleoCEkrcIQVCEj' | |
E Full diff: | |
E ['BMeXuGDkjJvckBDERoLJPrGdYJVgE', | |
E 'FuEltDZHtWbDjTenwJJpYIuwGyWjs', | |
E - 'hlJHDsnEWVJTFhSJcZmeercQMCHEO', | |
E 'KSbYMNHYojauyObleoCEkrcIQVCEj', | |
E - 'SMNEfMtqMFqjtFBhskpQQpclLCswp'] | |
E ? ^ | |
E + 'SMNEfMtqMFqjtFBhskpQQpclLCswp', | |
E ? ^ | |
E + 'hlJHDsnEWVJTFhSJcZmeercQMCHEO'] | |
bulk_importer/tests/views_tests.py:275: AssertionError |
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
import pytest | |
from data_warehouse.conftest import * # noqa | |
from bulk_importer.tests import factories | |
@pytest.fixture | |
def bulk_import(django_db_blocker): | |
return factories.BulkImportFactory() | |
@pytest.fixture | |
def token(django_db_blocker): | |
return factories.TokenFactory() | |
@pytest.fixture | |
def examplefortesting(django_db_blocker): | |
return factories.ExampleForTestingFactory.create_batch(5) | |
@pytest.mark.django_db | |
def test_custom_view_with_ordering(token, examplefortesting): | |
"""Test ordering query returns csv with specified order""" | |
kwargs = {'app_label': 'bulk_importer', | |
'model_name': 'examplefortesting', } | |
data = {'ordering': 'text', } | |
url = reverse_lazy('api-dataframe', kwargs=kwargs) | |
factory = APIRequestFactory() | |
request = factory.get(url, data) | |
force_authenticate(request, user=token.user, token=token) | |
response = views.CustomPandasView.as_view()( | |
request, app_label='bulk_importer', model_name='examplefortesting') | |
response.render() | |
csv_file = csv.reader(io.StringIO( | |
response.content.decode('utf-8')), delimiter=',') | |
rows = [] | |
for row in csv_file: | |
rows.append(row) | |
assert response.status_code == 200 | |
sorted_texts = sorted([x.text for x in examplefortesting]) | |
text_index = rows[0].index('text') | |
texts = [x[text_index] for x in rows[1:]] | |
assert texts == sorted_texts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment