Repository: ckan/ckan

Issue:
Datasets not listed in group feed
### CKAN Version if known (or site URL)

2.5.1
### Please describe the expected behaviour

/feeds/group/group-name.atom should list datasets
### Please describe the actual behaviour

/feeds/group/group-name.atom does not list any datasets. My understanding is that this should be the same as /feeds/custom.atom?groups=group-name

Some public examples:
https://data.hdx.rwlabs.org/feeds/group/nepal-earthquake.atom
https://data.hdx.rwlabs.org/feeds/custom.atom?groups=nepal-earthquake

http://demo.ckan.org/feeds/group/data-explorer.atom
http://demo.ckan.org/feeds/custom.atom?groups=data-explorer
### What steps can be taken to reproduce the issue?

Create a dataset in a group
Go to
/feeds/group/name-of-group.atom



Discussion:

Resolving patch:
diff --git a/ckan/controllers/feed.py b/ckan/controllers/feed.py
--- a/ckan/controllers/feed.py
+++ b/ckan/controllers/feed.py
@@ -171,12 +171,17 @@ def _alternate_url(self, params, **kwargs):
     def _group_or_organization(self, obj_dict, is_org):
 
         data_dict, params = self._parse_url_params()
-        key = 'owner_org' if is_org else 'groups'
-        data_dict['fq'] = '%s:"%s"' % (key, obj_dict['id'],)
-        group_type = 'organization'
-        if not is_org:
+        if is_org:
+            key = 'owner_org'
+            value = obj_dict['id']
+            group_type = 'organization'
+        else:
+            key = 'groups'
+            value = obj_dict['name']
             group_type = 'group'
 
+        data_dict['fq'] = '{0}:"{1}"'.format(key, value)
+
         item_count, results = _package_search(data_dict)
 
         navigation_urls = self._navigation_urls(params,


Test patch:
diff --git a/ckan/tests/controllers/test_feed.py b/ckan/tests/controllers/test_feed.py
--- a/ckan/tests/controllers/test_feed.py
+++ b/ckan/tests/controllers/test_feed.py
@@ -8,6 +8,10 @@
 
 class TestFeedNew(helpers.FunctionalTestBase):
 
+    @classmethod
+    def teardown_class(cls):
+        helpers.reset_db()
+
     def test_atom_feed_page_zero_gives_error(self):
         group = factories.Group()
         offset = url_for(controller='feed', action='group',
@@ -31,3 +35,49 @@ def test_atom_feed_page_not_int_gives_error(self):
         app = self._get_test_app()
         res = app.get(offset, status=400)
         assert '"page" parameter must be a positive integer' in res, res
+
+    def test_general_atom_feed_works(self):
+        dataset = factories.Dataset()
+        offset = url_for(controller='feed', action='general')
+        app = self._get_test_app()
+        res = app.get(offset)
+
+        assert '<title>{0}</title>'.format(dataset['title']) in res.body
+
+    def test_group_atom_feed_works(self):
+        group = factories.Group()
+        dataset = factories.Dataset(groups=[{'id': group['id']}])
+        offset = url_for(controller='feed', action='group',
+                         id=group['name'])
+        app = self._get_test_app()
+        res = app.get(offset)
+
+        assert '<title>{0}</title>'.format(dataset['title']) in res.body
+
+    def test_organization_atom_feed_works(self):
+        group = factories.Organization()
+        dataset = factories.Dataset(owner_org=group['id'])
+        offset = url_for(controller='feed', action='organization',
+                         id=group['name'])
+        app = self._get_test_app()
+        res = app.get(offset)
+
+        assert '<title>{0}</title>'.format(dataset['title']) in res.body
+
+    def test_custom_atom_feed_works(self):
+        dataset1 = factories.Dataset(
+            title='Test weekly',
+            extras=[{'key': 'frequency', 'value': 'weekly'}])
+        dataset2 = factories.Dataset(
+            title='Test daily',
+            extras=[{'key': 'frequency', 'value': 'daily'}])
+        offset = url_for(controller='feed', action='custom')
+        params = {
+            'q': 'frequency:weekly'
+        }
+        app = self._get_test_app()
+        res = app.get(offset, params=params)
+
+        assert '<title>{0}</title>'.format(dataset1['title']) in res.body
+
+        assert '<title>{0}</title>'.format(dataset2['title']) not in res.body