Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
internewshid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aptivate
client-projects
internewshid
Commits
e68aa938
Commit
e68aa938
authored
9 years ago
by
Alice Heaton
Browse files
Options
Downloads
Patches
Plain Diff
Update tests to match the new table widget functionality.
parent
f6392a04
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
django/website/hid/tests/table_widget_tests.py
+41
-18
41 additions, 18 deletions
django/website/hid/tests/table_widget_tests.py
with
41 additions
and
18 deletions
django/website/hid/tests/table_widget_tests.py
+
41
−
18
View file @
e68aa938
from
mock
import
patch
from
django.test
import
TestCase
from
hid.widgets.table
import
TableWidget
...
...
@@ -10,25 +13,45 @@ class TestTableWidget(TestCase):
)
self
.
assertEqual
(
context_data
[
'
title
'
],
'
table title
'
)
def
test_context_data_in
cludes_headers
(
self
):
def
test_
get_
context_data_in
vokes_api
(
self
):
widget
=
TableWidget
()
context_data
=
widget
.
get_context_data
(
headers
=
[
'
header one
'
,
'
header two
'
]
)
self
.
assertEqual
(
context_data
[
'
headers
'
],
[
'
header one
'
,
'
header two
'
])
with
patch
(
'
hid.widgets.table.transport.items.list
'
)
as
mock
:
widget
.
get_context_data
()
self
.
assertTrue
(
mock
.
called
)
def
test_context_data_in
cludes_row
s
(
self
):
def
test_
get_
context_data_in
vokes_api_with_filter
s
(
self
):
widget
=
TableWidget
()
with
patch
(
'
hid.widgets.table.transport.items.list
'
)
as
mock
:
widget
.
get_context_data
(
filters
=
{
'
a
'
:
'
b
'
})
self
.
assertEquals
(
mock
.
call_args
[
1
],
{
'
a
'
:
'
b
'
})
context_data
=
widget
.
get_context_data
(
rows
=
[
[
'
row one, col one
'
,
'
row one, col two
'
],
[
'
row two, col one
'
,
'
row two, col two
'
]
]
)
self
.
assertEqual
(
context_data
[
'
rows
'
],
[
[
'
row one, col one
'
,
'
row one, col two
'
],
[
'
row two, col one
'
,
'
row two, col two
'
]
])
def
test_get_context_data_limits_rows_as_per_settings
(
self
):
widget
=
TableWidget
()
with
patch
(
'
hid.widgets.table.transport.items.list
'
)
as
mock
:
mock
.
return_value
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
with
patch
(
'
hid.widgets.table.ItemTable
'
)
as
mock_table
:
widget
.
get_context_data
(
count
=
3
)
processed_rows
=
mock_table
.
call_args
[
0
][
0
]
self
.
assertEqual
(
len
(
processed_rows
),
3
)
def
test_get_context_data_orders_rows_as_per_settings
(
self
):
widget
=
TableWidget
()
with
patch
(
'
hid.widgets.table.transport.items.list
'
)
as
mock
:
mock
.
return_value
=
[{
'
a
'
:
1
},
{
'
a
'
:
4
},
{
'
a
'
:
2
}]
with
patch
(
'
hid.widgets.table.ItemTable
'
)
as
mock_table
:
widget
.
get_context_data
(
order_by
=
'
a
'
)
processed_rows
=
mock_table
.
call_args
[
0
][
0
]
self
.
assertEqual
(
processed_rows
,
[
{
'
a
'
:
1
},
{
'
a
'
:
2
},
{
'
a
'
:
4
}
])
def
test_get_context_data_orders_row_reverse_as_per_settings
(
self
):
widget
=
TableWidget
()
with
patch
(
'
hid.widgets.table.transport.items.list
'
)
as
mock
:
mock
.
return_value
=
[{
'
a
'
:
1
},
{
'
a
'
:
4
},
{
'
a
'
:
2
}]
with
patch
(
'
hid.widgets.table.ItemTable
'
)
as
mock_table
:
widget
.
get_context_data
(
order_by
=
'
-a
'
)
processed_rows
=
mock_table
.
call_args
[
0
][
0
]
self
.
assertEqual
(
processed_rows
,
[
{
'
a
'
:
4
},
{
'
a
'
:
2
},
{
'
a
'
:
1
}
])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment