Пример #1
0
    def test01(self):
        from lino.core import constants
        from lino.modlib.users.choicelists import UserTypes
        from lino.api.shell import countries, users

        Client = rt.models.avanti.Client

        u = users.User(username='******',
                       user_type=UserTypes.admin,
                       language="en")
        u.save()
        self.client.force_login(u)

        be = countries.Country(name="Belgium", isocode="BE")
        be.save()

        kw = dict()
        kw.update(national_id="680601 053-29")
        kw.update(first_name="Jean")
        kw.update(middle_name="Jacques")
        kw.update(last_name="Jeffin")
        jean = create_row(Client, **kw)

        kw.update(first_name="Jo")
        kw.update(national_id="680601 054-28")
        kw.update(last_name="Jeffin")
        jo = create_row(Client, **kw)

        def grid_put(username, url, **data):
            data[constants.URL_PARAM_ACTION_NAME] = 'grid_put'
            kwargs = dict(data=urlencode(data))
            kwargs['REMOTE_USER'] = username
            response = self.client.put(url, **kwargs)
            # print(response)
            return self.check_json_result(response, 'rows success message')

        url = '/api/avanti/Clients/' + str(jean.pk)
        result = grid_put('robin', url, national_id="")
        self.assertEqual(result['success'], True)
        self.assertEqual(result['message'],
                         'Client "JEFFIN Jean (100)" has been updated.')

        jean = Client.objects.get(pk=jean.pk)
        self.assertEqual(jean.national_id, None)

        url = '/api/avanti/Clients/' + str(jo.pk)
        result = grid_put('robin', url, national_id="")
        self.assertEqual(result['success'], True)
        self.assertEqual(result['message'],
                         'Client "JEFFIN Jo (101)" has been updated.')
Пример #2
0
    def test01(self):
        Enrolment = rt.models.courses.Enrolment
        Pupil = rt.models.courses.Pupil
        Line = rt.models.courses.Line
        Course = rt.models.courses.Course
        CourseStates = rt.models.courses.CourseStates
        EnrolmentStates = rt.models.courses.EnrolmentStates
        EventType = rt.models.cal.EventType

        
        # room = create(cal.Room, name="First Room")
        lesson = create(EventType, name="Lesson", event_label="Lesson")
        line = create(Line, name="First Line", event_type=lesson)
        obj = create(
            Course,
            line=line,
            # room=room,
            max_places=3,
            #monday=True,
            #start_date=i2d(20140110),
            state=courses.CourseStates.active)
        self.assertEqual(str(obj), "Activity #1")

        # self.assertEqual(settings.SITE.kernel.site, settings.SITE)
        # self.assertEqual(settings.SITE, dd.site)
        # self.assertEqual(settings.SITE.plugins, dd.plugins)
        # self.assertEqual(settings.SITE.plugins.extjs, dd.plugins.extjs)

        settings.SITE.verbose_client_info_message = True
        users.User(username="******",
                   user_type=UserTypes.admin,
                   language="en").save()
        ses = settings.SITE.login('robin')

        anna = create(Pupil, first_name="Anna")
        bert = create(Pupil, first_name="Bert")
        claire = create(Pupil, first_name="Claire")
        ernie = create(Pupil, first_name="Ernie")

        def ENR(p, start_date, **kwargs):
            return create(
                Enrolment, course=obj, pupil=p,
                state=EnrolmentStates.confirmed,
                start_date=start_date, **kwargs)

        # anna and ernie participated from the beginning.
        # bert stopped in may, and claire started in june.
        # so there were never more than 3 participants.

        # 2015-12-31 : 0 participants, 3 free places
        # 2016-01-01 : 3 participants
        # 2016-05-01 : bert leaves. 2 participants
        # 2016-06-01 : claire starts. 3 participants
        
        ENR(anna, i2d(20160101))
        ENR(bert, i2d(20160101), end_date=i2d(20160501))
        ENR(claire, i2d(20160601))
        ENR(ernie, i2d(20160101))

        self.assertEqual(obj.get_free_places(i2d(20151231)), 3)
        self.assertEqual(obj.get_free_places(i2d(20160101)), 0)
        self.assertEqual(obj.get_free_places(i2d(20160301)), 0)
        self.assertEqual(obj.get_free_places(i2d(20160531)), 1)
        self.assertEqual(obj.get_free_places(i2d(20161231)), 0)
        
        #self.assertEqual(enr.get_confirm_veto(None), '')

        # 20180731 the default value for the enrolment state was a
        # string which became an EnrolmentStates choice only during
        # full_clean().  Now this case is being resolved in
        # ChoiceListField.__init__().
        
        enr = Enrolment(course=obj, pupil=anna)
        self.assertEqual(enr.state, EnrolmentStates.requested)
