How to use taguette - 10 common examples

To help you get started, we’ve selected a few taguette examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github remram44 / taguette / tests.py View on Github external
def test_project(self):
        db = self.application.DBSession()
        projects = [
            database.Project(name="first project", description=""),
            database.Project(name="a test", description="Test project"),
            database.Project(name="private P", description="admin can't see"),
            database.Project(name="last project", description="Other"),
        ]
        for project in projects:
            db.add(project)
        db.commit()
        for i in [1, 2, 4]:
            db.add(database.ProjectMember(
                project_id=i,
                user_login='admin',
                privileges=database.Privileges.ADMIN))
        db.commit()

        # Authenticate with token
        response = self.get('/?token=' + self.application.single_user_token)
        self.assertEqual(response.code, 302)
        self.assertEqual(response.headers['Location'], '/')

        # Check project list
        response = self.get('/')
        self.assertEqual(response.code, 200)
        self.assertIn(b"first project", response.body)
        self.assertIn(b"a test", response.body)
        self.assertNotIn(b"private P", response.body)
github remram44 / taguette / tests.py View on Github external
def test_project(self):
        db = self.application.DBSession()
        projects = [
            database.Project(name="first project", description=""),
            database.Project(name="a test", description="Test project"),
            database.Project(name="private P", description="admin can't see"),
            database.Project(name="last project", description="Other"),
        ]
        for project in projects:
            db.add(project)
        db.commit()
        for i in [1, 2, 4]:
            db.add(database.ProjectMember(
                project_id=i,
                user_login='admin',
                privileges=database.Privileges.ADMIN))
        db.commit()

        # Authenticate with token
        response = self.get('/?token=' + self.application.single_user_token)
        self.assertEqual(response.code, 302)
        self.assertEqual(response.headers['Location'], '/')
github remram44 / taguette / tests.py View on Github external
def test_project(self):
        db = self.application.DBSession()
        projects = [
            database.Project(name="first project", description=""),
            database.Project(name="a test", description="Test project"),
            database.Project(name="private P", description="admin can't see"),
            database.Project(name="last project", description="Other"),
        ]
        for project in projects:
            db.add(project)
        db.commit()
        for i in [1, 2, 4]:
            db.add(database.ProjectMember(
                project_id=i,
                user_login='admin',
                privileges=database.Privileges.ADMIN))
        db.commit()

        # Authenticate with token
        response = self.get('/?token=' + self.application.single_user_token)
github remram44 / taguette / tests.py View on Github external
def test_project(self):
        db = self.application.DBSession()
        projects = [
            database.Project(name="first project", description=""),
            database.Project(name="a test", description="Test project"),
            database.Project(name="private P", description="admin can't see"),
            database.Project(name="last project", description="Other"),
        ]
        for project in projects:
            db.add(project)
        db.commit()
        for i in [1, 2, 4]:
            db.add(database.ProjectMember(
                project_id=i,
                user_login='admin',
                privileges=database.Privileges.ADMIN))
        db.commit()

        # Authenticate with token
        response = self.get('/?token=' + self.application.single_user_token)
        self.assertEqual(response.code, 302)
        self.assertEqual(response.headers['Location'], '/')

        # Check project list
        response = self.get('/')
        self.assertEqual(response.code, 200)
        self.assertIn(b"first project", response.body)
        self.assertIn(b"a test", response.body)
        self.assertNotIn(b"private P", response.body)
        self.assertIn(b"last project", response.body)
github remram44 / taguette / tests.py View on Github external
def tearDown(self):
        close_all_sessions()
        engine = create_engine(DATABASE_URI)
        database.Base.metadata.drop_all(bind=engine)
github remram44 / taguette / tests.py View on Github external
response = self.post('/register', dict(login='User',
                                               password1='hackme',
                                               password2='hackme',
                                               email='test@example.com'))
        self.assertEqual(response.code, 302)
        self.assertEqual(response.headers['Location'], '/')

        # User exists in database
        db = self.application.DBSession()
        self.assertEqual(
            [
                (
                    user.login,
                    bool(user.hashed_password), bool(user.password_set_date),
                )
                for user in db.query(database.User).all()
            ],
            [
                ('admin', True, True),
                ('user', True, True),
            ],
        )

        # Log out
        response = self.get('/logout')
        self.assertEqual(response.code, 302)
        self.assertEqual(response.headers['Location'], '/')

        # Wait so that reset link is more recent than password
        time.sleep(1)

        # Send reset link
