Esempio n. 1
0
 def unused_test03(self):
     """
     Test the following situation:
     
     - User 1 opens the :menuselection:`Configure --> System--> System Parameters` dialog
     - User 2 creates a new Person (which increases next_partner_id)
     - User 1 clicks on `Save`.
     
     `next_partner_id` may not get overwritten 
     
     """
     
     url = settings.SITE.build_admin_url('api','system','SiteConfigs','1?an=detail&fmt=json')
     response = self.client.get(url,REMOTE_USER='******')
     result = self.check_json_result(response,'navinfo disable_delete data id title')
     """
     `test01` created one Person, so next_partner_id should be at 101:
     """
     data = result['data']
     self.assertEqual(data['next_partner_id'],contacts.PARTNER_NUMBERS_START_AT + 1) 
     
     
     data['next_partner_id'] = 12345
     #~ pprint(data)
     response = self.client.put(url,data,
       #~ content_type="application/x-www-form-urlencoded; charset=UTF-8",
       REMOTE_USER='******')
     
     result = self.check_json_result(response,'message rows success data_record')
     data = result['data_record']['data']
     
     john = create_and_get(Person,first_name='John',last_name='Smith')
     # fails: self.assertEqual(john.pk,12345)
     """
Esempio n. 2
0
    def unused_test03(self):
        """
        Test the following situation:

        - User 1 opens the :menuselection:`Configure --> System--> System Parameters` dialog
        - User 2 creates a new Person (which increases next_partner_id)
        - User 1 clicks on `Save`.

        `next_partner_id` may not get overwritten

        """

        url = settings.SITE.buildurl('api', 'system', 'SiteConfigs',
                                     '1?an=detail&fmt=json')
        response = self.client.get(url, REMOTE_USER='******')
        result = self.check_json_result(
            response, 'navinfo disable_delete data id title')
        """
        `test01` created one Person, so next_partner_id should be at 101:
        """
        data = result['data']
        self.assertEqual(data['next_partner_id'],
                         contacts.PARTNER_NUMBERS_START_AT + 1)

        data['next_partner_id'] = 12345
        #~ pprint(data)
        response = self.client.put(
            url,
            data,
            #~ content_type="application/x-www-form-urlencoded; charset=UTF-8",
            REMOTE_USER='******')

        result = self.check_json_result(response,
                                        'message rows success data_record')
        data = result['data_record']['data']

        john = create_and_get(Person, first_name='John', last_name='Smith')
Esempio n. 3
0
    def test01(self):

        settings.SITE.startup()  # create cache/wsdl files

        root = create_and_get(settings.SITE.user_model, username='******')

        luc = create_and_get(
            rt.models.pcsw.Client, first_name='Luc', last_name='Saffre')

        # First IdentifyPersonRequest
        # Create an IPR with NISS just to have the XML validated.

        req = cbss.IdentifyPersonRequest(
            national_id="70100853190", user=root, person=luc)
        try:
            req.full_clean()
            self.fail('Expected ValidationError "birth_date cannot be blank."')
        except ValidationError:
            pass

        req.birth_date = IncompleteDate(1938, 6, 1)
        try:
            req.validate_request()
        except Warning as e:
            self.assertEqual(unicode(e), "")
            pass

        req.birth_date = IncompleteDate(1938, 0, 0)
        req.validate_request()
        req.execute_request(simulate_response='Foo', now=NOW)

        expected = """\
<ssdn:SSDNRequest xmlns:ssdn="http://www.ksz-bcss.fgov.be/XSD/SSDN/Service">
<ssdn:RequestContext>
<ssdn:AuthorizedUser>
<ssdn:UserID>00901234567</ssdn:UserID>
<ssdn:Email>[email protected]</ssdn:Email>
<ssdn:OrgUnit>0123456789</ssdn:OrgUnit>
<ssdn:MatrixID>17</ssdn:MatrixID>
<ssdn:MatrixSubID>1</ssdn:MatrixSubID>
</ssdn:AuthorizedUser>
<ssdn:Message>
<ssdn:Reference>IdentifyPersonRequest # 1</ssdn:Reference>
<ssdn:TimeRequest>20150511T183101</ssdn:TimeRequest>
</ssdn:Message>
</ssdn:RequestContext>
<ssdn:ServiceRequest>
<ssdn:ServiceId>OCMWCPASIdentifyPerson</ssdn:ServiceId>
<ssdn:Version>20050930</ssdn:Version>
<ipr:IdentifyPersonRequest xmlns:ipr="http://www.ksz-bcss.fgov.be/XSD/SSDN/OCMW_CPAS/IdentifyPerson">
<ipr:SearchCriteria>
<ipr:SSIN>70100853190</ipr:SSIN>
<ipr:PhoneticCriteria>
<ipr:LastName></ipr:LastName>
<ipr:FirstName></ipr:FirstName>
<ipr:MiddleName></ipr:MiddleName>
<ipr:BirthDate>1938-00-00</ipr:BirthDate>
</ipr:PhoneticCriteria>
</ipr:SearchCriteria>
<ipr:VerificationData>
<ipr:PersonData>
<ipr:LastName></ipr:LastName>
<ipr:FirstName></ipr:FirstName>
<ipr:MiddleName></ipr:MiddleName>
<ipr:BirthDate>1938-00-00</ipr:BirthDate>
</ipr:PersonData>
</ipr:VerificationData>
</ipr:IdentifyPersonRequest>
</ssdn:ServiceRequest>
</ssdn:SSDNRequest>"""
        self.assertEquivalent(expected, req.request_xml)

        ## 

        req = cbss.IdentifyPersonRequest(
            last_name="MUSTERMANN",
            birth_date=IncompleteDate(1938, 0, 0))
        req.validate_request()

        # Create another one, this time a name search.
        # This time we also inspect the generated XML.

        req = cbss.IdentifyPersonRequest(
            user=root, person=luc,
            last_name="MUSTERMANN",
            first_name="Max",
            birth_date=IncompleteDate(1938, 6, 1))
        req.validate_request()
        req.execute_request(simulate_response='Foo', now=NOW)

        expected = """\
