Ejemplo n.º 1
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_role1.id

        role_view = role.RoleViews(request)

        self.patch_logged_in_user(request)
        response = role_view.delete_entity()

        from stalker import Role
        self.assertIsNone(
            Role.query.filter(Role.id == self.test_role1.id).first())
Ejemplo n.º 2
0
    def test_get_entities_is_working_properly(self):
        """testing if GET: /api/roles view is working properly
        """
        from stalker_pyramid.testing import DummyRequest
        request = DummyRequest()
        role_view = role.RoleViews(request)

        response = self.test_app.get('/api/roles', status=200)

        from stalker import Role
        self.assertEqual(response.json_body, [{
            'id': r.id,
            'name': r.name,
            'entity_type': 'Role',
            '$ref': '/api/roles/%s' % r.id
        } for r in Role.query.all()])
Ejemplo n.º 3
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_role1.id

        request.params = DummyMultiDict()
        request.params['name'] = 'New Role Name'
        request.params['description'] = 'New description'

        role_view = role.RoleViews(request)

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

        from stalker import Role
        role_db = Role.query.get(self.test_role1.id)

        self.assertEqual(role_db.name, 'New Role Name')
        self.assertEqual(role_db.description, 'New description')
Ejemplo n.º 4
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_role1.id
        role_view = role.RoleViews(request)

        response = role_view.get_entity()

        import stalker
        from stalker_pyramid.views import EntityViewBase
        self.maxDiff = None
        self.assertEqual(
            response.json_body, {
                'created_by': {
                    'name': 'admin',
                    'id': 3,
                    'entity_type': 'User',
                    '$ref': '/api/users/3'
                },
                'date_created':
                EntityViewBase.milliseconds_since_epoch(
                    self.test_role1.date_created),
                'date_updated':
                EntityViewBase.milliseconds_since_epoch(
                    self.test_role1.date_updated),
                'description':
                '',
                'entity_type':
                'Role',
                'generic_text':
                '',
                'generic_data': {
                    '$ref':
                    '/api/simple_entities/%s/generic_data' %
                    self.test_role1.id,
                    'length':
                    0
                },
                'id':
                self.test_role1.id,
                'name':
                'Test Role 1',
                'notes': {
                    '$ref': '/api/entities/%s/notes' % self.test_role1.id,
                    'length': 0
                },
                'stalker_version':
                stalker.__version__,
                'tags': {
                    '$ref': '/api/entities/%s/tags' % self.test_role1.id,
                    'length': 0
                },
                'thumbnail':
                None,
                'type':
                None,
                'updated_by': {
                    'name': 'admin',
                    'id': 3,
                    'entity_type': 'User',
                    '$ref': '/api/users/3'
                },
            })
Ejemplo n.º 5
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 Role'
        request.params['description'] = 'this is a new test role'
        request.params['created_by_id'] = 3

        role_view = role.RoleViews(request)

        self.patch_logged_in_user(request)
        response = role_view.create_entity()

        from stalker import Role
        role_db = Role.query\
            .filter(Role.name == 'New Role')\
            .first()

        import stalker
        from stalker_pyramid.views import EntityViewBase
        self.maxDiff = None
        self.assertEqual(
            response.json_body, {
                'created_by': {
                    'name': 'admin',
                    'id': 3,
                    'entity_type': 'User',
                    '$ref': '/api/users/3'
                },
                'date_created':
                EntityViewBase.milliseconds_since_epoch(role_db.date_created),
                'date_updated':
                EntityViewBase.milliseconds_since_epoch(role_db.date_updated),
                'description':
                'this is a new test role',
                'entity_type':
                'Role',
                'generic_text':
                '',
                'generic_data': {
                    '$ref':
                    '/api/simple_entities/%s/generic_data' % role_db.id,
                    'length': 0
                },
                'id':
                role_db.id,
                'name':
                'New Role',
                'notes': {
                    '$ref': '/api/entities/%s/notes' % role_db.id,
                    'length': 0
                },
                'stalker_version':
                stalker.__version__,
                'tags': {
                    '$ref': '/api/entities/%s/tags' % role_db.id,
                    'length': 0
                },
                'thumbnail':
                None,
                'type':
                None,
                'updated_by': {
                    'name': 'admin',
                    'id': 3,
                    'entity_type': 'User',
                    '$ref': '/api/users/3'
                },
            })