Esempio n. 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_link1.id

        request.params = DummyMultiDict()
        request.params['name'] = 'New Link Name'
        request.params['description'] = 'New description'
        request.params['full_path'] = '/new/path/to/a/file'
        request.params['original_filename'] = 'new_original_file_name'

        link_view = link.LinkViews(request)

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

        from stalker import Link
        link_db = Link.query.get(self.test_link1.id)

        self.assertEqual(link_db.name, 'New Link Name')
        self.assertEqual(link_db.description, 'New description')
        self.assertEqual(link_db.full_path, '/new/path/to/a/file')
        self.assertEqual(link_db.original_filename, 'new_original_file_name')
Esempio n. 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_link1.id

        link_view = link.LinkViews(request)

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

        from stalker import Link
        self.assertIsNone(
            Link.query.filter(Link.id == self.test_link1.id).first())
Esempio n. 3
0
    def test_get_entities_is_working_properly(self):
        """testing if GET: /api/links view is working properly
        """
        from stalker_pyramid.testing import DummyRequest
        request = DummyRequest()
        link_view = link.LinkViews(request)

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

        from stalker import Link
        self.assertEqual(response.json_body, [{
            'id': r.id,
            'name': r.name,
            'entity_type': 'Link',
            '$ref': '/api/links/%s' % r.id
        } for r in Link.query.all()])
Esempio 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_link1.id
        link_view = link.LinkViews(request)

        response = link_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_link1.date_created),
                'date_updated':
                EntityViewBase.milliseconds_since_epoch(
                    self.test_link1.date_updated),
                'description':
                '',
                'entity_type':
                'Link',
                'full_path':
                '/some/full/path/to/a/file.txt',
                'generic_text':
                '',
                'generic_data': {
                    '$ref':
                    '/api/simple_entities/%s/generic_data' %
                    self.test_link1.id,
                    'length':
                    0
                },
                'id':
                self.test_link1.id,
                'name':
                'Test Link 1',
                'notes': {
                    '$ref': '/api/entities/%s/notes' % self.test_link1.id,
                    'length': 0
                },
                'original_filename':
                'the_original_file_name.txt',
                'stalker_version':
                stalker.__version__,
                'tags': {
                    '$ref': '/api/entities/%s/tags' % self.test_link1.id,
                    'length': 0
                },
                'thumbnail':
                None,
                'type':
                None,
                'updated_by': {
                    'name': 'admin',
                    'id': 3,
                    'entity_type': 'User',
                    '$ref': '/api/users/3'
                },
            })
Esempio 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 Link'
        request.params['description'] = 'this is a new test link'
        request.params['created_by_id'] = 3
        request.params['full_path'] = '/full/path/to/a/new/file'
        request.params['original_filename'] = 'original_file_name'

        link_view = link.LinkViews(request)

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

        from stalker import Link
        link_db = Link.query\
            .filter(Link.name == 'New Link')\
            .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(link_db.date_created),
                'date_updated':
                EntityViewBase.milliseconds_since_epoch(link_db.date_updated),
                'description':
                'this is a new test link',
                'entity_type':
                'Link',
                'full_path':
                '/full/path/to/a/new/file',
                'generic_text':
                '',
                'generic_data': {
                    '$ref':
                    '/api/simple_entities/%s/generic_data' % link_db.id,
                    'length': 0
                },
                'id':
                link_db.id,
                'name':
                'New Link',
                'notes': {
                    '$ref': '/api/entities/%s/notes' % link_db.id,
                    'length': 0
                },
                'original_filename':
                'original_file_name',
                'stalker_version':
                stalker.__version__,
                'tags': {
                    '$ref': '/api/entities/%s/tags' % link_db.id,
                    'length': 0
                },
                'thumbnail':
                None,
                'type':
                None,
                'updated_by': {
                    'name': 'admin',
                    'id': 3,
                    'entity_type': 'User',
                    '$ref': '/api/users/3'
                },
            })