<ssdn:SSDNRequest xmlns:ssdn="http://www.ksz-bcss.fgov.be/XSD/SSDN/Service">
<ssdn:RequestContext>
<ssdn:AuthorizedUser>
<ssdn:UserID>00901234567</ssdn:UserID>
<ssdn:Email>[email protected]</ssdn:Email>
<ssdn:OrgUnit>0123456789</ssdn:OrgUnit>
<ssdn:MatrixID>17</ssdn:MatrixID>
<ssdn:MatrixSubID>1</ssdn:MatrixSubID>
</ssdn:AuthorizedUser>
<ssdn:Message>
<ssdn:Reference>IdentifyPersonRequest # 2</ssdn:Reference>
<ssdn:TimeRequest>20150511T183101</ssdn:TimeRequest>
</ssdn:Message>
</ssdn:RequestContext>
<ssdn:ServiceRequest>
<ssdn:ServiceId>OCMWCPASIdentifyPerson</ssdn:ServiceId>
<ssdn:Version>20050930</ssdn:Version>
<ipr:IdentifyPersonRequest xmlns:ipr="http://www.ksz-bcss.fgov.be/XSD/SSDN/OCMW_CPAS/IdentifyPerson">
<ipr:SearchCriteria>
<ipr:PhoneticCriteria>
<ipr:LastName>MUSTERMANN</ipr:LastName>
<ipr:FirstName>Max</ipr:FirstName>
<ipr:MiddleName></ipr:MiddleName>
<ipr:BirthDate>1938-06-01</ipr:BirthDate>
</ipr:PhoneticCriteria>
</ipr:SearchCriteria>
</ipr:IdentifyPersonRequest>
</ssdn:ServiceRequest>
</ssdn:SSDNRequest>"""

        self.assertEquivalent(expected, req.request_xml)

        if settings.SITE.plugins.cbss.cbss_environment != 'test':
            # Skip live tests unless we are in test environment.
            # Otherwise we would have to build /media/chache/wsdl files
            return

        # Execute a RetrieveTIGroupsRequest.

        req = cbss.RetrieveTIGroupsRequest(
            user=root, person=luc,
            national_id='12345678901', language='fr')

        # Try it without environment and see the XML.
        # Note that NewStyleRequests have no validate_request method.

        req.execute_request(simulate_response='Foo', now=NOW)
        expected = ""
        self.assertEquivalent(expected, req.request_xml)

        # Now a ManageAccessRequest

        today = datetime.date(2012, 5, 24)
        kw = dict()
        # dossier in onderzoek voor een maximale periode van twee maanden
        kw.update(purpose_id=1)
        kw.update(national_id='68060105329')
        kw.update(user=root)
        kw.update(person=luc)
        kw.update(start_date=today)
        kw.update(end_date=today)
        kw.update(action=cbss.ManageActions.REGISTER)
        kw.update(query_register=cbss.QueryRegisters.SECONDARY)
        #~ kw.update(id_card_no=)

        kw.update(last_name='SAFFRE')
        kw.update(first_name='LUC JOHANNES')
        kw.update(birth_date=IncompleteDate(1968, 6, 1))
        req = cbss.ManageAccessRequest(**kw)

        req.execute_request(simulate_response='Foo', now=NOW)
        expected = """<ssdn:SSDNRequest xmlns:ssdn="http://www.ksz-bcss.fgov.be/XSD/SSDN/Service">
