Example #1
0
 def test_remove_role(self):
     assert_equal(TestRoles.get_roles('system', user_ref='testsysadmin'),
                  ['"testsysadmin" is "admin" on "System"'])
     RightsTool.make_or_remove_roles('remove', 'testsysadmin', 'admin',
                                     'system')
     assert_equal(TestRoles.get_roles('system', user_ref='testsysadmin'),
                  [])
Example #2
0
 def test_make_role(self):
     assert_equal(TestRoles.get_roles('annakarenina', user_ref='tester'),
                  [])
     RightsTool.make_or_remove_roles('make', 'tester', 'admin',
                                     'annakarenina')
     assert_equal(TestRoles.get_roles('annakarenina', user_ref='tester'),
                  [u'"tester" is "admin" on "annakarenina"'])
Example #3
0
 def test_get_children_group_hierarchy__from_top_2(self):
     groups = model.Group.by_name(u'department-of-health').\
             get_children_group_hierarchy(type=group_type)
     # the first group must be NHS or Food Standards Agency - i.e. on the
     # first level down
     nhs = groups[0]
     assert_in(nhs[1], ('national-health-service', 'food-standards-agency'))
     assert_equal(model.Group.get(nhs[3]).name, 'department-of-health')
Example #4
0
 def test_get_children_group_hierarchy__from_top_2(self):
     groups = model.Group.by_name(u'department-of-health').\
             get_children_group_hierarchy(type=group_type)
     # the first group must be NHS or Food Standards Agency - i.e. on the
     # first level down
     nhs = groups[0]
     assert_in(nhs[1], ('national-health-service', 'food-standards-agency'))
     assert_equal(model.Group.get(nhs[3]).name, 'department-of-health')
Example #5
0
 def test_get_children_groups(self):
     res = model.Group.by_name(u'department-of-health').\
           get_children_groups(type=group_type)
     # check groups
     assert_equal(name_set_from_groups(res),
                  set(('national-health-service',
                       'food-standards-agency')))
     # check each group is a Group
     assert isinstance(res[0], model.Group)
     assert_in(res[0].name, ('national-health-service', 'food-standards-agency'))
     assert_in(res[0].title, ('National Health Service', 'Food Standards Agency'))
Example #6
0
 def test_get_children_groups(self):
     res = model.Group.by_name(u'department-of-health').\
           get_children_groups(type=group_type)
     # check groups
     assert_equal(name_set_from_groups(res),
                  set(('national-health-service', 'food-standards-agency')))
     # check each group is a Group
     assert isinstance(res[0], model.Group)
     assert_in(res[0].name,
               ('national-health-service', 'food-standards-agency'))
     assert_in(res[0].title,
               ('National Health Service', 'Food Standards Agency'))
Example #7
0
    def test_search_by_name_or_title_only_returns_active_groups(self):
        model.repo.new_revision()

        active_group = model.Group(name=u'active_group')
        active_group.state = u'active'
        inactive_group = model.Group(name=u'inactive_group')
        inactive_group.state = u'inactive'
        model.Session.add(active_group)
        model.Session.add(inactive_group)
        model.repo.commit_and_remove()

        assert_equal(self._search_results('active_group'), set(['active_group']))
        assert_equal(self._search_results('inactive_group'), set([]))
Example #8
0
    def test_19_package_tag_list_save_duplicates(self):
        name = u"testpkg19"
        context = {"model": model, "session": model.Session}
        pkg_dict = {"name": name}

        rev = model.repo.new_revision()
        package = table_dict_save(pkg_dict, model.Package, context)

        tag_dicts = [{"name": "tag1"}, {"name": "tag1"}]  # duplicate
        package_tag_list_save(tag_dicts, package, context)
        model.repo.commit_and_remove()

        pkg = model.Package.by_name(name)
        assert_equal(set([tag.name for tag in pkg.get_tags()]), set(("tag1",)))
Example #9
0
    def test_search_by_name_or_title_only_returns_active_groups(self):
        model.repo.new_revision()

        active_group = model.Group(name=u'active_group')
        active_group.state = u'active'
        inactive_group = model.Group(name=u'inactive_group')
        inactive_group.state = u'inactive'
        model.Session.add(active_group)
        model.Session.add(inactive_group)
        model.repo.commit_and_remove()

        assert_equal(self._search_results('active_group'),
                     set(['active_group']))
        assert_equal(self._search_results('inactive_group'), set([]))
Example #10
0
    def test_19_package_tag_list_save_duplicates(self):
        name = u'testpkg19'
        context = {'model': model,
                   'session': model.Session}
        pkg_dict = {'name': name}

        rev = model.repo.new_revision()
        package = table_dict_save(pkg_dict, model.Package, context)

        tag_dicts = [{'name': 'tag1'}, {'name': 'tag1'}] # duplicate
        package_tag_list_save(tag_dicts, package, context)
        model.repo.commit_and_remove()

        pkg = model.Package.by_name(name)
        assert_equal(set([tag.name for tag in pkg.get_tags()]), set(('tag1',)))
