Exemple #1
0
    def test_update_entity_is_working_properly(self):
        """testing if update_entity() method is working properly
        """
        from stalker_pyramid.testing import DummyRequest, DummyMultiDict
        request = DummyRequest()
        request.matchdict['id'] = self.test_group1.id
        request.params = DummyMultiDict()
        request.params['name'] = 'New Group Name'
        request.params['user_id'] = [self.test_user1.id, self.test_user2.id]
        request.params['description'] = 'New description'

        request.params['permission'] = \
            ['%s_%s_%s' % (p.access, p.action, p.class_name)
             for p in self.all_permissions[0:5]]

        group_view = group.GroupViews(request)

        self.patch_logged_in_user(request)
        response = group_view.update_entity()

        # get group1 from db
        from stalker import Group
        test_group1_db = Group.query.get(self.test_group1.id)

        self.assertEqual(test_group1_db.name, 'New Group Name')
        self.assertEqual(
            sorted(test_group1_db.users),
            sorted([self.test_user1, self.test_user2])
        )
        self.assertEqual(test_group1_db.description, 'New description')
        self.assertEqual(
            sorted(test_group1_db.permissions),
            sorted(self.all_permissions[0:5])
        )
Exemple #2
0
    def test_delete_entity_is_working_properly(self):
        """testing if delete_entity() method is working properly
        """
        from stalker_pyramid.testing import DummyRequest
        request = DummyRequest()
        request.matchdict['id'] = self.test_group1.id
        group_view = group.GroupViews(request)
        response = group_view.delete_entity()

        from stalker import Group
        self.assertIsNone(
            Group.query.filter(Group.name == self.test_group1.name).first()
        )
Exemple #3
0
    def test_remove_users_is_working_properly(self):
        """testing if remove_users() method is working properly
        """
        from stalker_pyramid.testing import DummyRequest, DummyMultiDict
        request = DummyRequest()
        request.matchdict['id'] = self.test_group1.id
        request.params = DummyMultiDict()
        request.params['user_id'] = [self.test_user2.id]

        group_view = group.GroupViews(request)
        response = group_view.remove_users()

        from stalker import Group
        test_group1_db = Group.query.get(self.test_group1.id)

        self.assertEqual(
            sorted(test_group1_db.users),
            sorted([self.test_user1])
        )
Exemple #4
0
    def test_get_users_is_working_properly(self):
        """testing if get_users() method is working properly
        """
        from stalker_pyramid.testing import DummyRequest
        request = DummyRequest()
        request.matchdict['id'] = self.test_group1.id
        group_view = group.GroupViews(request)
        response = group_view.get_users()

        self.assertEqual(
            sorted(response.json_body),
            sorted([
                {
                    'id': u.id,
                    'name': u.name,
                    'entity_type': 'User',
                    '$ref': '/api/users/%s' % u.id
                } for u in [self.test_user1, self.test_user2]
            ])
        )
Exemple #5
0
    def test_get_entities_is_working_properly(self):
        """testing if get_entities() method is working properly
        """
        from stalker_pyramid.testing import DummyRequest
        request = DummyRequest()
        group_view = group.GroupViews(request)
        response = group_view.get_entities()

        from stalker import Group
        self.assertEqual(
            sorted(response.json_body),
            sorted([
                {
                    'id': g.id,
                    'name': g.name,
                    'entity_type': 'Group',
                    '$ref': '/api/groups/%s' % g.id
                } for g in Group.query.all()
            ])
        )
Exemple #6
0
    def test_update_users_is_working_properly_with_post(self):
        """testing if update_users() method is working properly with request
        method is post
        """
        from stalker_pyramid.testing import DummyRequest, DummyMultiDict
        request = DummyRequest()
        request.matchdict['id'] = self.test_group1.id
        request.params = DummyMultiDict()
        request.params['user_id'] = [self.test_user2.id, self.test_user3.id]
        request.method = 'POST'

        group_view = group.GroupViews(request)
        response = group_view.update_users()

        from stalker import Group
        test_group1_db = Group.query.get(self.test_group1.id)

        self.assertEqual(
            sorted(test_group1_db.users),
            sorted([self.test_user2, self.test_user3])
        )