<ssdn:RequestContext>
<ssdn:AuthorizedUser>
<ssdn:UserID>00901234567</ssdn:UserID>
<ssdn:Email>[email protected]</ssdn:Email>
<ssdn:OrgUnit>0123456789</ssdn:OrgUnit>
<ssdn:MatrixID>17</ssdn:MatrixID>
<ssdn:MatrixSubID>1</ssdn:MatrixSubID>
</ssdn:AuthorizedUser>
<ssdn:Message>
<ssdn:Reference>ManageAccessRequest # 1</ssdn:Reference>
<ssdn:TimeRequest>20150511T183101</ssdn:TimeRequest>
</ssdn:Message>
</ssdn:RequestContext>
<ssdn:ServiceRequest>
<ssdn:ServiceId>OCMWCPASManageAccess</ssdn:ServiceId>
<ssdn:Version>20050930</ssdn:Version>
<mar:ManageAccessRequest xmlns:mar="http://www.ksz-bcss.fgov.be/XSD/SSDN/OCMW_CPAS/ManageAccess">
<mar:SSIN>68060105329</mar:SSIN>
<mar:Purpose>10</mar:Purpose>
<mar:Period>
<common:StartDate xmlns:common="http://www.ksz-bcss.fgov.be/XSD/SSDN/Common">2012-05-24</common:StartDate>
<common:EndDate xmlns:common="http://www.ksz-bcss.fgov.be/XSD/SSDN/Common">2012-05-24</common:EndDate>
</mar:Period>
<mar:Action>REGISTER</mar:Action>
<mar:Sector>17</mar:Sector>
<mar:QueryRegister>SECONDARY</mar:QueryRegister>
<mar:ProofOfAuthentication>
<mar:PersonData>
<mar:LastName>SAFFRE</mar:LastName>
<mar:FirstName>LUC JOHANNES</mar:FirstName>
<mar:BirthDate>1968-06-01</mar:BirthDate>
</mar:PersonData>
</mar:ProofOfAuthentication>
</mar:ManageAccessRequest>
</ssdn:ServiceRequest>
</ssdn:SSDNRequest>
"""
        self.assertEquivalent(expected, req.request_xml)
Esempio n. 4
0
    def test01(self):
        """
        Tests some basic funtionality.
        """
        self.assertEqual(
            settings.MIDDLEWARE, (
                'django.middleware.common.CommonMiddleware',
                'django.middleware.locale.LocaleMiddleware',
                'django.contrib.sessions.middleware.SessionMiddleware',
                'lino.core.auth.middleware.AuthenticationMiddleware',
                'lino.core.auth.middleware.WithUserMiddleware',
                'lino.core.auth.middleware.DeviceTypeMiddleware',
                'lino.core.auth.middleware.RemoteUserMiddleware',
                'lino.utils.ajax.AjaxExceptionResponse'))
            # settings.MIDDLEWARE_CLASSES, (
            #     'django.middleware.common.CommonMiddleware',
            #     'django.middleware.locale.LocaleMiddleware',
            #     'lino.core.auth.RemoteUserMiddleware',
            #     'lino.utils.ajax.AjaxExceptionResponse'))

        Person = rt.models.contacts.Person
        Partner = rt.models.contacts.Partner
        Country = rt.models.countries.Country
        Place = rt.models.countries.Place
        PlaceTypes = rt.models.countries.PlaceTypes
        
        ee = create_and_get(Country,
                            isocode='EE', **dd.babelkw('name',
                                                    de="Estland",
                                                    fr='Estonie',
                                                    en="Estonia",
                                                    nl='Estland',
                                                    et='Eesti',
                                                    ))
        be = create_and_get(Country,
                            isocode='BE', **dd.babelkw('name',
                                                    de="Belgien",
                                                    fr='Belgique',
                                                    en="Belgium",
                                                    nl='Belgie',
                                                    et='Belgia',
                                                    ))

        eupen = create_and_get(
            Place, name=u'Eupen', country=be, zip_code='4700')

        vigala = create_and_get(Place,
                                name='Vigala',
                                country=ee,
                                type=PlaceTypes.municipality)

        luc = create_and_get(Person,
                             first_name='Luc', last_name='Saffre',
                             gender=Genders.male,
                             country=ee, street='Uus', street_no='1',
                             addr2=u'Vana-Vigala küla',
                             city=vigala, zip_code='78003')

        settings.SITE.uppercase_last_name = True

        """If the following tests raise a "DoesNotExist: Company matching
        query does not exist" then this may come because
        Site._site_config has been filled before the database switched
        from the real db to test db.  and not properly reset.

        """

        with translation.override('en'):
            self.assertEquals(luc.address, u'''\
Mr Luc SAFFRE
Uus 1
Vana-Vigala küla
78003 Vigala vald
Estonia''')

        with translation.override('de'):
            self.assertEquals(luc.address, u'''\
Herrn Luc SAFFRE
Uus 1
Vana-Vigala küla
78003 Vigala vald
Estland''')
            self.assertEquals(luc.address_html, '''\
<p>Herrn Luc SAFFRE<br/>Uus 1<br/>Vana-Vigala küla<br/>78003 Vigala vald<br/>Estland</p>''')

        # "new" or "full" style is when the database knows the
        # geographic hierarchy. We then just select "Vana-Vigala" as
        # the "City".

        vana_vigala = create_and_get(Place,
                                     name='Vana-Vigala',
                                     country=ee,
                                     parent=vigala,
                                     type=PlaceTypes.village,
                                     zip_code='78003')

        meeli = create_and_get(Person,
                               first_name='Meeli', last_name='Mets',
                               gender=Genders.female,
                               country=ee, street='Hirvepargi',
                               street_no='123',
                               city=vana_vigala)

        with translation.override('en'):
            self.assertEquals(meeli.address, u'''\
Mrs Meeli METS
Hirvepargi 123
Vana-Vigala küla
78003 Vigala vald
Estonia''')

        root = create_and_get(settings.SITE.user_model,
                              username='******', language='',
                              user_type=UserTypes.admin)

        """
        disable SITE.is_imported_partner() otherwise 
        disabled_fields may contain more than just the 'id' field.
        """
        save_iip = settings.SITE.is_imported_partner

        def f(obj):
            return False
        settings.SITE.is_imported_partner = f

        """
        Note that we must specify the language both in the user 
        and in HTTP_ACCEPT_LANGUAGE because...
        """

        luc = Person.objects.get(name__exact="Saffre Luc")
        self.assertEqual(luc.pk, contacts.PARTNER_NUMBERS_START_AT)

        url = settings.SITE.buildurl(
            'api', 'contacts', 'Person',
            '%d?query=&an=detail&fmt=json' % luc.pk)
        #~ url = '/api/contacts/Person/%d?query=&an=detail&fmt=json' % luc.pk
        if settings.SITE.get_language_info('en'):
            root.language = 'en'
            root.save()
            self.client.force_login(root)
            response = self.client.get(
                url, REMOTE_USER='******', HTTP_ACCEPT_LANGUAGE='en')
            result = self.check_json_result(
                response, 'navinfo disable_delete data id title')
            self.assertEqual(result['data']['country'], "Estonia")
            self.assertEqual(result['data']['gender'], "Male")

        if settings.SITE.get_language_info('de'):
            root.language = 'de'
            root.save()
            response = self.client.get(
                url, REMOTE_USER='******', HTTP_ACCEPT_LANGUAGE='de')
            result = self.check_json_result(
                response,
                'navinfo disable_delete data id title')
            self.assertEqual(result['data']['country'], "Estland")
            self.assertEqual(result['data']['gender'], "Männlich")
            #~ self.assertEqual(result['data']['disabled_fields'],['contact_ptr_id','id'])
            #~ self.assertEqual(result['data']['disabled_fields'],['id'])
            df = result['data']['disabled_fields']
            self.assertEqual(df['id'], True)

        if settings.SITE.get_language_info('fr'):
            root.language = 'fr'
            root.save()
            response = self.client.get(
                url, REMOTE_USER='******', HTTP_ACCEPT_LANGUAGE='fr')
            result = self.check_json_result(
                response, 'navinfo disable_delete data id title')
            self.assertEqual(result['data']['country'], "Estonie")
            self.assertEqual(result['data']['gender'], u"Masculin")

        #~ root.language = lang
        #~ root.save()
        # restore is_imported_partner method
        settings.SITE.is_imported_partner = save_iip

        #~ def test03(self):
        """
        Test the following situation:
        
        - User 1 opens the :menuselection:`Configure --> System--> System Parameters` dialog
        - User 2 creates a new Person (which increases next_partner_id)
        - User 1 clicks on `Save`.
        
        `next_partner_id` may not get overwritten 
        
        """
        # User 1
        sc = settings.SITE.site_config
        self.assertEqual(sc.next_partner_id,
                         contacts.PARTNER_NUMBERS_START_AT + 2)
        sc.update(next_partner_id=12345)
        
        # SiteConfigs = settings.SITE.models.system.SiteConfigs
        # elem = SiteConfigs.get_row_by_pk(None, settings.SITE.config_id)
        # self.assertEqual(elem.next_partner_id,
        #                  contacts.PARTNER_NUMBERS_START_AT + 2)
        # elem.next_partner_id = 12345
        # elem.full_clean()
        # elem.save()
        #~ print "saved"
        sc = settings.SITE.site_config  # re-read it from db
        self.assertEqual(sc.next_partner_id, 12345)
        john = create_and_get(Partner, name='John')
        self.assertEqual(john.pk, 12345)
        self.assertEqual(sc.next_partner_id, 12346)
        sc = settings.SITE.site_config  # re-read it from db
        self.assertEqual(sc.next_partner_id, 12346)
Esempio n. 5
0
    def test01(self):
        """
        Tests some basic funtionality.
        """
        self.assertEqual(settings.MIDDLEWARE_CLASSES,
                         ('django.middleware.common.CommonMiddleware',
                          'django.middleware.locale.LocaleMiddleware',
                          'lino.core.auth.RemoteUserMiddleware',
                          'lino.utils.ajax.AjaxExceptionResponse'))

        Person = dd.resolve_model("contacts.Person")

        ee = create_and_get('countries.Country',
                            isocode='EE',
                            **dd.babelkw(
                                'name',
                                de="Estland",
                                fr='Estonie',
                                en="Estonia",
                                nl='Estland',
                                et='Eesti',
                            ))
        be = create_and_get('countries.Country',
                            isocode='BE',
                            **dd.babelkw(
                                'name',
                                de="Belgien",
                                fr='Belgique',
                                en="Belgium",
                                nl='Belgie',
                                et='Belgia',
                            ))

        PlaceTypes = rt.modules.countries.PlaceTypes
        eupen = create_and_get('countries.Place',
                               name=u'Eupen',
                               country=be,
                               zip_code='4700')

        vigala = create_and_get('countries.Place',
                                name='Vigala',
                                country=ee,
                                type=PlaceTypes.municipality)

        luc = create_and_get(Person,
                             first_name='Luc',
                             last_name='Saffre',
                             gender=Genders.male,
                             country=ee,
                             street='Uus',
                             street_no='1',
                             addr2=u'Vana-Vigala küla',
                             city=vigala,
                             zip_code='78003')

        settings.SITE.uppercase_last_name = True
        """If the following tests raise a "DoesNotExist: Company matching
        query does not exist" then this may come because
        Site._site_config has been filled before the database switched
        from the real db to test db.  and not properly reset.

        """

        with translation.override('en'):
            self.assertEquals(
                luc.address, u'''\
Mr Luc SAFFRE
Uus 1
Vana-Vigala küla
78003 Vigala vald
Estonia''')

        with translation.override('de'):
            self.assertEquals(
                luc.address, u'''\
Herrn Luc SAFFRE
Uus 1
Vana-Vigala küla
78003 Vigala vald
Estland''')
            self.assertEquals(
                luc.address_html, '''\
<p>Herrn Luc SAFFRE<br />Uus 1<br />Vana-Vigala k&#252;la<br />78003 Vigala vald<br />Estland</p>'''
            )

        # "new" or "full" style is when the database knows the
        # geographic hierarchy. We then just select "Vana-Vigala" as
        # the "City".

        vana_vigala = create_and_get('countries.Place',
                                     name='Vana-Vigala',
                                     country=ee,
                                     parent=vigala,
                                     type=PlaceTypes.village,
                                     zip_code='78003')

        meeli = create_and_get(Person,
                               first_name='Meeli',
                               last_name='Mets',
                               gender=Genders.female,
                               country=ee,
                               street='Hirvepargi',
                               street_no='123',
                               city=vana_vigala)

        with translation.override('en'):
            self.assertEquals(
                meeli.address, u'''\
Mrs Meeli METS
Hirvepargi 123
Vana-Vigala küla
78003 Vigala vald
Estonia''')

        u = create_and_get(settings.SITE.user_model,
                           username='******',
                           language='',
                           profile=UserProfiles.admin)
        """
        disable SITE.is_imported_partner() otherwise 
        disabled_fields may contain more than just the 'id' field.
        """
        save_iip = settings.SITE.is_imported_partner

        def f(obj):
            return False

        settings.SITE.is_imported_partner = f
        """
        Note that we must specify the language both in the user 
        and in HTTP_ACCEPT_LANGUAGE because...
        """

        luc = Person.objects.get(name__exact="Saffre Luc")
        self.assertEqual(luc.pk, contacts.PARTNER_NUMBERS_START_AT)

        url = settings.SITE.buildurl('api', 'contacts', 'Person',
                                     '%d?query=&an=detail&fmt=json' % luc.pk)
        #~ url = '/api/contacts/Person/%d?query=&an=detail&fmt=json' % luc.pk
        if settings.SITE.get_language_info('en'):
            u.language = 'en'
            u.save()
            response = self.client.get(url,
                                       REMOTE_USER='******',
                                       HTTP_ACCEPT_LANGUAGE='en')
            result = self.check_json_result(
                response, 'navinfo disable_delete data id title')
            self.assertEqual(result['data']['country'], "Estonia")
            self.assertEqual(result['data']['gender'], "Male")

        if settings.SITE.get_language_info('de'):
            u.language = 'de'
            u.save()
            response = self.client.get(url,
                                       REMOTE_USER='******',
                                       HTTP_ACCEPT_LANGUAGE='de')
            result = self.check_json_result(
                response, 'navinfo disable_delete data id title')
            self.assertEqual(result['data']['country'], "Estland")
            self.assertEqual(result['data']['gender'], u"Männlich")
            #~ self.assertEqual(result['data']['disabled_fields'],['contact_ptr_id','id'])
            #~ self.assertEqual(result['data']['disabled_fields'],['id'])
            df = result['data']['disabled_fields']
            self.assertEqual(df['id'], True)

        if settings.SITE.get_language_info('fr'):
            u.language = 'fr'
            u.save()
            response = self.client.get(url,
                                       REMOTE_USER='******',
                                       HTTP_ACCEPT_LANGUAGE='fr')
            result = self.check_json_result(
                response, 'navinfo disable_delete data id title')
            self.assertEqual(result['data']['country'], "Estonie")
            self.assertEqual(result['data']['gender'], u"Masculin")

        #~ u.language = lang
        #~ u.save()
        # restore is_imported_partner method
        settings.SITE.is_imported_partner = save_iip

        #~ def test03(self):
        """
        Test the following situation:
        
        - User 1 opens the :menuselection:`Configure --> System--> System Parameters` dialog
        - User 2 creates a new Person (which increases next_partner_id)
        - User 1 clicks on `Save`.
        
        `next_partner_id` may not get overwritten 
        
        """
        # User 1
        SiteConfigs = settings.SITE.modules.system.SiteConfigs
        elem = SiteConfigs.get_row_by_pk(None, settings.SITE.config_id)
        self.assertEqual(elem.next_partner_id,
                         contacts.PARTNER_NUMBERS_START_AT + 2)

        elem.next_partner_id = 12345
        elem.full_clean()
        elem.save()
        #~ print "saved"
        self.assertEqual(settings.SITE.site_config.next_partner_id, 12345)
        john = create_and_get(Person, first_name='John', last_name='Smith')
        self.assertEqual(john.pk, 12345)
        self.assertEqual(elem.next_partner_id, 12346)
        self.assertEqual(settings.SITE.site_config.next_partner_id, 12346)
Esempio n. 6
0
    def test01(self):

        # print("20180502 test_cbss.test01()")
        settings.SITE.startup()  # create cache/wsdl files

        root = create_and_get(settings.SITE.user_model, username='******')

        luc = create_and_get(rt.models.pcsw.Client,
                             first_name='Luc',
                             last_name='Saffre')

        # First IdentifyPersonRequest
        # Create an IPR with NISS just to have the XML validated.

        req = cbss.IdentifyPersonRequest(national_id="70100853190",
                                         user=root,
                                         person=luc)
        try:
            req.full_clean()
            self.fail('Expected ValidationError "birth_date cannot be blank."')
        except ValidationError:
            pass

        req.birth_date = IncompleteDate(1938, 6, 1)
        try:
            req.validate_request()
        except Warning as e:
            self.assertEqual(str(e), "")
            pass

        req.birth_date = IncompleteDate(1938, 0, 0)
        req.validate_request()
        req.execute_request(simulate_response='Foo', now=NOW)

        expected = """\