github remram44 / taguette / tests.py View on Github external
def test_filename(self):
        validate.filename.windows = True  # escape device names

        self.assertEqual(validate.filename('/etc/passwd'), 'passwd')
        self.assertEqual(validate.filename('/etc/passwd.txt'), 'passwd.txt')
        self.assertEqual(validate.filename('ééé'), '_')
        self.assertEqual(validate.filename('ééé.pdf'), '_.pdf')
        self.assertEqual(validate.filename('/tmp/NUL.pdf'), '_NUL.pdf')
        self.assertEqual(validate.filename('/tmp/nul.pdf'), '_nul.pdf')
github remram44 / taguette / tests.py View on Github external
{'document_add': [{'description': '', 'id': 1, 'name': name}],
             'id': 3})
        poll_proj1 = self.poll_event(1, 3)

        # Create document 2 in project 2
        response = await self.apost('/api/project/2/document/new',
                                    dict(name='otherdoc',
                                         description='Other one'),
                                    fmt='multipart',
                                    files=dict(file=('../otherdoc.html',
                                                     'text/plain',
                                                     b'different content')))
        self.assertEqual(response.code, 200)
        self.assertEqual(response.body, b'{"created": 2}')
        db = self.application.DBSession()
        doc = db.query(database.Document).get(2)
        self.assertEqual(doc.name, 'otherdoc')
        self.assertEqual(doc.description, 'Other one')
        self.assertEqual(doc.filename, 'otherdoc.html')
        self.assertEqual(
            await poll_proj2,
            {'document_add': [{'description': 'Other one', 'id': 2,
                               'name': 'otherdoc'}], 'id': 4})
        poll_proj2 = self.poll_event(2, 4)

        # Create highlight 1 in document 1
        response = await self.apost('/api/project/1/document/1/highlight/new',
                                    dict(start_offset=3, end_offset=7,
                                         tags=[1]),
                                    fmt='json')
        self.assertEqual(response.code, 200)
        self.assertEqual(response.body, b'{"id": 1}')
github remram44 / taguette / tests.py View on Github external
body = (
            b"\n"
            b"\n  \n  <title>Test</title>\n\n"
            b"<h1>Example</h1><p>This is an <a>example</a> text document.\n"
            b"It should be <blink>converted</blink>.</p>\n\n"
            b"<p>It has another paragraph <strong>here</strong>, "
            b"images: <img src="\&quot;here.png\&quot;" width="\&quot;50\&quot;"> "
            b"<img width="\&quot;30\&quot;" src="\&quot;/over/there.png\&quot;" title="\&quot;important\&quot;"> "
            b"<img class="\&quot;a\&quot;" src="\&quot;http://and/the/last/one.png\&quot;">, and "
            b"links: <a href="\&quot;here\&quot;">1</a> "
            b"<a href="\&quot;/over/there\&quot;" title="\&quot;important\&quot;">2</a> "
            b"<a class="\&quot;a\&quot;" href="\&quot;http://and/the/last/one\&quot;">3</a></p>\n"
            b"\n"
        )
        with mock.patch('tornado.process.Subprocess', object()):
            body = await convert.to_html(body, 'text/html', 'test.html',
                                         self.config)
        self.assertEqual(
            body,
            "<h1>Example</h1><p>This is an example text document.\n"
            "It should be converted.</p>\n\n"
github remram44 / taguette / tests.py View on Github external
def test_filename(self):
        validate.filename.windows = True  # escape device names

        self.assertEqual(validate.filename('/etc/passwd'), 'passwd')
        self.assertEqual(validate.filename('/etc/passwd.txt'), 'passwd.txt')
        self.assertEqual(validate.filename('ééé'), '_')
        self.assertEqual(validate.filename('ééé.pdf'), '_.pdf')
        self.assertEqual(validate.filename('/tmp/NUL.pdf'), '_NUL.pdf')
        self.assertEqual(validate.filename('/tmp/nul.pdf'), '_nul.pdf')