cubicweb/web/test/unittest_views_cwsources.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 30 Sep 2016 18:25:08 +0200
changeset 11767 432f87a63057
parent 11756 60fed6272771
child 12153 0ff0aff4413d
permissions -rw-r--r--
flake8 and all * update some copyright * drop most __docformat__ declaration * fix some flake8 warnings / errors
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11767
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
     1
# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
     3
#
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
     4
# This file is part of CubicWeb.
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
     5
#
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
     9
# any later version.
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
    10
#
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
    14
# details.
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
    15
#
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
    18
11138
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
from logilab.common import tempattr
11767
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11756
diff changeset
    20
11138
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
from cubicweb.devtools.testlib import CubicWebTC
11756
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    22
from cubicweb.server.sources import datafeed
11138
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
class SynchronizeSourceTC(CubicWebTC):
11756
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    26
11138
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
    def test_synchronize_view(self):
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
        with self.admin_access.web_request(vid='cw.source-sync') as req:
11756
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    29
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    30
            class AParser(datafeed.DataFeedParser):
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    31
                __regid__ = 'testparser'
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    32
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    33
                def process(self, url, raise_on_error=False):
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    34
                    pass
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    35
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    36
            with self.temporary_appobjects(AParser):
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    37
                source = req.create_entity('CWSource', name=u'ext', type=u'datafeed',
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    38
                                           parser=u'cw.entityxml')
60fed6272771 [repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11138
diff changeset
    39
                req.cnx.commit()
11138
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
            self.threads = 0
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
            def threaded_task(func):
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
                self.threads += 1
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
            with tempattr(req.cnx.repo, 'threaded_task', threaded_task):
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
                path, args = self.expect_redirect_handle_request(
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
                    req, path=source.rest_path())
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
                self.assertEqual(self.threads, 1)
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
                self.assertTrue(path.startswith('cwdataimport/'))
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    51
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    53
if __name__ == '__main__':
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    54
    import unittest
78c8e64f3cef [sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    55
    unittest.main()