<ssdn:SSDNRequest xmlns:ssdn="http://www.ksz-bcss.fgov.be/XSD/SSDN/Service">
<ssdn:RequestContext>
<ssdn:AuthorizedUser>
<ssdn:UserID>00901234567</ssdn:UserID>
<ssdn:Email>[email protected]</ssdn:Email>
<ssdn:OrgUnit>0123456789</ssdn:OrgUnit>
<ssdn:MatrixID>17</ssdn:MatrixID>
<ssdn:MatrixSubID>1</ssdn:MatrixSubID>
</ssdn:AuthorizedUser>
<ssdn:Message>
<ssdn:Reference>IdentifyPersonRequest # 1</ssdn:Reference>
<ssdn:TimeRequest>20150511T183101</ssdn:TimeRequest>
</ssdn:Message>
</ssdn:RequestContext>
<ssdn:ServiceRequest>
<ssdn:ServiceId>OCMWCPASIdentifyPerson</ssdn:ServiceId>
<ssdn:Version>20050930</ssdn:Version>
<ipr:IdentifyPersonRequest xmlns:ipr="http://www.ksz-bcss.fgov.be/XSD/SSDN/OCMW_CPAS/IdentifyPerson">
<ipr:SearchCriteria>
<ipr:SSIN>70100853190</ipr:SSIN>
<ipr:PhoneticCriteria>
<ipr:LastName></ipr:LastName>
<ipr:FirstName></ipr:FirstName>
<ipr:MiddleName></ipr:MiddleName>
<ipr:BirthDate>1938-00-00</ipr:BirthDate>
</ipr:PhoneticCriteria>
</ipr:SearchCriteria>
<ipr:VerificationData>
<ipr:PersonData>
<ipr:LastName></ipr:LastName>
<ipr:FirstName></ipr:FirstName>
<ipr:MiddleName></ipr:MiddleName>
<ipr:BirthDate>1938-00-00</ipr:BirthDate>
</ipr:PersonData>
</ipr:VerificationData>
</ipr:IdentifyPersonRequest>
</ssdn:ServiceRequest>
</ssdn:SSDNRequest>"""
        self.assertEquivalent(expected, req.request_xml)

        ##

        req = cbss.IdentifyPersonRequest(last_name="MUSTERMANN",
                                         birth_date=IncompleteDate(1938, 0, 0))
        req.validate_request()

        # Create another one, this time a name search.
        # This time we also inspect the generated XML.

        req = cbss.IdentifyPersonRequest(user=root,
                                         person=luc,
                                         last_name="MUSTERMANN",
                                         first_name="Max",
                                         birth_date=IncompleteDate(1938, 6, 1))
        req.validate_request()
        req.execute_request(simulate_response='Foo', now=NOW)

        expected = """\