Пример #3
0
    def test01(self):
        # Create a room, event type, series and a course

        room = create(cal.Room, name="First Room")
        lesson = create(cal.EventType, name="Lesson", event_label="Lesson")
        line = create(courses.Line, name="First Line", event_type=lesson)
        obj = create(courses.Course,
                     line=line,
                     room=room,
                     max_events=5,
                     monday=True,
                     state=courses.CourseStates.active,
                     start_date=i2d(20140110))
        self.assertEqual(str(obj), "Activity #1")

        # self.assertEqual(settings.SITE.kernel.site, settings.SITE)
        # self.assertEqual(settings.SITE, dd.site)
        # self.assertEqual(settings.SITE.plugins, dd.plugins)
        # self.assertEqual(settings.SITE.plugins.extjs, dd.plugins.extjs)

        settings.SITE.verbose_client_info_message = True
        users.User(username="******", user_type=UserTypes.admin,
                   language="en").save()
        ses = settings.SITE.login('robin')

        # utility function which runs update_events and checks whether
        # info_message and output of cal.EntriesByController are as
        # expected:
        def check_update(obj, msg1, msg2):
            res = ses.run(obj.do_update_events)
            self.assertEqual(res['success'], True)
            print(res['info_message'])
            self.assertEqual(res['info_message'].strip(), msg1.strip())
            ar = ses.spawn(cal.EntriesByController, master_instance=obj)
            s = ar.to_rst(column_names="when_text state summary",
                          nosummary=True)
            # print(s)
            self.assertEqual(s.strip(), msg2.strip())

        # Run do_update_events a first time
        check_update(
            obj, """
Update Events for Activity #1...
Generating events between 2014-01-13 and 2020-05-22 (max. 5).
Update presences for Activity #1 Lesson 1 : 0 created, 0 unchanged, 0 deleted.
Update presences for Activity #1 Lesson 2 : 0 created, 0 unchanged, 0 deleted.
Update presences for Activity #1 Lesson 3 : 0 created, 0 unchanged, 0 deleted.
Update presences for Activity #1 Lesson 4 : 0 created, 0 unchanged, 0 deleted.
Update presences for Activity #1 Lesson 5 : 0 created, 0 unchanged, 0 deleted.
5 row(s) have been updated.
""", """
================ =========== ===================
 When             State       Short description
---------------- ----------- -------------------
 Mon 13/01/2014   Suggested   Lesson 1
 Mon 20/01/2014   Suggested   Lesson 2
 Mon 27/01/2014   Suggested   Lesson 3
 Mon 03/02/2014   Suggested   Lesson 4
 Mon 10/02/2014   Suggested   Lesson 5
================ =========== ===================
""")

        # Decrease max_events and check whether the superfluous events
        # get removed.

        obj.max_events = 3
        check_update(
            obj, """
Update Events for Activity #1...
Generating events between 2014-01-13 and 2020-05-22 (max. 3).
2 row(s) have been updated.""", """
================ =========== ===================
 When             State       Short description
---------------- ----------- -------------------
 Mon 13/01/2014   Suggested   Lesson 1
 Mon 20/01/2014   Suggested   Lesson 2
 Mon 27/01/2014   Suggested   Lesson 3
================ =========== ===================
""")

        # Run do_update_events for 5 events a second time
        obj.max_events = 5
        check_update(
            obj, """
Update Events for Activity #1...
Generating events between 2014-01-13 and 2020-05-22 (max. 5).
Update presences for Activity #1 Lesson 4 : 0 created, 0 unchanged, 0 deleted.
Update presences for Activity #1 Lesson 5 : 0 created, 0 unchanged, 0 deleted.
2 row(s) have been updated.""", """
================ =========== ===================
 When             State       Short description
---------------- ----------- -------------------
 Mon 13/01/2014   Suggested   Lesson 1
 Mon 20/01/2014   Suggested   Lesson 2
 Mon 27/01/2014   Suggested   Lesson 3
 Mon 03/02/2014   Suggested   Lesson 4
 Mon 10/02/2014   Suggested   Lesson 5
================ =========== ===================
""")

        # Now we want to skip the 2nd event.  We click on "Move next"
        # on this event. Lino then moves all subsequent events
        # accordingly.

        ar = cal.EntriesByController.request(
            master_instance=obj, known_values=dict(start_date=i2d(20140120)))
        e = ar.data_iterator[0]
        self.assertEqual(e.state, cal.EntryStates.suggested)
        #
        res = ses.run(e.move_next)

        self.assertEqual(res['success'], True)
        expected = """\
Move down for Activity #1 Lesson 2...
Generating events between 2014-01-13 and 2020-05-22 (max. 5).
Lesson 2 has been moved from 2014-01-20 to 2014-01-27.
1 row(s) have been updated."""
        self.assertEqual(res['info_message'], expected)

        # The event is now in state "draft" because it has been
        # modified by the user.

        self.assertEqual(e.state, cal.EntryStates.draft)
        # e.full_clean()
        # e.save()

        check_update(
            obj, """
Update Events for Activity #1...
Generating events between 2014-01-13 and 2020-05-22 (max. 5).
Lesson 2 has been moved from 2014-01-20 to 2014-01-27.
0 row(s) have been updated.
""", """
================ =========== ===================
 When             State       Short description
---------------- ----------- -------------------
 Mon 13/01/2014   Suggested   Lesson 1
 Mon 27/01/2014   Draft       Lesson 2
 Mon 03/02/2014   Suggested   Lesson 3
 Mon 10/02/2014   Suggested   Lesson 4
 Mon 17/02/2014   Suggested   Lesson 5
================ =========== ===================
""")

        # Now we imagine that February 3 is the National Day in our
        # country and that we create the rule for this only now.  So
        # we have a conflict because Lino created an appointment on
        # that date. Of course the National Day must *not* move to an
        # alternative date.

        et = create(cal.EventType, name="Holiday", all_rooms=True)
        national_day = create(cal.RecurrentEvent,
                              name="National Day",
                              event_type=et,
                              start_date=i2d(20140203),
                              every_unit=cal.Recurrencies.yearly)

        res = ses.run(national_day.do_update_events)
        self.assertEqual(res['success'], True)
        expected = """\
Update Events for National Day...
Generating events between 2014-02-03 and 2020-05-22 (max. 72).
Reached upper date limit 2020-05-22
Update presences for Recurring event #1 National Day : 0 created, 0 unchanged, 0 deleted.
Update presences for Recurring event #1 National Day : 0 created, 0 unchanged, 0 deleted.
Update presences for Recurring event #1 National Day : 0 created, 0 unchanged, 0 deleted.
Update presences for Recurring event #1 National Day : 0 created, 0 unchanged, 0 deleted.
Update presences for Recurring event #1 National Day : 0 created, 0 unchanged, 0 deleted.
Update presences for Recurring event #1 National Day : 0 created, 0 unchanged, 0 deleted.
Update presences for Recurring event #1 National Day : 0 created, 0 unchanged, 0 deleted.
7 row(s) have been updated."""
        self.assertEqual(res['info_message'], expected)
        ar = ses.spawn(cal.EntriesByController, master_instance=national_day)
        s = ar.to_rst(column_names="when_text state", nosummary=True)
        # print s
        self.assertEqual(
            s, """\
================ ===========
 When             State
---------------- -----------
 Mon 03/02/2014   Suggested
 Tue 03/02/2015   Suggested
 Wed 03/02/2016   Suggested
 Fri 03/02/2017   Suggested
 Sat 03/02/2018   Suggested
 Sun 03/02/2019   Suggested
 Mon 03/02/2020   Suggested
================ ===========

""")

        # the national day is now conflicting with our Lesson 3:
        ce = ar[0]
        self.assertEqual(ce.summary, "National Day")
        self.assertEqual(ce.start_date.year, 2014)
        ar = ses.spawn(cal.ConflictingEvents, master_instance=ce)
        s = ar.to_rst(column_names="when_text state auto_type")
        # print s
        self.assertEqual(
            s, """\
==================== =========== =======
 When                 State       No.
-------------------- ----------- -------
 Mon 03/02/2014       Suggested   3
 **Total (1 rows)**               **3**
==================== =========== =======

""")

        # delete all lessons and start again with a virgin series

        cal.Event.objects.filter(event_type=lesson).delete()

        check_update(
            obj, """
Update Events for Activity #1...
Generating events between 2014-01-13 and 2020-05-22 (max. 5).
Lesson 4 wants 2014-02-03 but conflicts with <QuerySet [Event #8 ('Recurring event #1 National Day')]>, moving to 2014-02-10. 
Update presences for Activity #1 Lesson 1 : 0 created, 0 unchanged, 0 deleted.
Update presences for Activity #1 Lesson 2 : 0 created, 0 unchanged, 0 deleted.
Update presences for Activity #1 Lesson 3 : 0 created, 0 unchanged, 0 deleted.
Update presences for Activity #1 Lesson 4 : 0 created, 0 unchanged, 0 deleted.
Update presences for Activity #1 Lesson 5 : 0 created, 0 unchanged, 0 deleted.
5 row(s) have been updated.
""", """
================ =========== ===================
 When             State       Short description
---------------- ----------- -------------------
 Mon 13/01/2014   Suggested   Lesson 1
 Mon 20/01/2014   Suggested   Lesson 2
 Mon 27/01/2014   Suggested   Lesson 3
 Mon 10/02/2014   Suggested   Lesson 4
 Mon 17/02/2014   Suggested   Lesson 5
================ =========== ===================
""")

        # we move the first lesson one week down and check whether
        # remaining entries get adapted. We manually set the state to
        # draft (this is automatically done when using the web ui).

        e = cal.Event.objects.get(event_type=lesson, auto_type=1)
        e.start_date = i2d(20140120)
        e.state = cal.EntryStates.draft
        e.full_clean()
        e.save()

        check_update(
            obj, """
Update Events for Activity #1...
Generating events between 2014-01-27 and 2020-05-22 (max. 5).
Lesson 3 wants 2014-02-03 but conflicts with <QuerySet [Event #8 ('Recurring event #1 National Day')]>, moving to 2014-02-10. 
0 row(s) have been updated.
        """, """
================ =========== ===================
 When             State       Short description
---------------- ----------- -------------------
 Mon 20/01/2014   Draft       Lesson 1
 Mon 27/01/2014   Suggested   Lesson 2
 Mon 10/02/2014   Suggested   Lesson 3
 Mon 17/02/2014   Suggested   Lesson 4
 Mon 24/02/2014   Suggested   Lesson 5
================ =========== ===================
""")

        # we cancel the third lesson and see whether Lino adds a

        e = cal.Event.objects.get(event_type=lesson, auto_type=3)
        e.state = cal.EntryStates.cancelled
        e.auto_type = None
        e.full_clean()
        e.save()