Example #11
0
    def test_19_package_tag_list_save_duplicates(self):
        name = u'testpkg19'
        context = {'model': model, 'session': model.Session}
        pkg_dict = {'name': name}

        rev = model.repo.new_revision()
        package = table_dict_save(pkg_dict, model.Package, context)

        tag_dicts = [{'name': 'tag1'}, {'name': 'tag1'}]  # duplicate
        package_tag_list_save(tag_dicts, package, context)
        model.repo.commit_and_remove()

        pkg = model.Package.by_name(name)
        assert_equal(set([tag.name for tag in pkg.get_tags()]), set(
            ('tag1', )))
Example #12
0
 def test_get_children_group_hierarchy__from_bottom_tier(self):
     assert_equal(name_set_from_group_tuple(model.Group.by_name(u'nhs-wirral-ccg').\
                                    get_children_group_hierarchy(type=group_type)),
                  set())
Example #13
0
 def test_get_parent_groups_up_hierarchy__from_top(self):
     assert_equal(names_from_groups(model.Group.by_name(u'department-of-health').\
                                   get_parent_group_hierarchy(type=group_type)),
                  [])
Example #14
0
 def test_get_top_level_groups(self):
     assert_equal(names_from_groups(model.Group.by_name(u'nhs-wirral-ccg').\
                                    get_top_level_groups(type=group_type)),
                  ['cabinet-office', 'department-of-health'])
Example #15
0
 def test_get_parent_groups_up_hierarchy__from_top(self):
     assert_equal(names_from_groups(model.Group.by_name(u'department-of-health').\
                                   get_parent_group_hierarchy(type=group_type)),
                  [])
Example #16
0
                    "owner_org": None,
                    "url": u"http://www.annakarenina.com",
                    "version": u"0.7a",
                },
            ],
            "state": u"active",
            "approval_status": u"approved",
            "title": u"help",
            "type": u"group",
        }

        expected["packages"] = sorted(expected["packages"], key=lambda x: x["name"])
        result = self.remove_changable_columns(group_dictized)
        result["packages"] = sorted(result["packages"], key=lambda x: x["name"])

        assert_equal(sorted(result.keys()), sorted(expected.keys()))
        for key in result:
            if key == "is_organization":
                continue
            assert_equal(sorted(result[key]), sorted(expected[key]))

    def test_17_group_apis_to_dict(self):

        context = {"model": model, "session": model.Session}

        api_group = {
            "name": u"testgroup",
            "title": u"Some Group Title",
            "description": u"Great group!",
            "packages": [u"annakarenina", u"warandpeace"],
        }
Example #17
0
 def test_get_children_group_hierarchy__from_bottom_tier(self):
     assert_equal(name_set_from_group_tuple(model.Group.by_name(u'nhs-wirral-ccg').\
                                    get_children_group_hierarchy(type=group_type)),
                  set())
Example #18
0
 def test_get_parents__tier_two(self):
     assert_equal(names_from_groups(model.Group.by_name(u'national-health-service').\
             get_parent_groups(type=group_type)),
                 ['department-of-health'])
Example #19
0
    def test_3_search(self):
        model.repo.new_revision()
        model.Session.add(
            model.Group(name=u'test_org',
                        title=u'Test org',
                        type=u'organization'))
        model.repo.commit_and_remove()

        assert_equal(self._search_results('random'), set([]))
        assert_equal(self._search_results('david'), set(['david']))
        assert_equal(self._search_results('roger'), set(['roger']))
        assert_equal(self._search_results('roger '), set(['roger']))
        assert_equal(self._search_results('David'), set(['david']))
        assert_equal(self._search_results('Dave'), set(['david']))
        assert_equal(self._search_results('Dave\'s'), set(['david']))
        assert_equal(self._search_results('Dave\'s books'), set(['david']))
        assert_equal(self._search_results('Books'), set(['david', 'roger']))
        assert_equal(self._search_results('Books', is_org=True), set([]))
        assert_equal(self._search_results('Test', is_org=True),
                     set(['test_org']))
Example #20
0
 def test_get_top_level_groups(self):
     assert_equal(names_from_groups(model.Group.by_name(u'nhs-wirral-ccg').\
                                    get_top_level_groups(type=group_type)),
                  ['cabinet-office', 'department-of-health'])
Example #21
0
 def test_get_parent_groups_up_hierarchy__from_tier_three(self):
     assert_equal(names_from_groups(model.Group.by_name(u'nhs-wirral-ccg').\
                                    get_parent_group_hierarchy(type=group_type)),
                  ['department-of-health',
                   'national-health-service'])
