Passed
Branch v2 (18c5d8)
by Michel
02:43
created

tests.test_listing.test_list_fixed_length()   A

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
import pytest
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
introduced by
Unable to import 'pytest'
Loading history...
2
3
from datatables import ColumnDT, DataTables
4
5
from .helpers import create_dt_params
6
from .models import Address, User
7
8
9 View Code Duplication
def test_list(session):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
10
    """Test if it returns a list of users."""
11
    columns = [ColumnDT(User.id)]
12
13
    query = session.query().select_from(User)
14
15
    params = create_dt_params(columns)
16
    rowTable = DataTables(params, query, columns)
0 ignored issues
show
Coding Style Naming introduced by
The name rowTable does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
17
    res = rowTable.output_result()
18
19
    assert len(res['data']) == 10
20
    assert len(res['data'][0]) == 1
21
    assert res['recordsTotal'] == '50'
22
    assert res['recordsFiltered'] == '50'
23
24
25
def test_list_bad_length(session):
26
    """Test if it returns an error for querying with a bad length."""
27
    columns = [ColumnDT(User.id)]
28
29
    query = session.query()
30
31
    params = create_dt_params(columns, length=-10)
32
    rowTable = DataTables(params, query, columns)
0 ignored issues
show
Coding Style Naming introduced by
The name rowTable does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
33
    res = rowTable.output_result()
34
35
    assert 'Length should be' in res['error']
36
37
38
def test_list_detail(session):
39
    """Test if it returns a list of detailed users."""
40
    columns = [
41
        ColumnDT(User.id),
42
        ColumnDT(User.name),
43
        ColumnDT(Address.description),
44
        ColumnDT(User.created_at)
45
    ]
46
47
    query = session.query()
48
49
    params = create_dt_params(columns)
50
    rowTable = DataTables(params, query, columns)
0 ignored issues
show
Coding Style Naming introduced by
The name rowTable does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
51
    res = rowTable.output_result()
52
53
    assert len(res['data'][0]) == 4
54
55
56
def test_list_fixed_length(session):
57
    """Test if it returns a fixed list of users."""
58
    columns = [ColumnDT(User.id)]
59
60
    query = session.query()
61
62
    params = create_dt_params(columns, length=7)
63
    rowTable = DataTables(params, query, columns)
0 ignored issues
show
Coding Style Naming introduced by
The name rowTable does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
64
    res = rowTable.output_result()
65
66
    assert len(res['data']) == 7
67
68
69
def test_list_inner_join(session):
70
    """Test if it returns a list of users with address."""
71
    columns = [ColumnDT(User.id)]
72
73
    query = session.query().select_from(User).join(Address)
74
75
    params = create_dt_params(columns)
76
    rowTable = DataTables(params, query, columns)
0 ignored issues
show
Coding Style Naming introduced by
The name rowTable does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
77
    res = rowTable.output_result()
78
79
    assert len(res['data']) == 3
80
    assert res['recordsTotal'] == '3'
81
    assert res['recordsFiltered'] == '3'
82
83
84
def test_list_total_length(session):
85
    """Test if it returns the total list of users."""
86
    columns = [ColumnDT(User.id)]
87
88
    query = session.query()
89
90
    params = create_dt_params(columns, length=-1)
91
    rowTable = DataTables(params, query, columns)
0 ignored issues
show
Coding Style Naming introduced by
The name rowTable does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
92
    res = rowTable.output_result()
93
94
    assert len(res['data']) == 50
95
96
97
@pytest.fixture(scope="function")
98
def fixtures_list_hybrid_attributes(session):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
99
    user51 = User(name='User 51')
100
101
    session.add(user51)
102
    session.commit()
103
104
    yield
105
106
    session.delete(user51)
107
    session.commit()
108
109
110
@pytest.mark.usefixtures("fixtures_list_hybrid_attributes")
111
def test_list_hybrid_attributes(session):
112
    """Test if it returns a list of users with a hybrid property."""
113
    columns = [
114
        ColumnDT(User.id),
115
        ColumnDT(User.dummy),
116
        ColumnDT(User.name),
117
        ColumnDT(User.created_at)
118
    ]
119
120
    session.query(*[User.id, User.dummy]).all()
121
122
    query = session.query()
123
124
    params = create_dt_params(columns, start=50, length=10)
125
    rowTable = DataTables(params, query, columns)
0 ignored issues
show
Coding Style Naming introduced by
The name rowTable does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
126
    res = rowTable.output_result()
127
128
    assert len(res['data']) == 1
129
    assert res['data'][0]['1'] == 'Us'
130
    assert res['data'][0]['2'] == 'User 51'
131
132
133
@pytest.fixture(scope="function")
134
def fixtures_list_specific_page(session):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
135
    user51 = User(name='User 51')
136
    user52 = User(name='User 52')
137
138
    session.add(user51)
139
    session.add(user52)
140
    session.commit()
141
142
    yield
143
144
    session.delete(user51)
145
    session.delete(user52)
146
    session.commit()
147
148
149
@pytest.mark.usefixtures("fixtures_list_specific_page")
150
def test_list_specific_page(session):
151
    """Test if it returns the list of users that are on page 6."""
152
    columns = [ColumnDT(User.id)]
153
154
    query = session.query().select_from(User)
155
156
    params = create_dt_params(columns, start=50, length=10)
157
    rowTable = DataTables(params, query, columns)
0 ignored issues
show
Coding Style Naming introduced by
The name rowTable does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
158
    res = rowTable.output_result()
159
160
    assert len(res['data']) == 2
161
    assert res['recordsTotal'] == '52'
162
    assert res['recordsFiltered'] == '52'
163
    assert res['data'][0]['0'] == 51
164
    assert res['data'][1]['0'] == 52
165