Пример #4
0
    def test01(self):
        from lino.core import constants
        from django.conf import settings
        from lino.modlib.users.choicelists import UserTypes
        from lino.api.shell import countries, avanti, users

        # is it the right settings module?
        self.assertEqual(os.environ['DJANGO_SETTINGS_MODULE'],
                         'lino_book.projects.avanti1.settings.demo')

        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.RemoteUserMiddleware',
             'lino.utils.ajax.AjaxExceptionResponse'))

        u = users.User(username='******',
                       user_type=UserTypes.admin,
                       language="en")
        u.save()
        self.client.force_login(u)
        be = countries.Country(name="Belgium", isocode="BE")
        be.save()

        Holder = dd.plugins.beid.holder_model
        kw = dict()
        # kw.update(card_number="123456789")
        # kw.update(national_id="680601 053-29")
        kw.update(first_name="Jean-Jacques")
        # kw.update(middle_name="")
        kw.update(last_name="Jeffin")
        obj = Holder(**kw)
        obj.full_clean()
        obj.save()

        def simulate_eidreader(uuid):
            # simulate the client's eidreader posting its data to the
            # server.
            s = readfile(uuid + '.json')
            # raise Exception(repr(s))
            data = dict(card_data=s)
            url = '/eid/' + uuid
            response = self.client.post(url,
                                        data,
                                        REMOTE_USER='******',
                                        HTTP_ACCEPT_LANGUAGE='en')
            result = self.check_json_result(response, 'success message')
            self.assertEqual(result, {'message': 'OK', 'success': True})

        # The following tests are based on an older simulation system developed
        # before simulate_eidreader_path was developed. TODO: convert them to
        # simulate_eidreader_path. En attendant we simply disable
        # simulate_eidreader_path here. Works as well.
        save_path = dd.plugins.beid.simulate_eidreader_path
        dd.plugins.beid.simulate_eidreader_path = None

        uuid = 'beid_test_1'
        simulate_eidreader(uuid)

        url = '/api/avanti/Clients'
        post_data = dict()
        # post_data.update(
        #     card_data=readfile('beid_test_1.json'))
        post_data['uuid'] = uuid
        post_data[constants.URL_PARAM_ACTION_NAME] = 'find_by_beid'

        # First attempt fails because a person with exactly the same
        # name already exists.
        response = self.client.post(url,
                                    post_data,
                                    REMOTE_USER='******',
                                    HTTP_ACCEPT_LANGUAGE='en')

        # result = self.check_json_result(response, 'alert success message')
        result = self.check_json_result(response)
        # raise Exception(repr(result))
        self.assertEqual(result['success'], False)
        expected = ("Sorry, I cannot handle that case: Cannot create "
                    "new client because there is already a person named "
                    "Jean-Jacques Jeffin in our database.")
        self.assertEqual(result['message'], expected)

        # Second attempt. We are reading the same card, but this time
        # there is a person with this `national_id`.
        obj.national_id = "680601 053-29"
        # obj.first_name = "Jean-Claude"
        obj.full_clean()
        obj.save()

        dlg = []
        expected = """\
Click OK to apply the following changes for JEFFIN Jean-Jacques (100) :\
<br/>Birth date : '' -> 1968-06-01
<br/>Birth place : '' -> 'Mons'
<br/>Country : None -> Country #BE ('Belgium')
<br/>Gender : None -> <system.Genders.male:M>
<br/>ID card valid from : None -> 2016-02-06
<br/>Locality : None -> Place #1 ('Helsinki')
<br/>Nationality (text) : '' -> 'Belgier'
<br/>Street : '' -> 'Estland'
<br/>Zip code : '' -> '1262'
<br/>eID card issuer : '' -> 'Helsinki'
<br/>eID card number : '' -> '592382784772'
<br/>eID card type : None -> <beid.BeIdCardTypes.belgian_citizen:01>
<br/>until : None -> 2026-02-06"""

        # Click OK to apply the following changes for JEFFIN Jean (100) :\
        # <br/>Locality : None -> Place #1 ('Tallinn')
        # <br/>Gender : None -> <Genders.male:M>
        # <br/>until : None -> 2016-08-19
        # <br/>Street : '' -> 'Estland'
        # <br/>ID card valid from : None -> 2011-08-19
        # <br/>eID card type : None -> <BeIdCardTypes.belgian_citizen:1>
        # <br/>eID card issuer : '' -> 'Tallinn'
        # <br/>Birth place : '' -> 'Mons'
        # <br/>Country : None -> Country #BE ('Belgium')
        # <br/>Birth date : '' -> 1968-06-01
        # <br/>eID card number : '' -> '592345678901'
        # <br/>Zip code : '' -> '1418'

        dlg.append((expected, 'yes'))
        dlg.append(
            ('Client "JEFFIN Jean-Jacques (100)" has been saved.', None))
        self.check_callback_dialog(self.client.post, 'robin', url, dlg,
                                   post_data)

        obj = avanti.Client.objects.get(id=100)
        # addr = addresses.Address.objects.get(partner=obj)
        self.assertEqual(obj.city.name, "Helsinki")
        # self.assertEqual(addr.primary, True)

        # Third attempt. A person with almost same name and same
        # national_id.

        obj.national_id = "680601 053-29"
        obj.first_name = "Jean"
        obj.middle_name = "Jacques"
        obj.full_clean()
        obj.save()
        self.assertEqual(obj.national_id, "680601 053-29")
        response = self.client.post(url,
                                    post_data,
                                    REMOTE_USER='******',
                                    HTTP_ACCEPT_LANGUAGE='en')
        result = self.check_json_result(response, 'xcallback success message')
        self.assertEqual(result['success'], True)
        expected = """\
Click OK to apply the following changes for JEFFIN Jean-Jacques (100) :<br/>First name : 'Jean' -> 'Jean-Jacques'
<br/>Middle name : 'Jacques' -> ''"""
        # print(result['message'])
        self.assertEqual(result['message'], expected)

        # Fourth attempt. A person with slightly different name and
        # equivalent but wrongly formatted national_id exists.  Lino
        # does not recognize this duplicate here. To avoid this case,
        # the StrangeClients table warns about wrongly formatted
        # national_id fields.

        Holder.validate_national_id = False

        ssin.parse_ssin('68060105329')
        obj.national_id = "68060105329"
        obj.first_name = "Jean Jacques"
        obj.middle_name = ""
        # obj.client_state = ClientStates.coached
        # obj.update_dupable_words()  # avoid repairable message
        obj.full_clean()
        obj.save()
        self.assertEqual(obj.national_id, "68060105329")
        response = self.client.post(url,
                                    post_data,
                                    REMOTE_USER='******',
                                    HTTP_ACCEPT_LANGUAGE='en')
        # self.assertEqual(response.content, '')
        result = self.check_json_result(response, 'xcallback success message')
        self.assertEqual(result['success'], True)
        expected = "Create new client Jean-Jacques Jeffin : Are you sure?"
        # print(result['message'])
        self.assertEqual(result['message'], expected)

        # test whether we would have been warned:
        obj.update_dupable_words()  # avoid repairable message
        ar = rt.models.checkdata.ProblemsByOwner.request(master_instance=obj)
        obj.check_data(fix=False)
        s = ar.to_rst()
        # print(s)
        self.assertEqual(
            s, """\
*(★) Malformed SSIN '68060105329' must be '680601 053-29'.*
""")

        obj.check_data(fix=True)
        ar = rt.models.checkdata.ProblemsByOwner.request(master_instance=obj)
        s = ar.to_rst()
        # print(s)
        self.assertEqual(s, "\n")

        # Last attempt for this card. No similar person exists. Create
        # new client from eid.

        obj.first_name = "Jean-Claude"
        obj.national_id = ""
        obj.full_clean()
        obj.save()
        response = self.client.post(url,
                                    post_data,
                                    REMOTE_USER='******',
                                    HTTP_ACCEPT_LANGUAGE='en')
        # self.assertEqual(response.content, '')
        result = self.check_json_result(response, 'xcallback success message')
        self.assertEqual(result['success'], True)
        expected = "Create new client Jean-Jacques Jeffin : Are you sure?"
        self.assertEqual(result['message'], expected)

        dd.plugins.beid.eidreader_timeout = 1

        # when eidreader is not installed on client, there will be no
        # incoming POST and therefore we will have a timeout.
        post_data['uuid'] = 'foo'  #
        response = self.client.post(url,
                                    post_data,
                                    REMOTE_USER='******',
                                    HTTP_ACCEPT_LANGUAGE='en')
        # self.assertEqual(response.content, '')
        result = self.check_json_result(response, 'alert success message')
        self.assertEqual(result['success'], False)
        self.assertEqual(result['message'], "Abandoned after 1 seconds")

        dd.plugins.beid.eidreader_timeout = 15

        uuid = 'beid_test_0'
        simulate_eidreader(uuid)

        post_data['uuid'] = uuid
        response = self.client.post(url,
                                    post_data,
                                    REMOTE_USER='******',
                                    HTTP_ACCEPT_LANGUAGE='en')
        # self.assertEqual(response.content, '')
        result = self.check_json_result(response, 'alert success message')
        self.assertEqual(result['success'], False)
        self.assertEqual(
            result['message'],
            "No card data found: Could not find any reader with a card inserted"
        )

        if True:
            # skip the following tests because we don't yet have
            # test data for the Python eidreader.
            return

        # next card. a foreigner card with incomplete birth date

        post_data.update(card_data=readfile('beid_tests_2.txt'))
        response = self.client.post(url,
                                    post_data,
                                    REMOTE_USER='******',
                                    HTTP_ACCEPT_LANGUAGE='en')
        # self.assertEqual(response.content, '')
        result = self.check_json_result(response, 'xcallback success message')
        self.assertEqual(result['success'], True)
        expected = "Create new client Marc Petitjean : Are you sure?"
        self.assertEqual(result['message'], expected)

        # next card. issued after 2015 and the photo is invalid

        post_data.update(card_data=readfile('beid_tests_3.txt'))
        response = self.client.post(url,
                                    post_data,
                                    REMOTE_USER='******',
                                    HTTP_ACCEPT_LANGUAGE='en')
        # self.assertEqual(response.content, '')
        result = self.check_json_result(response, 'xcallback success message')
        self.assertEqual(result['success'], True)
        expected = "Create new client Bernd Brecht : Are you sure?"
        self.assertEqual(result['message'], expected)

        # next card. issued after 2015 and the photo is valid

        post_data.update(card_data=readfile('beid_tests_4.txt'))
        response = self.client.post(url,
                                    post_data,
                                    REMOTE_USER='******',
                                    HTTP_ACCEPT_LANGUAGE='en')
        # self.assertEqual(response.content, '')
        result = self.check_json_result(response, 'xcallback success message')
        self.assertEqual(result['success'], True)
        expected = "Create new client Jean Dupont : Are you sure?"
        self.assertEqual(result['message'], expected)

        dd.plugins.beid.simulate_eidreader_path = save_path