Example #22
0
 def test_get_parents__tier_two(self):
     assert_equal(names_from_groups(model.Group.by_name(u'national-health-service').\
             get_parent_groups(type=group_type)),
                 ['department-of-health'])
Example #23
0
 def test_get_parents__tier_three(self):
     assert_equal(names_from_groups(model.Group.by_name(u'nhs-wirral-ccg').\
             get_parent_groups(type=group_type)),
                 ['national-health-service'])
Example #24
0
 def test_make_role(self):
     assert_equal(TestRoles.get_roles('annakarenina', user_ref='tester'), [])
     RightsTool.make_or_remove_roles('make', 'tester', 'admin', 'annakarenina')
     assert_equal(TestRoles.get_roles('annakarenina', user_ref='tester'), [u'"tester" is "admin" on "annakarenina"'])
Example #25
0
 def test_get_parent_groups_up_hierarchy__from_tier_three(self):
     assert_equal(names_from_groups(model.Group.by_name(u'nhs-wirral-ccg').\
                                    get_parent_group_hierarchy(type=group_type)),
                  ['department-of-health',
                   'national-health-service'])
Example #26
0
 def test_remove_role(self):
     assert_equal(TestRoles.get_roles('system', user_ref='testsysadmin'), ['"testsysadmin" is "admin" on "System"'])
     RightsTool.make_or_remove_roles('remove', 'testsysadmin', 'admin', 'system')
     assert_equal(TestRoles.get_roles('system', user_ref='testsysadmin'), [])
Example #27
0
    def test_3_search(self):
        model.repo.new_revision()
        model.Session.add(model.Group(name=u'test_org',
                                       title=u'Test org',
                                       type=u'organization'
                         ))
        model.repo.commit_and_remove()


        assert_equal(self._search_results('random'), set([]))
        assert_equal(self._search_results('david'), set(['david']))
        assert_equal(self._search_results('roger'), set(['roger']))
        assert_equal(self._search_results('roger '), set(['roger']))
        assert_equal(self._search_results('David'), set(['david']))
        assert_equal(self._search_results('Dave'), set(['david']))
        assert_equal(self._search_results('Dave\'s'), set(['david']))
        assert_equal(self._search_results('Dave\'s books'), set(['david']))
        assert_equal(self._search_results('Books'), set(['david', 'roger']))
        assert_equal(self._search_results('Books', is_org=True), set([]))
        assert_equal(self._search_results('Test', is_org=True), set(['test_org']))
Example #28
0
 def test_get_children_group_hierarchy__from_tier_two(self):
     assert_equal(name_set_from_group_tuple(model.Group.by_name(u'national-health-service').\
                                    get_children_group_hierarchy(type=group_type)),
                  set(('nhs-wirral-ccg',
                       'nhs-southwark-ccg')))