Exemple #7
0
    def test_create_entity_is_working_properly(self):
        """testing if create_entity() method is working properly
        """
        from stalker_pyramid.testing import DummyRequest, DummyMultiDict
        request = DummyRequest()
        request.params = DummyMultiDict()
        request.params['name'] = 'New Group'
        request.params['description'] = 'This is a new test group'
        request.params['user_id'] = [self.test_user1.id, self.test_user3.id]
        request.params['permission'] = \
            ['%s_%s_%s' % (p.access, p.action, p.class_name)
             for p in self.all_permissions[4:10]]
        request.params['created_by_id'] = self.test_user2.id

        group_view = group.GroupViews(request)
        response = group_view.create_entity()

        # get the new group from db
        import stalker
        from stalker import Group
        from stalker_pyramid.views import EntityViewBase
        new_group = Group.query.filter(Group.name == 'New Group').first()

        self.maxDiff = None
        self.assertEqual(
            response.json_body,
            {
                'created_by': {
                    'id': self.test_user2.id,
                    '$ref': '/api/users/%s' % self.test_user2.id,
                    'name': self.test_user2.name,
                    'entity_type': 'User'
                },
                'date_created':
                    EntityViewBase.milliseconds_since_epoch(new_group.date_created),
                'date_updated':
                    EntityViewBase.milliseconds_since_epoch(new_group.date_updated),
                'description': 'This is a new test group',
                'entity_type': 'Group',
                'generic_data': {
                    '$ref': '/api/simple_entities/%s/generic_data' %
                            new_group.id,
                    'length': 0
                },
                'generic_text': '',
                'id': new_group.id,
                'name': 'New Group',
                'notes': {
                    '$ref': '/api/entities/%s/notes' % new_group.id,
                    'length': 0
                },
                'permissions': [
                    '%s_%s_%s' % (p.access, p.action, p.class_name)
                    for p in self.all_permissions[4:10]
                ],
                'stalker_version': stalker.__version__,
                'tags': {
                    '$ref': '/api/entities/%s/tags' % new_group.id,
                    'length': 0
                },
                'thumbnail': None,
                'type': None,
                'updated_by': {
                    'id': self.test_user2.id,
                    '$ref': '/api/users/%s' % self.test_user2.id,
                    'name': self.test_user2.name,
                    'entity_type': 'User'
                },
                'users': {
                    '$ref': '/api/groups/%s/users' % new_group.id,
                    'length': 2
                }
            }
        )
Exemple #8
0
    def test_get_entity_is_working_properly(self):
        """testing if get_entity() method is working properly
        """
        from stalker_pyramid.testing import DummyRequest
        request = DummyRequest()
        request.matchdict['id'] = self.test_group1.id

        group_view = group.GroupViews(request)
        response = group_view.get_entity()

        import stalker
        from stalker_pyramid.views import EntityViewBase

        self.maxDiff = None
        self.assertEqual(
            response.json_body,
            {
                'created_by': {
                    'id': self.admin.id,
                    '$ref': '/api/users/%s' % self.admin.id,
                    'name': self.admin.name,
                    'entity_type': 'User'
                },
                'date_created':
                    EntityViewBase.milliseconds_since_epoch(
                        self.test_group1.date_created
                    ),
                'date_updated':
                    EntityViewBase.milliseconds_since_epoch(
                        self.test_group1.date_updated
                    ),
                'description': '',
                'entity_type': 'Group',
                'generic_data': {
                    '$ref': '/api/simple_entities/%s/generic_data' %
                            self.test_group1.id,
                    'length': 0
                },
                'generic_text': '',
                'id': self.test_group1.id,
                'name': 'Test Group',
                'notes': {
                    '$ref': '/api/entities/%s/notes' % self.test_group1.id,
                    'length': 0
                },
                'permissions': [
                    'Allow_Create_User',
                    'Allow_Read_User',
                    'Allow_Update_User',
                    'Deny_Delete_User'
                ],
                'stalker_version': stalker.__version__,
                'tags': {
                    '$ref': '/api/entities/%s/tags' % self.test_group1.id,
                    'length': 0
                },
                'thumbnail': None,
                'type': None,
                'updated_by': {
                    'id': self.admin.id,
                    '$ref': '/api/users/%s' % self.admin.id,
                    'name': self.admin.name,
                    'entity_type': 'User'
                },
                'users': {
                    '$ref': '/api/groups/%s/users' % self.test_group1.id,
                    'length': 2
                }
            }
        )