Пример #5
0
    def test01(self):
        # print("20180502 test_debts.test01()")

        # Member = rt.models.households.Member
        Household = rt.models.households.Household
        Person = rt.models.contacts.Person
        Genders = rt.models.system.Genders
        Budget = rt.models.debts.Budget
        Actor = rt.models.debts.Actor
        Entry = rt.models.debts.Entry
        
        def check_count(b, a, e):
            self.assertEqual(Budget.objects.count(), b)
            self.assertEqual(Actor.objects.count(), a)
            self.assertEqual(Entry.objects.count(), e)
        
        

        u = users.User(username='******',
                       user_type=UserTypes.admin,
                       language="en")
        u.save()
        # be = countries.Country(name="Belgium", isocode="BE")
        # be.save()
        # kw = dict()
        # # kw.update(card_number="123456789")
        # # kw.update(national_id="680601 053-29")
        # kw.update(id=116)
        # kw.update(first_name="Jean")
        # kw.update(middle_name="Jacques")
        # kw.update(last_name="Jeffin")
        # obj = pcsw.Client(**kw)
        # obj.full_clean()
        # obj.save()

        from lino_welfare.modlib.debts.fixtures.minimal import objects
        for o in objects():
            o.save()
        # from lino_xl.lib.households.fixtures.std import objects
        # for o in objects():
        #     o.save()

        # Reproduce ticket #521
        ar = rt.login('root')
        
        p1 = Person(first_name="A", last_name="A", gender=Genders.male)
        p1.save()
        p2 = Person(first_name="B", last_name="B", gender=Genders.female)
        p2.save()
        h = Household.create_household(ar, p1, p2, None)

        # The household has for whatever reason an empty member
        # entry. Lino should ignore this entry.
        h.add_member(None)

        check_count(0, 0, 0)
        
        b = Budget(partner=h, user=u)
        b.save()
        b.fill_defaults()
        # from django.utils.encoding import force_text
        # s = ' & '.join([force_text(a) for a in b.get_actors()])
        # s = '{0} & {1}'.format(*b.get_actors())
        # self.assertEqual(s, "Mr. & Mrs.")

        ##
        ## Reproduce ticket #159 ('NoneType' object is not iterable
        ## (after duplicating a budget)) and verify ticket #471
        ## (Become the author after duplicating a budget).
        ##
        
        self.assertEqual(b.user.username, 'root')
        self.assertEqual(b.id, 1)

        ou = users.User(username='******',
                        user_type=UserTypes.admin,
                        language="en")
        ou.save()
        ar = rt.login('other')

        check_count(1, 2, 44)
        
        new = b.duplicate.run_from_code(ar)
        self.assertEqual(new.user.username, 'other')
        self.assertEqual(new.id, 2)
        
        check_count(2, 4, 88)
        new = Budget.objects.get(pk=2)
        self.assertEqual(new.user.username, 'other')
       
        url = "/api/debts/Budgets/1?&an=duplicate&sr=1"
        dlg = []
        dlg.append((
            "This will create a copy of Budget 1 for A & B A-B Are you sure?",
            'yes'))
        dlg.append((
            'Duplicated Budget 1 for A & B A-B to Budget 3 for A & B A-B.',
            None))
        self.check_callback_dialog(self.client.get, 'other', url, dlg)

        check_count(3, 6, 132)

        new = Budget.objects.get(pk=3)
        self.assertEqual(new.user.username, 'other')