sobjects/test/unittest_parsers.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 06 Jun 2011 17:44:43 +0200
changeset 7463 a7daba4046db
parent 7399 972ed1843bd8
child 7531 e891ca479586
permissions -rw-r--r--
[test] update test to avoid failure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
# copyright 2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
#
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
# This file is part of CubicWeb.
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
#
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
# any later version.
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
#
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
# details.
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
#
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
from datetime import datetime
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
from cubicweb.devtools.testlib import CubicWebTC
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
from cubicweb.sobjects.parsers import CWEntityXMLParser
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
orig_parse = CWEntityXMLParser.parse
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    27
def parse(self, url):
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
    try:
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
        url = RELATEDXML[url.split('?')[0]]
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
    except KeyError:
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    31
        pass
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    32
    return orig_parse(self, url)
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
def setUpModule():
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    35
    CWEntityXMLParser.parse = parse
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    36
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
def tearDownModule():
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    38
    CWEntityXMLParser.parse = orig_parse
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
BASEXML = ''.join(u'''
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
<rset size="1">
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    43
 <CWUser eid="5" cwuri="http://pouet.org/5">
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
  <login>sthenault</login>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
  <upassword>toto</upassword>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
  <last_login_time>2011-01-25 14:14:06</last_login_time>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
  <creation_date>2010-01-22 10:27:59</creation_date>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
  <modification_date>2011-01-25 14:14:06</modification_date>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
  <use_email role="subject">
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    50
    <EmailAddress cwuri="http://pouet.org/6" eid="6"/>
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    51
  </use_email>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
  <in_group role="subject">
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    53
    <CWGroup cwuri="http://pouet.org/7" eid="7"/>
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    54
    <CWGroup cwuri="http://pouet.org/8" eid="8"/>
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    55
  </in_group>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    56
  <tags role="object">
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    57
    <Tag cwuri="http://pouet.org/9" eid="9"/>
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    58
    <Tag cwuri="http://pouet.org/10" eid="10"/>
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    59
  </tags>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    60
 </CWUser>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    61
</rset>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    62
'''.splitlines())
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    63
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
RELATEDXML ={
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    65
    'http://pouet.org/6': u'''
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    66
<rset size="1">
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    67
 <EmailAddress eid="6" cwuri="http://pouet.org/6">
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    68
  <address>syt@logilab.fr</address>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    69
  <modification_date>2010-04-13 14:35:56</modification_date>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    70
  <creation_date>2010-04-13 14:35:56</creation_date>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    71
 </EmailAddress>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    72
</rset>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    73
''',
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    74
    'http://pouet.org/7': u'''
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    75
<rset size="1">
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    76
 <CWGroup eid="7" cwuri="http://pouet.org/7">
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    77
  <name>users</name>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    78
 </CWGroup>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    79
</rset>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    80
''',
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    81
    'http://pouet.org/8': u'''
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    82
<rset size="1">
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    83
 <CWGroup eid="8" cwuri="http://pouet.org/8">
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    84
  <name>unknown</name>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    85
 </CWGroup>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    86
</rset>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    87
''',
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    88
    'http://pouet.org/9': u'''
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    89
<rset size="1">
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    90
 <Tag eid="9" cwuri="http://pouet.org/9">
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    91
  <name>hop</name>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    92
 </Tag>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    93
</rset>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    94
''',
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    95
    'http://pouet.org/10': u'''
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    96
<rset size="1">
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    97
 <Tag eid="10" cwuri="http://pouet.org/10">
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    98
  <name>unknown</name>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    99
 </Tag>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   100
</rset>
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   101
''',
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   102
    }
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   103
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   104
class CWEntityXMLParserTC(CubicWebTC):
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   105
    def setup_database(self):
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   106
        req = self.request()
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   107
        source = req.create_entity('CWSource', name=u'myfeed', type=u'datafeed',
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   108
                                   parser=u'cw.entityxml', url=BASEXML)
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   109
        self.commit()
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   110
        source.init_mapping([(('CWUser', 'use_email', '*'),
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   111
                              u'role=subject\naction=copy'),
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   112
                             (('CWUser', 'in_group', '*'),
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   113
                              u'role=subject\naction=link\nlinkattr=name'),
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   114
                             (('*', 'tags', 'CWUser'),
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   115
                              u'role=object\naction=link-or-create\nlinkattr=name'),
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   116
                            ])
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   117
        req.create_entity('Tag', name=u'hop')
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   118
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   119
    def test_actions(self):
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   120
        dfsource = self.repo.sources_by_uri['myfeed']
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   121
        self.assertEqual(dfsource.mapping,
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   122
                         {u'CWUser': {
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   123
                             (u'in_group', u'subject', u'link'): [
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   124
                                 (u'CWGroup', {u'linkattr': u'name'})],
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   125
                             (u'tags', u'object', u'link-or-create'): [
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   126
                                 (u'Tag', {u'linkattr': u'name'})],
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   127
                             (u'use_email', u'subject', u'copy'): [
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   128
                                 (u'EmailAddress', {})]
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   129
                             }
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   130
                          })
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   131
        session = self.repo.internal_session()