<ssdn:SSDNRequest xmlns:ssdn="http://www.ksz-bcss.fgov.be/XSD/SSDN/Service">
<ssdn:RequestContext>
<ssdn:AuthorizedUser>
<ssdn:UserID>00901234567</ssdn:UserID>
<ssdn:Email>[email protected]</ssdn:Email>
<ssdn:OrgUnit>0123456789</ssdn:OrgUnit>
<ssdn:MatrixID>17</ssdn:MatrixID>
<ssdn:MatrixSubID>1</ssdn:MatrixSubID>
</ssdn:AuthorizedUser>
<ssdn:Message>
<ssdn:Reference>IdentifyPersonRequest # 2</ssdn:Reference>
<ssdn:TimeRequest>20150511T183101</ssdn:TimeRequest>
</ssdn:Message>
</ssdn:RequestContext>
<ssdn:ServiceRequest>
<ssdn:ServiceId>OCMWCPASIdentifyPerson</ssdn:ServiceId>
<ssdn:Version>20050930</ssdn:Version>
<ipr:IdentifyPersonRequest xmlns:ipr="http://www.ksz-bcss.fgov.be/XSD/SSDN/OCMW_CPAS/IdentifyPerson">
<ipr:SearchCriteria>
<ipr:PhoneticCriteria>
<ipr:LastName>MUSTERMANN</ipr:LastName>
<ipr:FirstName>Max</ipr:FirstName>
<ipr:MiddleName></ipr:MiddleName>
<ipr:BirthDate>1938-06-01</ipr:BirthDate>
</ipr:PhoneticCriteria>
</ipr:SearchCriteria>
</ipr:IdentifyPersonRequest>
</ssdn:ServiceRequest>
</ssdn:SSDNRequest>"""

        self.assertEquivalent(expected, req.request_xml)

        if settings.SITE.plugins.cbss.cbss_environment != 'test':
            # Skip live tests unless we are in test environment.
            # Otherwise we would have to build /media/chache/wsdl files
            return

        # Execute a RetrieveTIGroupsRequest.

        req = cbss.RetrieveTIGroupsRequest(user=root,
                                           person=luc,
                                           national_id='12345678901',
                                           language='fr')

        # Try it without environment and see the XML.
        # Note that NewStyleRequests have no validate_request method.

        req.execute_request(simulate_response='Foo', now=NOW)
        expected = ""
        self.assertEquivalent(expected, req.request_xml)

        # Now a ManageAccessRequest

        today = datetime.date(2012, 5, 24)
        kw = dict()
        # dossier in onderzoek voor een maximale periode van twee maanden
        kw.update(purpose_id=1)
        kw.update(national_id='68060105329')
        kw.update(user=root)
        kw.update(person=luc)
        kw.update(start_date=today)
        kw.update(end_date=today)
        kw.update(action=cbss.ManageActions.REGISTER)
        kw.update(query_register=cbss.QueryRegisters.SECONDARY)
        #~ kw.update(id_card_no=)

        kw.update(last_name='SAFFRE')
        kw.update(first_name='LUC JOHANNES')
        kw.update(birth_date=IncompleteDate(1968, 6, 1))
        req = cbss.ManageAccessRequest(**kw)

        req.execute_request(simulate_response='Foo', now=NOW)
        expected = """<ssdn:SSDNRequest xmlns:ssdn="http://www.ksz-bcss.fgov.be/XSD/SSDN/Service">