Example #29
0
                    "creator_user_id": None,
                    "owner_org": None,
                    "url": u"http://www.annakarenina.com",
                    "version": u"0.7a",
                },
            ],
            "state": u"active",
            "approval_status": u"approved",
            "title": u"help",
            "type": u"group",
        }
        expected["packages"] = sorted(expected["packages"], key=lambda x: x["name"])
        result = self.remove_changable_columns(group_dictized)
        result["packages"] = sorted(result["packages"], key=lambda x: x["name"])

        assert_equal(sorted(result.keys()), sorted(expected.keys()))

        for key in result:
            if key in ("is_organization", "package_count"):
                continue
            assert_equal(sorted(result[key]), sorted(expected[key]))
        assert_equal(result["package_count"], expected["package_count"])

    def test_17_group_apis_to_dict(self):

        context = {"model": model, "session": model.Session}

        api_group = {
            "name": u"testgroup",
            "title": u"Some Group Title",
            "description": u"Great group!",
Example #30
0
 def test_get_children_group_hierarchy__from_top(self):
     assert_equal(name_set_from_group_tuple(model.Group.by_name(u'department-of-health').\
                                    get_children_group_hierarchy(type=group_type)),
                  set(('national-health-service', 'food-standards-agency',
                       'nhs-wirral-ccg', 'nhs-southwark-ccg')))
Example #31
0
    def test_16_group_dictized(self):

        context = {"model": model,
                  "session": model.Session}

        pkg = model.Session.query(model.Package).filter_by(name='annakarenina3').first()

        simple_group_dict = {'name': 'simple',
                             'title': 'simple',
                             'type': 'organization',
                            }
        model.repo.new_revision()
        group_dict_save(simple_group_dict, context)
        model.Session.commit()
        model.Session.remove()

        context = {"model": model,
                  "session": model.Session}

        group_dict = {'name': 'help',
                      'title': 'help',
                      'approval_status': 'approved',
                      'extras': [{'key': 'genre', 'value': u'"horror"'},
                                 {'key': 'media', 'value': u'"dvd"'}],
                      'packages':[{'name': 'annakarenina2'}, {'id': pkg.id, 'capacity': 'in'}],
                      'users':[{'name': 'annafan'}],
                      'groups':[{'name': 'simple'}],
                      'tags':[{'name': 'russian'}]
                      }

        model.repo.new_revision()
        group_dict_save(group_dict, context)
        model.Session.commit()
        model.Session.remove()

        group = model.Session.query(model.Group).filter_by(name=u'help').one()

        context = {"model": model,
                  "session": model.Session}

        group_dictized = group_dictize(group, context)

        expected = {'description': u'',
                    'extras': [{'key': u'genre', 'state': u'active', 'value': u'"horror"'},
                               {'key': u'media', 'state': u'active', 'value': u'"dvd"'}],
                    'tags': [{'capacity': u'public', 'display_name': u'russian', 'name': u'russian'}],
                    'groups': [{'description': u'',
                               'capacity' : 'public',
                               'display_name': u'simple',
                               'image_url': u'',
                               'name': u'simple',
                               'packages': 0,
                               'state': u'active',
                               'title': u'simple',
                               'type': u'organization',
                               'approval_status': u'approved'}],
                    'users': [{'about': u'I love reading Annakarenina. My site: <a href="http://anna.com">anna.com</a>',
                              'display_name': u'annafan',
                              'capacity' : 'public',
                              'email': None,
                              'email_hash': 'd41d8cd98f00b204e9800998ecf8427e',
                              'fullname': None,
                              'name': u'annafan',
                              'number_administered_packages': 1L,
                              'number_of_edits': 0L,
                              'reset_key': None}],
                    'name': u'help',
                    'display_name': u'help',
                    'image_url': u'',
                    'packages': [{'author': None,
                                  'author_email': None,
                                  'license_id': u'other-open',
                                  'maintainer': None,
                                  'maintainer_email': None,
                                  'type': None,
                                  'name': u'annakarenina3',
                                  'notes': u'Some test notes\n\n### A 3rd level heading\n\n**Some bolded text.**\n\n*Some italicized text.*\n\nForeign characters:\nu with umlaut \xfc\n66-style quote \u201c\nforeign word: th\xfcmb\n\nNeeds escaping:\nleft arrow <\n\n<http://ckan.net/>\n\n',
                                  'state': u'active',
                                  'capacity' : 'in',
                                  'title': u'A Novel By Tolstoy',
                                  'url': u'http://www.annakarenina.com',
                                  'version': u'0.7a'},
                                 {'author': None,
                                  'author_email': None,
                                  'capacity' : 'public',
                                  'title': u'A Novel By Tolstoy',
                                  'license_id': u'other-open',
                                  'maintainer': None,
                                  'maintainer_email': None,
                                  'type': None,
                                  'name': u'annakarenina2',
                                  'notes': u'Some test notes\n\n### A 3rd level heading\n\n**Some bolded text.**\n\n*Some italicized text.*\n\nForeign characters:\nu with umlaut \xfc\n66-style quote \u201c\nforeign word: th\xfcmb\n\nNeeds escaping:\nleft arrow <\n\n<http://ckan.net/>\n\n',
                                  'state': u'active',
                                  'title': u'A Novel By Tolstoy',
                                  'url': u'http://www.annakarenina.com',
                                  'version': u'0.7a'}],
                    'state': u'active',
                    'approval_status': u'approved',
                    'title': u'help',
                    'type': u'group'}

        expected['packages'] = sorted(expected['packages'], key=lambda x: x['name'])
        result = self.remove_changable_columns(group_dictized)
        result['packages'] = sorted(result['packages'], key=lambda x: x['name'])

        assert_equal(sorted(result.keys()), sorted(expected.keys()))
        for key in result:
            assert_equal(sorted(result[key]), sorted(expected[key]))
Example #32
0
 def test_get_children_group_hierarchy__from_top(self):
     assert_equal(name_set_from_group_tuple(model.Group.by_name(u'department-of-health').\
                                    get_children_group_hierarchy(type=group_type)),
                  set(('national-health-service', 'food-standards-agency',
                       'nhs-wirral-ccg', 'nhs-southwark-ccg')))
Example #33
0
 def test_get_children_group_hierarchy__from_tier_two(self):
     assert_equal(name_set_from_group_tuple(model.Group.by_name(u'national-health-service').\
                                    get_children_group_hierarchy(type=group_type)),
                  set(('nhs-wirral-ccg',
                       'nhs-southwark-ccg')))
Example #34
0
 def test_get_parents__tier_three(self):
     assert_equal(names_from_groups(model.Group.by_name(u'nhs-wirral-ccg').\
             get_parent_groups(type=group_type)),
                 ['national-health-service'])