mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-10-15 01:42:12 -05:00
Simplify testcases for websupport
Now websupport modules has separated and move into sphinxcontrib-websupport package. They are also tested in the package. Hence, we should test the bridge code for them.
This commit is contained in:
1 parent
fef9f870d4
commit
c0a39eb3f7
7 files changed
+3
-776
No files matched your search
@@ -8,8 +8,6 @@ Pygments>=2.0
|
||||
docutils>=0.11
|
||||
snowballstemmer>=1.1
|
||||
babel
|
||||
sqlalchemy>=0.9
|
||||
whoosh>=2.0
|
||||
alabaster
|
||||
sphinx_rtd_theme
|
||||
imagesize
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
master_doc = 'markup'
|
||||
source_suffix = '.txt'
|
||||
@@ -1,447 +0,0 @@
|
||||
:tocdepth: 2
|
||||
|
||||
.. title:: set by title directive
|
||||
|
||||
Testing various markup
|
||||
======================
|
||||
|
||||
Meta markup
|
||||
-----------
|
||||
|
||||
.. sectionauthor:: Georg Brandl
|
||||
.. moduleauthor:: Georg Brandl
|
||||
|
||||
.. contents:: TOC
|
||||
|
||||
.. meta::
|
||||
:author: Me
|
||||
:keywords: docs, sphinx
|
||||
|
||||
|
||||
Generic reST
|
||||
------------
|
||||
|
||||
A |subst| (the definition is in rst_epilog).
|
||||
|
||||
.. highlight:: none
|
||||
|
||||
.. _label:
|
||||
|
||||
::
|
||||
|
||||
some code
|
||||
|
||||
Option list:
|
||||
|
||||
-h help
|
||||
--help also help
|
||||
|
||||
Line block:
|
||||
|
||||
| line1
|
||||
| line2
|
||||
| line3
|
||||
| line4
|
||||
| line5
|
||||
| line6
|
||||
| line7
|
||||
|
||||
|
||||
Body directives
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
.. topic:: Title
|
||||
|
||||
Topic body.
|
||||
|
||||
.. sidebar:: Sidebar
|
||||
:subtitle: Sidebar subtitle
|
||||
|
||||
Sidebar body.
|
||||
|
||||
.. rubric:: Test rubric
|
||||
|
||||
.. epigraph:: Epigraph title
|
||||
|
||||
Epigraph body.
|
||||
|
||||
-- Author
|
||||
|
||||
.. highlights:: Highlights
|
||||
|
||||
Highlights body.
|
||||
|
||||
.. pull-quote:: Pull-quote
|
||||
|
||||
Pull quote body.
|
||||
|
||||
.. compound::
|
||||
|
||||
a
|
||||
|
||||
b
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
with some *markup* inside
|
||||
|
||||
|
||||
.. _admonition-section:
|
||||
|
||||
Admonitions
|
||||
^^^^^^^^^^^
|
||||
|
||||
.. admonition:: My Admonition
|
||||
|
||||
Admonition text.
|
||||
|
||||
.. note::
|
||||
Note text.
|
||||
|
||||
.. warning::
|
||||
|
||||
Warning text.
|
||||
|
||||
.. _some-label:
|
||||
|
||||
.. tip::
|
||||
Tip text.
|
||||
|
||||
Indirect hyperlink targets
|
||||
|
||||
.. _other-label: some-label_
|
||||
|
||||
Inline markup
|
||||
-------------
|
||||
|
||||
*Generic inline markup*
|
||||
|
||||
Adding \n to test unescaping.
|
||||
|
||||
* :command:`command\\n`
|
||||
* :dfn:`dfn\\n`
|
||||
* :guilabel:`guilabel with &accelerator and \\n`
|
||||
* :kbd:`kbd\\n`
|
||||
* :mailheader:`mailheader\\n`
|
||||
* :makevar:`makevar\\n`
|
||||
* :manpage:`manpage\\n`
|
||||
* :mimetype:`mimetype\\n`
|
||||
* :newsgroup:`newsgroup\\n`
|
||||
* :program:`program\\n`
|
||||
* :regexp:`regexp\\n`
|
||||
* :menuselection:`File --> Close\\n`
|
||||
* :menuselection:`&File --> &Print`
|
||||
* :file:`a/{varpart}/b\\n`
|
||||
* :samp:`print {i}\\n`
|
||||
|
||||
*Linking inline markup*
|
||||
|
||||
* :pep:`8`
|
||||
* :pep:`Python Enhancement Proposal #8 <8>`
|
||||
* :rfc:`1`
|
||||
* :rfc:`Request for Comments #1 <1>`
|
||||
* :envvar:`HOME`
|
||||
* :keyword:`with`
|
||||
* :token:`try statement <try_stmt>`
|
||||
* :ref:`admonition-section`
|
||||
* :ref:`here <some-label>`
|
||||
* :ref:`there <other-label>`
|
||||
* :ref:`my-figure`
|
||||
* :ref:`my-figure-name`
|
||||
* :ref:`my-table`
|
||||
* :ref:`my-table-name`
|
||||
* :ref:`my-code-block`
|
||||
* :ref:`my-code-block-name`
|
||||
* :numref:`my-figure`
|
||||
* :numref:`my-figure-name`
|
||||
* :numref:`my-table`
|
||||
* :numref:`my-table-name`
|
||||
* :numref:`my-code-block`
|
||||
* :numref:`my-code-block-name`
|
||||
* :doc:`subdir/includes`
|
||||
* ``:download:`` is tested in includes.txt
|
||||
* :option:`Python -c option <python -c>`
|
||||
* This used to crash: :option:`&option`
|
||||
|
||||
Test :abbr:`abbr (abbreviation)` and another :abbr:`abbr (abbreviation)`.
|
||||
|
||||
Testing the :index:`index` role, also available with
|
||||
:index:`explicit <pair: title; explicit>` title.
|
||||
|
||||
.. _with:
|
||||
|
||||
With
|
||||
----
|
||||
|
||||
(Empty section.)
|
||||
|
||||
|
||||
Tables
|
||||
------
|
||||
|
||||
.. tabularcolumns:: |L|p{5cm}|R|
|
||||
|
||||
.. _my-table:
|
||||
|
||||
.. table:: my table
|
||||
:name: my-table-name
|
||||
|
||||
+----+----------------+----+
|
||||
| 1 | * Block elems | x |
|
||||
| | * In table | |
|
||||
+----+----------------+----+
|
||||
| 2 | Empty cells: | |
|
||||
+----+----------------+----+
|
||||
|
||||
.. table:: empty cell in table header
|
||||
|
||||
===== ======
|
||||
\
|
||||
===== ======
|
||||
1 2
|
||||
3 4
|
||||
===== ======
|
||||
|
||||
Tables with multirow and multicol:
|
||||
|
||||
.. only:: latex
|
||||
|
||||
+----+----------------+---------+
|
||||
| 1 | test! | c |
|
||||
+----+---------+------+ |
|
||||
| 2 | col | col | |
|
||||
| y +---------+------+----+----+
|
||||
| x | multi-column cell | x |
|
||||
+----+---------------------+----+
|
||||
|
||||
+----+
|
||||
| 1 |
|
||||
+ +
|
||||
| |
|
||||
+----+
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 0
|
||||
|
||||
* - .. figure:: img.png
|
||||
|
||||
figure in table
|
||||
|
||||
|
||||
Figures
|
||||
-------
|
||||
|
||||
.. _my-figure:
|
||||
|
||||
.. figure:: img.png
|
||||
:name: my-figure-name
|
||||
|
||||
My caption of the figure
|
||||
|
||||
My description paragraph of the figure.
|
||||
|
||||
Description paragraph is wraped with legend node.
|
||||
|
||||
.. figure:: rimg.png
|
||||
:align: right
|
||||
|
||||
figure with align option
|
||||
|
||||
.. figure:: rimg.png
|
||||
:align: right
|
||||
:figwidth: 50%
|
||||
|
||||
figure with align & figwidth option
|
||||
|
||||
.. figure:: rimg.png
|
||||
:align: right
|
||||
:width: 3cm
|
||||
|
||||
figure with align & width option
|
||||
|
||||
Version markup
|
||||
--------------
|
||||
|
||||
.. versionadded:: 0.6
|
||||
Some funny **stuff**.
|
||||
|
||||
.. versionchanged:: 0.6
|
||||
Even more funny stuff.
|
||||
|
||||
.. deprecated:: 0.6
|
||||
Boring stuff.
|
||||
|
||||
.. versionadded:: 1.2
|
||||
|
||||
First paragraph of versionadded.
|
||||
|
||||
.. versionchanged:: 1.2
|
||||
First paragraph of versionchanged.
|
||||
|
||||
Second paragraph of versionchanged.
|
||||
|
||||
|
||||
Code blocks
|
||||
-----------
|
||||
|
||||
.. _my-code-block:
|
||||
|
||||
.. code-block:: ruby
|
||||
:linenos:
|
||||
:caption: my ruby code
|
||||
:name: my-code-block-name
|
||||
|
||||
def ruby?
|
||||
false
|
||||
end
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
import sys
|
||||
|
||||
sys.stdout.write('hello world!\n')
|
||||
|
||||
|
||||
Misc stuff
|
||||
----------
|
||||
|
||||
Stuff [#]_
|
||||
|
||||
Reference lookup: [Ref1]_ (defined in another file).
|
||||
Reference lookup underscore: [Ref_1]_
|
||||
|
||||
.. seealso:: something, something else, something more
|
||||
|
||||
`Google <http://www.google.com>`_
|
||||
For everything.
|
||||
|
||||
.. hlist::
|
||||
:columns: 4
|
||||
|
||||
* This
|
||||
* is
|
||||
* a horizontal
|
||||
* list
|
||||
* with several
|
||||
* items
|
||||
|
||||
.. rubric:: Side note
|
||||
|
||||
This is a side note.
|
||||
|
||||
This tests :CLASS:`role names in uppercase`.
|
||||
|
||||
.. centered:: LICENSE AGREEMENT
|
||||
|
||||
.. acks::
|
||||
|
||||
* Terry Pratchett
|
||||
* J. R. R. Tolkien
|
||||
* Monty Python
|
||||
|
||||
.. glossary::
|
||||
:sorted:
|
||||
|
||||
boson
|
||||
Particle with integer spin.
|
||||
|
||||
*fermion*
|
||||
Particle with half-integer spin.
|
||||
|
||||
tauon
|
||||
myon
|
||||
electron
|
||||
Examples for fermions.
|
||||
|
||||
über
|
||||
Gewisse
|
||||
|
||||
änhlich
|
||||
Dinge
|
||||
|
||||
.. productionlist::
|
||||
try_stmt: `try1_stmt` | `try2_stmt`
|
||||
try1_stmt: "try" ":" `suite`
|
||||
: ("except" [`expression` ["," `target`]] ":" `suite`)+
|
||||
: ["else" ":" `suite`]
|
||||
: ["finally" ":" `suite`]
|
||||
try2_stmt: "try" ":" `suite`
|
||||
: "finally" ":" `suite`
|
||||
|
||||
|
||||
Index markup
|
||||
------------
|
||||
|
||||
.. index::
|
||||
single: entry
|
||||
pair: entry; pair
|
||||
double: entry; double
|
||||
triple: index; entry; triple
|
||||
keyword: with
|
||||
see: from; to
|
||||
seealso: fromalso; toalso
|
||||
|
||||
Invalid index markup...
|
||||
|
||||
.. index::
|
||||
single:
|
||||
pair:
|
||||
keyword:
|
||||
|
||||
.. index::
|
||||
!Main, !Other
|
||||
!single: entry; pair
|
||||
|
||||
:index:`!Main`
|
||||
|
||||
.. _ölabel:
|
||||
|
||||
Ö... Some strange characters
|
||||
----------------------------
|
||||
|
||||
Testing öäü...
|
||||
|
||||
|
||||
Only directive
|
||||
--------------
|
||||
|
||||
.. only:: html
|
||||
|
||||
In HTML.
|
||||
|
||||
.. only:: latex
|
||||
|
||||
In LaTeX.
|
||||
|
||||
.. only:: html or latex
|
||||
|
||||
In both.
|
||||
|
||||
.. only:: confpytag and (testtag or nonexisting_tag)
|
||||
|
||||
Always present, because set through conf.py/command line.
|
||||
|
||||
|
||||
Any role
|
||||
--------
|
||||
|
||||
.. default-role:: any
|
||||
|
||||
Test referencing to `headings <with>` and `objects <func_without_body>`.
|
||||
Also `modules <mod>` and `classes <Time>`.
|
||||
|
||||
More domains:
|
||||
|
||||
* `JS <bar.baz>`
|
||||
* `C <SphinxType>`
|
||||
* `myobj` (user markup)
|
||||
* `n::Array`
|
||||
* `perl -c`
|
||||
|
||||
.. default-role::
|
||||
|
||||
|
||||
.. rubric:: Footnotes
|
||||
|
||||
.. [#] Like footnotes.
|
||||
|
||||
@@ -48,17 +48,6 @@ def test_html_with_set_translator_for_html_(app, status, warning):
|
||||
assert translator_class.__name__ == 'ConfHTMLTranslator'
|
||||
|
||||
|
||||
# this test break test_websupport.test_comments test. why?
|
||||
# @pytest.mark.sphinx(
|
||||
# buildername='dirhtml',
|
||||
# srcdir=(test_roots / 'test-api-set-translator'),
|
||||
# )
|
||||
# def test_dirhtml_set_translator_for_dirhtml(app, status, warning):
|
||||
# translator_class = app.builder.translator_class
|
||||
# assert translator_class
|
||||
# assert translator_class.__name__ == 'ConfDirHTMLTranslator'
|
||||
|
||||
|
||||
@pytest.mark.sphinx('singlehtml', testroot='api-set-translator')
|
||||
def test_singlehtml_set_translator_for_singlehtml(app, status, warning):
|
||||
translator_class = app.builder.translator_class
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
test_searchadapters
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Test the Web Support Package search adapters.
|
||||
|
||||
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
from six import StringIO
|
||||
|
||||
from sphinx.websupport import WebSupport
|
||||
|
||||
from test_websupport import sqlalchemy_missing
|
||||
from util import rootdir, tempdir, skip_if, skip_unless_importable
|
||||
|
||||
|
||||
def teardown_module():
|
||||
(tempdir / 'websupport').rmtree(True)
|
||||
|
||||
|
||||
def search_adapter_helper(adapter):
|
||||
settings = {'srcdir': rootdir / 'roots' / 'test-searchadapters',
|
||||
'builddir': tempdir / 'websupport',
|
||||
'status': StringIO(),
|
||||
'warning': StringIO(),
|
||||
'search': adapter}
|
||||
support = WebSupport(**settings)
|
||||
support.build()
|
||||
|
||||
s = support.search
|
||||
|
||||
# Test the adapters query method. A search for "Epigraph" should return
|
||||
# one result.
|
||||
results = s.query(u'Epigraph')
|
||||
assert len(results) == 1, \
|
||||
'%s search adapter returned %s search result(s), should have been 1'\
|
||||
% (adapter, len(results))
|
||||
|
||||
# Make sure documents are properly updated by the search adapter.
|
||||
s.init_indexing(changed=['markup'])
|
||||
s.add_document(u'markup', u'filename', u'title', u'SomeLongRandomWord')
|
||||
s.finish_indexing()
|
||||
# Now a search for "Epigraph" should return zero results.
|
||||
results = s.query(u'Epigraph')
|
||||
assert len(results) == 0, \
|
||||
'%s search adapter returned %s search result(s), should have been 0'\
|
||||
% (adapter, len(results))
|
||||
# A search for "SomeLongRandomWord" should return one result.
|
||||
results = s.query(u'SomeLongRandomWord')
|
||||
assert len(results) == 1, \
|
||||
'%s search adapter returned %s search result(s), should have been 1'\
|
||||
% (adapter, len(results))
|
||||
# Make sure it works through the WebSupport API
|
||||
support.get_search_results(u'SomeLongRandomWord')
|
||||
|
||||
|
||||
@skip_unless_importable('xapian', 'needs xapian bindings installed')
|
||||
@skip_if(sqlalchemy_missing, 'needs sqlalchemy')
|
||||
def test_xapian():
|
||||
search_adapter_helper('xapian')
|
||||
|
||||
|
||||
@skip_unless_importable('whoosh', 'needs whoosh package installed')
|
||||
@skip_if(sqlalchemy_missing, 'needs sqlalchemy')
|
||||
def test_whoosh():
|
||||
search_adapter_helper('whoosh')
|
||||
+3
-241
@@ -10,14 +10,7 @@
|
||||
"""
|
||||
|
||||
from sphinx.websupport import WebSupport
|
||||
from sphinx.websupport.errors import DocumentNotFoundError, \
|
||||
CommentNotAllowedError, UserNotAuthorizedError
|
||||
from sphinx.websupport.storage import StorageBackend
|
||||
from sphinx.websupport.storage.differ import CombinedHtmlDiff
|
||||
try:
|
||||
from sphinx.websupport.storage.sqlalchemystorage import Session, \
|
||||
Comment, CommentVote
|
||||
from sphinx.websupport.storage.sqlalchemy_db import Node
|
||||
sqlalchemy_missing = False
|
||||
except ImportError:
|
||||
sqlalchemy_missing = True
|
||||
@@ -26,10 +19,10 @@ import pytest
|
||||
from util import rootdir, tempdir
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def support(request):
|
||||
@pytest.mark.skipif(sqlalchemy_missing, reason='needs sqlalchemy')
|
||||
def test_build(request):
|
||||
settings = {
|
||||
'srcdir': rootdir / 'root',
|
||||
'srcdir': rootdir / 'roots' / 'test-basic',
|
||||
# to use same directory for 'builddir' in each 'support' fixture, using
|
||||
# 'tempdir' (static) value instead of 'tempdir' fixture value.
|
||||
# each test expect result of db value at previous test case.
|
||||
@@ -40,235 +33,4 @@ def support(request):
|
||||
settings.update(marker.kwargs)
|
||||
|
||||
support = WebSupport(**settings)
|
||||
yield support
|
||||
|
||||
|
||||
with_support = pytest.mark.support
|
||||
|
||||
|
||||
class NullStorage(StorageBackend):
|
||||
pass
|
||||
|
||||
|
||||
@with_support(storage=NullStorage())
|
||||
def test_no_srcdir(support):
|
||||
# make sure the correct exception is raised if srcdir is not given.
|
||||
with pytest.raises(RuntimeError):
|
||||
support.build()
|
||||
|
||||
|
||||
@pytest.mark.skipif(sqlalchemy_missing, reason='needs sqlalchemy')
|
||||
@with_support()
|
||||
def test_build(support):
|
||||
support.build()
|
||||
|
||||
|
||||
@pytest.mark.skipif(sqlalchemy_missing, reason='needs sqlalchemy')
|
||||
@with_support()
|
||||
def test_get_document(support):
|
||||
with pytest.raises(DocumentNotFoundError):
|
||||
support.get_document('nonexisting')
|
||||
|
||||
contents = support.get_document('contents')
|
||||
assert contents['title'] and contents['body'] \
|
||||
and contents['sidebar'] and contents['relbar']
|
||||
|
||||
|
||||
@pytest.mark.skipif(sqlalchemy_missing, reason='needs sqlalchemy')
|
||||
@with_support()
|
||||
def test_comments(support):
|
||||
session = Session()
|
||||
nodes = session.query(Node).all()
|
||||
first_node = nodes[0]
|
||||
second_node = nodes[1]
|
||||
|
||||
# Create a displayed comment and a non displayed comment.
|
||||
comment = support.add_comment('First test comment',
|
||||
node_id=first_node.id,
|
||||
username='user_one')
|
||||
hidden_comment = support.add_comment('Hidden comment',
|
||||
node_id=first_node.id,
|
||||
displayed=False)
|
||||
# Make sure that comments can't be added to a comment where
|
||||
# displayed == False, since it could break the algorithm that
|
||||
# converts a nodes comments to a tree.
|
||||
with pytest.raises(CommentNotAllowedError):
|
||||
support.add_comment('Not allowed', parent_id=str(hidden_comment['id']))
|
||||
# Add a displayed and not displayed child to the displayed comment.
|
||||
support.add_comment('Child test comment', parent_id=str(comment['id']),
|
||||
username='user_one')
|
||||
support.add_comment('Hidden child test comment',
|
||||
parent_id=str(comment['id']), displayed=False)
|
||||
# Add a comment to another node to make sure it isn't returned later.
|
||||
support.add_comment('Second test comment',
|
||||
node_id=second_node.id,
|
||||
username='user_two')
|
||||
|
||||
# Access the comments as a moderator.
|
||||
data = support.get_data(first_node.id, moderator=True)
|
||||
comments = data['comments']
|
||||
children = comments[0]['children']
|
||||
assert len(comments) == 2
|
||||
assert comments[1]['text'] == '<p>Hidden comment</p>\n'
|
||||
assert len(children) == 2
|
||||
assert children[1]['text'] == '<p>Hidden child test comment</p>\n'
|
||||
|
||||
# Access the comments without being a moderator.
|
||||
data = support.get_data(first_node.id)
|
||||
comments = data['comments']
|
||||
children = comments[0]['children']
|
||||
assert len(comments) == 1
|
||||
assert comments[0]['text'] == '<p>First test comment</p>\n'
|
||||
assert len(children) == 1
|
||||
assert children[0]['text'] == '<p>Child test comment</p>\n'
|
||||
|
||||
|
||||
@pytest.mark.skipif(sqlalchemy_missing, reason='needs sqlalchemy')
|
||||
@with_support()
|
||||
def test_user_delete_comments(support):
|
||||
def get_comment():
|
||||
session = Session()
|
||||
node = session.query(Node).first()
|
||||
session.close()
|
||||
return support.get_data(node.id)['comments'][0]
|
||||
|
||||
comment = get_comment()
|
||||
assert comment['username'] == 'user_one'
|
||||
# Make sure other normal users can't delete someone elses comments.
|
||||
with pytest.raises(UserNotAuthorizedError):
|
||||
support.delete_comment(comment['id'], username='user_two')
|
||||
# Now delete the comment using the correct username.
|
||||
support.delete_comment(comment['id'], username='user_one')
|
||||
comment = get_comment()
|
||||
assert comment['username'] == '[deleted]'
|
||||
assert comment['text'] == '[deleted]'
|
||||
|
||||
|
||||
called = False
|
||||
|
||||
|
||||
def moderation_callback(comment):
|
||||
global called
|
||||
called = True
|
||||
|
||||
|
||||
@pytest.mark.skipif(sqlalchemy_missing, reason='needs sqlalchemy')
|
||||
@with_support(moderation_callback=moderation_callback)
|
||||
def test_moderation(support):
|
||||
session = Session()
|
||||
nodes = session.query(Node).all()
|
||||
node = nodes[7]
|
||||
session.close()
|
||||
accepted = support.add_comment('Accepted Comment', node_id=node.id,
|
||||
displayed=False)
|
||||
deleted = support.add_comment('Comment to delete', node_id=node.id,
|
||||
displayed=False)
|
||||
# Make sure the moderation_callback is called.
|
||||
assert called
|
||||
# Make sure the user must be a moderator.
|
||||
with pytest.raises(UserNotAuthorizedError):
|
||||
support.accept_comment(accepted['id'])
|
||||
with pytest.raises(UserNotAuthorizedError):
|
||||
support.delete_comment(deleted['id'])
|
||||
support.accept_comment(accepted['id'], moderator=True)
|
||||
support.delete_comment(deleted['id'], moderator=True)
|
||||
comments = support.get_data(node.id)['comments']
|
||||
assert len(comments) == 1
|
||||
comments = support.get_data(node.id, moderator=True)['comments']
|
||||
assert len(comments) == 1
|
||||
|
||||
|
||||
@pytest.mark.skipif(sqlalchemy_missing, reason='needs sqlalchemy')
|
||||
@with_support()
|
||||
def test_moderator_delete_comments(support):
|
||||
def get_comment():
|
||||
session = Session()
|
||||
node = session.query(Node).first()
|
||||
session.close()
|
||||
return support.get_data(node.id, moderator=True)['comments'][1]
|
||||
|
||||
comment = get_comment()
|
||||
support.delete_comment(comment['id'], username='user_two',
|
||||
moderator=True)
|
||||
with pytest.raises(IndexError):
|
||||
get_comment()
|
||||
|
||||
|
||||
@pytest.mark.skipif(sqlalchemy_missing, reason='needs sqlalchemy')
|
||||
@with_support()
|
||||
def test_update_username(support):
|
||||
support.update_username('user_two', 'new_user_two')
|
||||
session = Session()
|
||||
comments = session.query(Comment).\
|
||||
filter(Comment.username == 'user_two').all()
|
||||
assert len(comments) == 0
|
||||
votes = session.query(CommentVote).\
|
||||
filter(CommentVote.username == 'user_two').all()
|
||||
assert len(votes) == 0
|
||||
comments = session.query(Comment).\
|
||||
filter(Comment.username == 'new_user_two').all()
|
||||
assert len(comments) == 1
|
||||
votes = session.query(CommentVote).\
|
||||
filter(CommentVote.username == 'new_user_two').all()
|
||||
assert len(votes) == 0
|
||||
|
||||
|
||||
@pytest.mark.skipif(sqlalchemy_missing, reason='needs sqlalchemy')
|
||||
@with_support()
|
||||
def test_proposals(support):
|
||||
session = Session()
|
||||
node = session.query(Node).first()
|
||||
|
||||
data = support.get_data(node.id)
|
||||
|
||||
source = data['source']
|
||||
proposal = source[:5] + source[10:15] + 'asdf' + source[15:]
|
||||
|
||||
support.add_comment('Proposal comment',
|
||||
node_id=node.id,
|
||||
proposal=proposal)
|
||||
|
||||
|
||||
@pytest.mark.skipif(sqlalchemy_missing, reason='needs sqlalchemy')
|
||||
@with_support()
|
||||
def test_voting(support):
|
||||
session = Session()
|
||||
nodes = session.query(Node).all()
|
||||
node = nodes[0]
|
||||
|
||||
comment = support.get_data(node.id)['comments'][0]
|
||||
|
||||
def check_rating(val):
|
||||
data = support.get_data(node.id)
|
||||
comment = data['comments'][0]
|
||||
assert comment['rating'] == val, '%s != %s' % (comment['rating'], val)
|
||||
|
||||
support.process_vote(comment['id'], 'user_one', '1')
|
||||
support.process_vote(comment['id'], 'user_two', '1')
|
||||
support.process_vote(comment['id'], 'user_three', '1')
|
||||
check_rating(3)
|
||||
support.process_vote(comment['id'], 'user_one', '-1')
|
||||
check_rating(1)
|
||||
support.process_vote(comment['id'], 'user_one', '0')
|
||||
check_rating(2)
|
||||
|
||||
# Make sure a vote with value > 1 or < -1 can't be cast.
|
||||
with pytest.raises(ValueError):
|
||||
support.process_vote(comment['id'], 'user_one', '2')
|
||||
with pytest.raises(ValueError):
|
||||
support.process_vote(comment['id'], 'user_one', '-2')
|
||||
|
||||
# Make sure past voting data is associated with comments when they are
|
||||
# fetched.
|
||||
data = support.get_data(str(node.id), username='user_two')
|
||||
comment = data['comments'][0]
|
||||
assert comment['vote'] == 1, '%s != 1' % comment['vote']
|
||||
|
||||
|
||||
def test_differ():
|
||||
source = 'Lorem ipsum dolor sit amet,\nconsectetur adipisicing elit,\n' \
|
||||
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
|
||||
prop = 'Lorem dolor sit amet,\nconsectetur nihil adipisicing elit,\n' \
|
||||
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
|
||||
differ = CombinedHtmlDiff(source, prop)
|
||||
differ.make_html()
|
||||
Reference in new issue
Block a user