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
1bd1b3f8
Commit
1bd1b3f8
authored
9 years ago
by
Martin Burchell
Browse files
Options
Downloads
Patches
Plain Diff
Added term item count to transport layer
parent
69fa20c8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django/website/transport/taxonomies.py
+12
-3
12 additions, 3 deletions
django/website/transport/taxonomies.py
django/website/transport/tests/taxonomy_term_itemcount_tests.py
+43
-0
43 additions, 0 deletions
.../website/transport/tests/taxonomy_term_itemcount_tests.py
with
55 additions
and
3 deletions
django/website/transport/taxonomies.py
+
12
−
3
View file @
1bd1b3f8
...
...
@@ -3,7 +3,6 @@ from django.core.urlresolvers import reverse
from
rest_api.views
import
TaxonomyViewSet
from
rest_framework.test
import
APIRequestFactory
actions
=
{
'
get
'
:
'
list
'
}
request_factory
=
APIRequestFactory
()
...
...
@@ -11,7 +10,11 @@ def list_url():
return
reverse
(
'
taxonomy-list
'
)
def
get_view
():
def
itemcount_url
(
slug
):
return
reverse
(
'
taxonomy-itemcount
'
,
kwargs
=
{
'
slug
'
:
slug
})
def
get_view
(
actions
):
return
TaxonomyViewSet
.
as_view
(
actions
)
...
...
@@ -22,6 +25,12 @@ def list(**kwargs):
to filter the Taxonomies.
"""
view
=
get_view
()
view
=
get_view
(
actions
=
{
'
get
'
:
'
list
'
}
)
request
=
request_factory
.
get
(
list_url
(),
kwargs
)
return
view
(
request
).
data
def
term_itemcount
(
slug
):
view
=
get_view
(
actions
=
{
'
get
'
:
'
itemcount
'
})
request
=
request_factory
.
get
(
itemcount_url
(
slug
))
return
view
(
request
,
slug
=
slug
).
data
This diff is collapsed.
Click to expand it.
django/website/transport/tests/taxonomy_term_itemcount_tests.py
0 → 100644
+
43
−
0
View file @
1bd1b3f8
from
__future__
import
unicode_literals
,
absolute_import
import
pytest
from
taxonomies.tests.factories
import
(
TaxonomyFactory
,
TermFactory
,
)
import
transport
@pytest.fixture
def
item_data
():
item
=
{
'
body
'
:
"
What is the cuse of ebola?
"
}
return
transport
.
items
.
create
(
item
)
@pytest.fixture
def
questions_category
():
# TODO: Replace with transport call when we have one
return
TaxonomyFactory
(
name
=
"
Ebola Questions
"
)
@pytest.fixture
def
questions_term
(
questions_category
):
# TODO: Replace with transport call when we have one
return
TermFactory
(
taxonomy
=
questions_category
)
@pytest.mark.django_db
def
test_term_itemcount_returns_terms_and_counts
(
item_data
,
questions_category
,
questions_term
):
# This is tested more comprehensively in the API tests
transport
.
items
.
add_term
(
item_data
[
'
id
'
],
questions_category
.
slug
,
questions_term
.
name
)
terms
=
transport
.
taxonomies
.
term_itemcount
(
slug
=
questions_category
.
slug
)
counts
=
{
term
[
'
name
'
]:
term
[
'
count
'
]
for
term
in
terms
}
assert
counts
[
questions_term
.
name
]
==
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