Projet

Général

Profil

0002-make-tests-insensible-to-postgres-sqlite-39583.patch

Emmanuel Cazenave, 06 février 2020 15:22

Télécharger (4,44 ko)

Voir les différences:

Subject: [PATCH 2/2] make tests insensible to postgres/sqlite (#39583)

 tests/test_api.py | 62 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 43 insertions(+), 19 deletions(-)
tests/test_api.py
109 109
    return agenda
110 110

  
111 111

  
112
def test_agendas_api(app, some_data, meetings_agenda):
112
def test_agendas_api(app, meetings_agenda):
113
    agenda = Agenda(label=u'Foo bar')
114
    agenda.save()
115
    first_date = localtime(now()).replace(hour=17, minute=0, second=0, microsecond=0)
116
    first_date += datetime.timedelta(days=1)
117
    for i in range(3):
118
        event = Event(start_datetime=first_date + datetime.timedelta(days=i), places=20, agenda=agenda)
119
        event.save()
120

  
121
    agenda2 = Agenda(label=u'Foo bar Again')
122
    agenda2.save()
123
    first_date = localtime(now()).replace(hour=20, minute=0, second=0, microsecond=0)
124
    first_date += datetime.timedelta(days=1)
125
    for i in range(2):
126
        event = Event(start_datetime=first_date + datetime.timedelta(days=i), places=20, agenda=agenda2)
127
        event.save()
128

  
129
    # a date in the past
130
    event = Event(start_datetime=first_date - datetime.timedelta(days=10), places=10, agenda=agenda)
131
    event.save()
132

  
113 133
    agenda1 = Agenda.objects.filter(label=u'Foo bar')[0]
114
    agenda2 = Agenda.objects.filter(label=u'Foo bar2')[0]
134
    agenda2 = Agenda.objects.filter(label=u'Foo bar Again')[0]
115 135
    resp = app.get('/api/agenda/')
116 136
    assert resp.json == {
117 137
        'data': [
......
127 147
                    'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % agenda1.slug,
128 148
                },
129 149
            },
150
            {
151
                'text': 'Foo bar Again',
152
                'id': u'foo-bar-again',
153
                'kind': 'events',
154
                'slug': 'foo-bar-again',
155
                'minimal_booking_delay': 1,
156
                'maximal_booking_delay': 56,
157
                'api': {
158
                    'datetimes_url': 'http://testserver/api/agenda/%s/datetimes/' % agenda2.slug,
159
                    'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % agenda2.slug,
160
                },
161
            },
130 162
            {
131 163
                'text': 'Foo bar Meeting',
132 164
                'id': u'foo-bar-meeting',
......
140 172
                    'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % meetings_agenda.slug,
141 173
                },
142 174
            },
143
            {
144
                'text': 'Foo bar2',
145
                'id': u'foo-bar2',
146
                'kind': 'events',
147
                'slug': 'foo-bar2',
148
                'minimal_booking_delay': 1,
149
                'maximal_booking_delay': 56,
150
                'api': {
151
                    'datetimes_url': 'http://testserver/api/agenda/%s/datetimes/' % agenda2.slug,
152
                    'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % agenda2.slug,
153
                },
154
            },
155 175
        ]
156 176
    }
157 177

  
......
609 629
    assert 'cancel_url' in resp.json['api']
610 630
    assert urlparse.urlparse(resp.json['api']['cancel_url']).netloc
611 631
    assert Booking.objects.count() == 3
612
    # these 3 bookings are related, the first is the primary one
613
    bookings = Booking.objects.all().order_by('primary_booking')
614
    assert bookings[0].primary_booking is None
615
    assert bookings[1].primary_booking.id == bookings[0].id == primary_booking_id
616
    assert bookings[2].primary_booking.id == bookings[0].id == primary_booking_id
632

  
633
    # there must be one primary booking
634
    primary_booking = Booking.objects.filter(primary_booking__isnull=True).get()
635

  
636
    # these 2 bookings are related to the primary booking
637
    secondary_bookings = Booking.objects.exclude(primary_booking__isnull=True).all()
638
    assert len(secondary_bookings) == 2
639
    assert secondary_bookings[0].primary_booking.id == primary_booking.id
640
    assert secondary_bookings[1].primary_booking.id == primary_booking.id
617 641

  
618 642
    # access by slug
619 643
    resp = app.post('/api/agenda/%s/fillslots/' % agenda.slug, params={'slots': events_slugs})
620
-