Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
ots
hypha
Commits
3c23774c
Commit
3c23774c
authored
7 years ago
by
Todd Dembrey
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for the admin section of the project
parent
3f581974
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
opentech/public/projects/tests.py
+82
-0
82 additions, 0 deletions
opentech/public/projects/tests.py
with
82 additions
and
0 deletions
opentech/public/projects/tests.py
0 → 100644
+
82
−
0
View file @
3c23774c
import
json
from
django.test
import
TestCase
from
opentech.apply.categories.models
import
Option
from
opentech.apply.categories.tests.factories
import
CategoryFactory
,
OptionFactory
from
.widgets
import
CategoriesWidget
class
TestCategoriesWidget
(
TestCase
):
def
setUp
(
self
):
self
.
category
=
CategoryFactory
()
self
.
options
=
OptionFactory
.
create_batch
(
3
,
category
=
self
.
category
)
def
test_init_has_no_queries
(
self
):
with
self
.
assertNumQueries
(
0
):
CategoriesWidget
()
def
test_can_access_categories_and_options
(
self
):
widget
=
CategoriesWidget
()
widgets
=
list
(
widget
.
widgets
)
self
.
assertEqual
(
len
(
widgets
),
1
)
choices
=
list
(
widgets
[
0
].
choices
)
self
.
assertEqual
(
len
(
choices
),
len
(
self
.
options
))
self
.
assertCountEqual
(
list
(
choices
),
list
(
Option
.
objects
.
values_list
(
'
id
'
,
'
value
'
)))
def
test_can_get_multiple_categories
(
self
):
CategoryFactory
()
widget
=
CategoriesWidget
()
widgets
=
list
(
widget
.
widgets
)
self
.
assertEqual
(
len
(
widgets
),
2
)
def
test_can_decompress_data
(
self
):
widget
=
CategoriesWidget
()
value
=
json
.
dumps
({
self
.
category
.
id
:
[
self
.
options
[
0
].
id
]
})
self
.
assertEqual
(
widget
.
decompress
(
value
),
[[
self
.
options
[
0
].
id
]])
def
test_can_decompress_multiple_data
(
self
):
new_category
=
CategoryFactory
()
widget
=
CategoriesWidget
()
value
=
json
.
dumps
({
self
.
category
.
id
:
[
self
.
options
[
0
].
id
],
new_category
.
id
:
[],
})
self
.
assertEqual
(
widget
.
decompress
(
value
),
[[
self
.
options
[
0
].
id
],
[]])
def
test_can_get_data_from_form
(
self
):
name
=
'
categories
'
widget
=
CategoriesWidget
()
submitted_data
=
{
name
+
'
_0
'
:
[
self
.
options
[
1
].
id
],
}
value
=
widget
.
value_from_datadict
(
submitted_data
,
[],
name
)
self
.
assertEqual
(
value
,
json
.
dumps
({
self
.
category
.
id
:
[
self
.
options
[
1
].
id
]}))
def
test_can_get_multiple_data_from_form
(
self
):
new_category
=
CategoryFactory
()
new_options
=
OptionFactory
.
create_batch
(
3
,
category
=
new_category
)
name
=
'
categories
'
widget
=
CategoriesWidget
()
answer_1
=
[
self
.
options
[
1
].
id
]
answer_2
=
[
new_options
[
1
].
id
,
new_options
[
2
].
id
]
submitted_data
=
{
name
+
'
_0
'
:
answer_1
,
name
+
'
_1
'
:
answer_2
,
}
value
=
widget
.
value_from_datadict
(
submitted_data
,
[],
name
)
self
.
assertEqual
(
value
,
json
.
dumps
({
self
.
category
.
id
:
answer_1
,
new_category
.
id
:
answer_2
,
})
)
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