<ssdn:RequestContext>
<ssdn:AuthorizedUser>
<ssdn:UserID>00901234567</ssdn:UserID>
<ssdn:Email>[email protected]</ssdn:Email>
<ssdn:OrgUnit>0123456789</ssdn:OrgUnit>
<ssdn:MatrixID>17</ssdn:MatrixID>
<ssdn:MatrixSubID>1</ssdn:MatrixSubID>
</ssdn:AuthorizedUser>
<ssdn:Message>
<ssdn:Reference>ManageAccessRequest # 1</ssdn:Reference>
<ssdn:TimeRequest>20150511T183101</ssdn:TimeRequest>
</ssdn:Message>
</ssdn:RequestContext>
<ssdn:ServiceRequest>
<ssdn:ServiceId>OCMWCPASManageAccess</ssdn:ServiceId>
<ssdn:Version>20050930</ssdn:Version>
<mar:ManageAccessRequest xmlns:mar="http://www.ksz-bcss.fgov.be/XSD/SSDN/OCMW_CPAS/ManageAccess">
<mar:SSIN>68060105329</mar:SSIN>
<mar:Purpose>10</mar:Purpose>
<mar:Period>
<common:StartDate xmlns:common="http://www.ksz-bcss.fgov.be/XSD/SSDN/Common">2012-05-24</common:StartDate>
<common:EndDate xmlns:common="http://www.ksz-bcss.fgov.be/XSD/SSDN/Common">2012-05-24</common:EndDate>
</mar:Period>
<mar:Action>REGISTER</mar:Action>
<mar:Sector>17</mar:Sector>
<mar:QueryRegister>SECONDARY</mar:QueryRegister>
<mar:ProofOfAuthentication>
<mar:PersonData>
<mar:LastName>SAFFRE</mar:LastName>
<mar:FirstName>LUC JOHANNES</mar:FirstName>
<mar:BirthDate>1968-06-01</mar:BirthDate>
</mar:PersonData>
</mar:ProofOfAuthentication>
</mar:ManageAccessRequest>
</ssdn:ServiceRequest>
</ssdn:SSDNRequest>
"""
        self.assertEquivalent(expected, req.request_xml)
Esempio n. 7
0
    def test01(self):
        """
        Tests some basic funtionality.
        """
        #~ self.assertEqual(settings.MIDDLEWARE_CLASSES,1)
        self.assertEqual(1+1, 2)

        Person = dd.resolve_model("contacts.Person")
        # person = Instantiator(Person).build
        # company = Instantiator("contacts.Company").build

        ee = create_and_get('countries.Country',
                            isocode='EE', **babelkw('name',
                                                    de="Estland",
                                                    fr='Estonie',
                                                    en="Estonia",
                                                    nl='Estland',
                                                    et='Eesti',
                                                    ))
        be = create_and_get('countries.Country',
                            isocode='BE', **babelkw('name',
                                                    de="Belgien",
                                                    fr='Belgique',
                                                    en="Belgium",
                                                    nl='Belgie',
                                                    et='Belgia',
                                                    ))

        eupen = create_and_get(
            'countries.Place', name=u'Eupen', country=be, zip_code='4700')

        vigala = create_and_get('countries.Place', name=u'Vigala', country=ee)

        luc = create_and_get(Person,
                             first_name='Luc', last_name='Saffre',
                             gender=Genders.male,
                             country=ee, street='Uus', street_no='1',
                             addr2=u'Vana-Vigala küla',
                             city=vigala, zip_code='78003')

        settings.SITE.uppercase_last_name = True

        """If the following tests raise a "DoesNotExist: Company matching
        query does not exist" then this may come because
        Site._site_config has been filled before the database switched
        from the real db to test db.  and not properly reset.

        """

        if settings.SITE.get_language_info('en'):
            with translation.override('en'):
                self.assertEquals(luc.address, u'''\
Mr Luc SAFFRE
Uus 1
Vana-Vigala küla
78003 Vigala
Estonia''')

        if settings.SITE.get_language_info('de'):
            with translation.override('de'):
                self.assertEquals(luc.address, u'''\
Herrn Luc SAFFRE
Uus 1
Vana-Vigala küla
78003 Vigala
Estland''')
                self.assertEquals(luc.address_html, '''\
<p>Herrn Luc SAFFRE<br />Uus 1<br />Vana-Vigala k&#252;la<br />78003 Vigala<br />Estland</p>''')

        u = create_and_get(settings.SITE.user_model,
                           username='******', language='', profile=dd.UserProfiles.admin)

        """
        disable SITE.is_imported_partner() otherwise 
        disabled_fields may contain more than just the 'id' field.
        """
        save_iip = settings.SITE.is_imported_partner

        def f(obj):
            return False
        settings.SITE.is_imported_partner = f

        """
        Note that we must specify the language both in the user 
        and in HTTP_ACCEPT_LANGUAGE because...
        """

        luc = Person.objects.get(name__exact="Saffre Luc")
        self.assertEqual(luc.pk, contacts.PARTNER_NUMBERS_START_AT)

        url = settings.SITE.build_admin_url(
            'api', 'contacts', 'Person',
            '%d?query=&an=detail&fmt=json' % luc.pk)
        #~ url = '/api/contacts/Person/%d?query=&an=detail&fmt=json' % luc.pk
        if settings.SITE.get_language_info('en'):
            u.language = 'en'
            u.save()
            response = self.client.get(
                url, REMOTE_USER='******', HTTP_ACCEPT_LANGUAGE='en')
            result = self.check_json_result(
                response, 'navinfo disable_delete data id title')
            self.assertEqual(result['data']['country'], "Estonia")
            self.assertEqual(result['data']['gender'], "Male")

        if settings.SITE.get_language_info('de'):
            u.language = 'de'
            u.save()
            response = self.client.get(
                url, REMOTE_USER='******', HTTP_ACCEPT_LANGUAGE='de')
            result = self.check_json_result(
                response,
                'navinfo disable_delete data id title')
            self.assertEqual(result['data']['country'], "Estland")
            self.assertEqual(result['data']['gender'], u"Männlich")
            #~ self.assertEqual(result['data']['disabled_fields'],['contact_ptr_id','id'])
            #~ self.assertEqual(result['data']['disabled_fields'],['id'])
            df = result['data']['disabled_fields']
            self.assertEqual(df['id'], True)

        if settings.SITE.get_language_info('fr'):
            u.language = 'fr'
            u.save()
            response = self.client.get(
                url, REMOTE_USER='******', HTTP_ACCEPT_LANGUAGE='fr')
            result = self.check_json_result(
                response, 'navinfo disable_delete data id title')
            self.assertEqual(result['data']['country'], "Estonie")
            self.assertEqual(result['data']['gender'], u"Masculin")

        #~ u.language = lang
        #~ u.save()
        # restore is_imported_partner method
        settings.SITE.is_imported_partner = save_iip

        #~ def test03(self):
        """
        Test the following situation:
        
        - User 1 opens the :menuselection:`Configure --> System--> System Parameters` dialog
        - User 2 creates a new Person (which increases next_partner_id)
        - User 1 clicks on `Save`.
        
        `next_partner_id` may not get overwritten 
        
        """
        # User 1
        SiteConfigs = settings.SITE.modules.system.SiteConfigs
        elem = SiteConfigs.get_row_by_pk(None, settings.SITE.config_id)
        self.assertEqual(elem.next_partner_id,
                         contacts.PARTNER_NUMBERS_START_AT + 1)

        elem.next_partner_id = 12345
        elem.full_clean()
        elem.save()
        #~ print "saved"
        self.assertEqual(settings.SITE.site_config.next_partner_id, 12345)
        john = create_and_get(Person, first_name='John', last_name='Smith')
        self.assertEqual(john.pk, 12345)
        self.assertEqual(elem.next_partner_id, 12346)
        self.assertEqual(settings.SITE.site_config.next_partner_id, 12346)