Completed
Pull Request — master (#110)
by Michel
01:13
created

tests.test_listing.test_list()   A

Complexity

Conditions 5

Size

Total Lines 18
Code Lines 14

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 14
dl 18
loc 18
rs 9.2333
c 0
b 0
f 0
cc 5
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
    if not len(res['data']) == 10:
20
        raise AssertionError()
21
    if not len(res['data'][0]) == 1:
22
        raise AssertionError()
23
    if not res['recordsTotal'] == '50':
24
        raise AssertionError()
25
    if not res['recordsFiltered'] == '50':
26
        raise AssertionError()
27
28
29 View Code Duplication
def test_list_bad_length(session):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
30
    """Test if it returns an error for querying with a bad length."""
31
    columns = [ColumnDT(User.id)]
32
33
    query = session.query()
34
35
    params = create_dt_params(columns, length=-10)
36
    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...
37
    res = rowTable.output_result()
38
39
    if 'Length should be' not in res['error']:
40
        raise AssertionError()
41
42
43
def test_list_detail(session):
44
    """Test if it returns a list of detailed users."""
45
    columns = [
46
        ColumnDT(User.id),
47
        ColumnDT(User.name),
48
        ColumnDT(Address.description),
49
        ColumnDT(User.created_at)
50
    ]
51
52
    query = session.query()
53
54
    params = create_dt_params(columns)
55
    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...
56
    res = rowTable.output_result()
57
58
    if not len(res['data'][0]) == 4:
59
        raise AssertionError()
60
61
62 View Code Duplication
def test_list_fixed_length(session):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
63
    """Test if it returns a fixed list of users."""
64
    columns = [ColumnDT(User.id)]
65
66
    query = session.query()
67
68
    params = create_dt_params(columns, length=7)
69
    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...
70
    res = rowTable.output_result()
71
72
    if not len(res['data']) == 7:
73
        raise AssertionError()
74
75
76
def test_list_inner_join(session):
77
    """Test if it returns a list of users with address."""
78
    columns = [ColumnDT(User.id)]
79
80
    query = session.query().select_from(User).join(Address)
81
82
    params = create_dt_params(columns)
83
    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...
84
    res = rowTable.output_result()
85
86
    if not len(res['data']) == 3:
87
        raise AssertionError()
88
    if not res['recordsTotal'] == '3':
89
        raise AssertionError()
90
    if not res['recordsFiltered'] == '3':
91
        raise AssertionError()
92
93
94 View Code Duplication
def test_list_total_length(session):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
95
    """Test if it returns the total list of users."""
96
    columns = [ColumnDT(User.id)]
97
98
    query = session.query()
99
100
    params = create_dt_params(columns, length=-1)
101
    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...
102
    res = rowTable.output_result()
103
104
    if not len(res['data']) == 50:
105
        raise AssertionError()
106
107
108
@pytest.fixture(scope="function")
109
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...
110
    user51 = User(name='User 51')
111
112
    session.add(user51)
113
    session.commit()
114
115
    yield
116
117
    session.delete(user51)
118
    session.commit()
119
120
121
@pytest.mark.usefixtures("fixtures_list_hybrid_attributes")
122
def test_list_hybrid_attributes(session):
123
    """Test if it returns a list of users with a hybrid property."""
124
    columns = [
125
        ColumnDT(User.id),
126
        ColumnDT(User.dummy),
127
        ColumnDT(User.name),
128
        ColumnDT(User.created_at)
129
    ]
130
131
    session.query(*[User.id, User.dummy]).all()
132
133
    query = session.query()
134
135
    params = create_dt_params(columns, start=50, length=10)
136
    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...
137
    res = rowTable.output_result()
138
139
    if not len(res['data']) == 1:
140
        raise AssertionError()
141
    if not res['data'][0]['1'] == 'Us':
142
        raise AssertionError()
143
    if not res['data'][0]['2'] == 'User 51':
144
        raise AssertionError()
145
146
147
@pytest.fixture(scope="function")
148
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...
149
    user51 = User(name='User 51')
150
    user52 = User(name='User 52')
151
152
    session.add(user51)
153
    session.add(user52)
154
    session.commit()
155
156
    yield
157
158
    session.delete(user51)
159
    session.delete(user52)
160
    session.commit()
161
162
163
@pytest.mark.usefixtures("fixtures_list_specific_page")
164
def test_list_specific_page(session):
165
    """Test if it returns the list of users that are on page 6."""
166
    columns = [ColumnDT(User.id)]
167
168
    query = session.query().select_from(User)
169
170
    params = create_dt_params(columns, start=50, length=10)
171
    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...
172
    res = rowTable.output_result()
173
174
    if not len(res['data']) == 2:
175
        raise AssertionError()
176
    if not res['recordsTotal'] == '52':
177
        raise AssertionError()
178
    if not res['recordsFiltered'] == '52':
179
        raise AssertionError()
180
    if not res['data'][0]['0'] == 51:
181
        raise AssertionError()
182
    if not res['data'][1]['0'] == 52:
183
        raise AssertionError()
184