Projet

Général

Profil

0001-agendas-add-user_external_id-field-on-Booking-40719.patch

Lauréline Guérin, 12 mai 2020 17:06

Télécharger (5,08 ko)

Voir les différences:

Subject: [PATCH 1/2] agendas: add user_external_id field on Booking (#40719)

 .../migrations/0043_booking_user_external_id.py | 17 +++++++++++++++++
 chrono/agendas/models.py                        | 16 ++++++----------
 chrono/api/views.py                             |  2 ++
 tests/test_api.py                               | 11 ++++++++---
 4 files changed, 33 insertions(+), 13 deletions(-)
 create mode 100644 chrono/agendas/migrations/0043_booking_user_external_id.py
chrono/agendas/migrations/0043_booking_user_external_id.py
1
# -*- coding: utf-8 -*-
2
from __future__ import unicode_literals
3

  
4
from django.db import migrations, models
5

  
6

  
7
class Migration(migrations.Migration):
8

  
9
    dependencies = [
10
        ('agendas', '0042_auto_20200503_1231'),
11
    ]
12

  
13
    operations = [
14
        migrations.AddField(
15
            model_name='booking', name='user_external_id', field=models.CharField(blank=True, max_length=250),
16
        ),
17
    ]
chrono/agendas/models.py
15 15
# You should have received a copy of the GNU Affero General Public License
16 16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17

  
18
import copy
18 19
import datetime
19 20
import math
20 21
import requests
......
660 661
    user_display_label = models.CharField(
661 662
        verbose_name=_('Label displayed to user'), max_length=250, blank=True
662 663
    )
664
    user_external_id = models.CharField(max_length=250, blank=True)
663 665
    user_name = models.CharField(max_length=250, blank=True)
664 666
    backoffice_url = models.URLField(blank=True)
665 667

  
......
717 719
        return ics.serialize()
718 720

  
719 721
    def clone(self, in_waiting_list=False, primary_booking=None, save=True):
720
        new_booking = Booking(
721
            primary_booking=primary_booking,
722
            event_id=self.event_id,
723
            in_waiting_list=in_waiting_list,
724
            label=self.label,
725
            user_name=self.user_name,
726
            backoffice_url=self.backoffice_url,
727
            user_display_label=self.user_display_label,
728
            extra_data=self.extra_data,
729
        )
722
        new_booking = copy.deepcopy(self)
723
        new_booking.id = None
724
        new_booking.in_waiting_list = in_waiting_list
725
        new_booking.primary_booking = primary_booking
730 726
        if save:
731 727
            new_booking.save()
732 728
        return new_booking
chrono/api/views.py
438 438
    '''
439 439

  
440 440
    label = serializers.CharField(max_length=250, allow_blank=True)
441
    user_external_id = serializers.CharField(max_length=250, allow_blank=True)
441 442
    user_name = serializers.CharField(max_length=250, allow_blank=True)
442 443
    user_display_label = serializers.CharField(max_length=250, allow_blank=True)
443 444
    backoffice_url = serializers.URLField(allow_blank=True)
......
741 742
                        event_id=event.id,
742 743
                        in_waiting_list=in_waiting_list,
743 744
                        label=payload.get('label', ''),
745
                        user_external_id=payload.get('user_external_id', ''),
744 746
                        user_name=payload.get('user_name', ''),
745 747
                        backoffice_url=payload.get('backoffice_url', ''),
746 748
                        user_display_label=payload.get('user_display_label', ''),
tests/test_api.py
675 675
        params={
676 676
            'slots': events_ids,
677 677
            'label': 'foo',
678
            'user_external_id': 'some_external_id',
678 679
            'user_name': 'bar',
680
            'user_display_label': 'foo',
679 681
            'backoffice_url': 'http://example.net/',
680 682
        },
681 683
    )
682 684
    booking_id = resp.json['booking_id']
683
    assert Booking.objects.get(id=booking_id).label == 'foo'
684
    assert Booking.objects.get(id=booking_id).user_name == 'bar'
685
    assert Booking.objects.get(id=booking_id).backoffice_url == 'http://example.net/'
685
    booking = Booking.objects.get(pk=booking_id)
686
    assert booking.label == 'foo'
687
    assert booking.user_external_id == 'some_external_id'
688
    assert booking.user_name == 'bar'
689
    assert booking.user_display_label == 'foo'
690
    assert booking.backoffice_url == 'http://example.net/'
686 691
    assert Booking.objects.filter(primary_booking=booking_id, label='foo').count() == 2
687 692
    # cancel
688 693
    cancel_url = resp.json['api']['cancel_url']
689
-