7351
ed66f236715d fix _set_relation when no target eids, update datafeed source pull_data arguments to raise on error during tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6968
diff changeset
   132
        stats = dfsource.pull_data(session, force=True, raise_on_error=True)
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   133
        self.assertEqual(sorted(stats.keys()), ['created', 'updated'])
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   134
        self.assertEqual(len(stats['created']), 2)
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   135
        self.assertEqual(stats['updated'], set())
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   136
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   137
        user = self.execute('CWUser X WHERE X login "sthenault"').get_entity(0, 0)
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
        self.assertEqual(user.creation_date, datetime(2010, 01, 22, 10, 27, 59))
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   139
        self.assertEqual(user.modification_date, datetime(2011, 01, 25, 14, 14, 06))
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
   140
        self.assertEqual(user.cwuri, 'http://pouet.org/5')
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   141
        self.assertEqual(user.cw_source[0].name, 'myfeed')
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   142
        self.assertEqual(len(user.use_email), 1)
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   143
        # copy action
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   144
        email = user.use_email[0]
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   145
        self.assertEqual(email.address, 'syt@logilab.fr')
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
   146
        self.assertEqual(email.cwuri, 'http://pouet.org/6')
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   147
        self.assertEqual(email.cw_source[0].name, 'myfeed')
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   148
        # link action
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   149
        self.assertFalse(self.execute('CWGroup X WHERE X name "unknown"'))
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   150
        groups = sorted([g.name for g in user.in_group])
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   151
        self.assertEqual(groups, ['users'])
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   152
        # link or create action
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   153
        tags = sorted([t.name for t in user.reverse_tags])
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   154
        self.assertEqual(tags, ['hop', 'unknown'])
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   155
        tag = self.execute('Tag X WHERE X name "unknown"').get_entity(0, 0)
6968
2abc3befb788 [test] update cwxml tests: computed cwuri have changed, and parser.parse isn't anymore a static method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
   156
        self.assertEqual(tag.cwuri, 'http://testing.fr/cubicweb/%s' % tag.eid)
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   157
        self.assertEqual(tag.cw_source[0].name, 'system')
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   158
7463
a7daba4046db [test] update test to avoid failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7399
diff changeset
   159
        session.set_cnxset()
7351
ed66f236715d fix _set_relation when no target eids, update datafeed source pull_data arguments to raise on error during tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6968
diff changeset
   160
        stats = dfsource.pull_data(session, force=True, raise_on_error=True)
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   161
        self.assertEqual(stats['created'], set())
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   162
        self.assertEqual(len(stats['updated']), 2)
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   163
        self.repo._type_source_cache.clear()
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   164
        self.repo._extid_cache.clear()
7463
a7daba4046db [test] update test to avoid failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7399
diff changeset
   165
        session.set_cnxset()
7351
ed66f236715d fix _set_relation when no target eids, update datafeed source pull_data arguments to raise on error during tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6968
diff changeset
   166
        stats = dfsource.pull_data(session, force=True, raise_on_error=True)
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   167
        self.assertEqual(stats['created'], set())
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   168
        self.assertEqual(len(stats['updated']), 2)
7399
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   169
        session.commit()
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   170
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   171
        # test move to system source
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   172
        self.sexecute('SET X cw_source S WHERE X eid %(x)s, S name "system"', {'x': email.eid})
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   173
        self.commit()
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   174
        rset = self.sexecute('EmailAddress X WHERE X address "syt@logilab.fr"')
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   175
        self.assertEqual(len(rset), 1)
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   176
        e = rset.get_entity(0, 0)
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   177
        self.assertEqual(e.eid, email.eid)
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   178
        self.assertEqual(e.cw_metainformation(), {'source': {'type': u'native', 'uri': u'system'},
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   179
                                                  'type': 'EmailAddress',
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   180
                                                  'extid': None})
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   181
        self.assertEqual(e.cw_source[0].name, 'system')
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   182
        self.assertEqual(e.reverse_use_email[0].login, 'sthenault')
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   183
        self.commit()
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   184
        # test everything is still fine after source synchronization
7463
a7daba4046db [test] update test to avoid failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7399
diff changeset
   185
        session.set_cnxset()
7399
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   186
        stats = dfsource.pull_data(session, force=True, raise_on_error=True)
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   187
        rset = self.sexecute('EmailAddress X WHERE X address "syt@logilab.fr"')
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   188
        self.assertEqual(len(rset), 1)
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   189
        e = rset.get_entity(0, 0)
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   190
        self.assertEqual(e.eid, email.eid)
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   191
        self.assertEqual(e.cw_metainformation(), {'source': {'type': u'native', 'uri': u'system'},
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   192
                                                  'type': 'EmailAddress',
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   193
                                                  'extid': None})
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   194
        self.assertEqual(e.cw_source[0].name, 'system')
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   195
        self.assertEqual(e.reverse_use_email[0].login, 'sthenault')
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   196
        session.commit()
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   197
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   198
        # test delete entity
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   199
        e.cw_delete()
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   200
        self.commit()
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   201
        # test everything is still fine after source synchronization
7463
a7daba4046db [test] update test to avoid failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7399
diff changeset
   202
        session.set_cnxset()
7399
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   203
        stats = dfsource.pull_data(session, force=True, raise_on_error=True)
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   204
        rset = self.sexecute('EmailAddress X WHERE X address "syt@logilab.fr"')
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   205
        self.assertEqual(len(rset), 0)
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   206
        rset = self.sexecute('Any X WHERE X use_email E, X login "sthenault"')
972ed1843bd8 [multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7351
diff changeset
   207
        self.assertEqual(len(rset), 0)
6960
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   208
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   209
if __name__ == '__main__':
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   210
    from logilab.common.testlib import unittest_main
822f2530570d [datafeed] add parser to import cubicweb xml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   211
    unittest_main()