make tests insensible to postgres/sqlite (#39583)
This commit is contained in:
parent
769f77c4c8
commit
65b1286d5e
|
@ -963,7 +963,7 @@ class TimePeriodExceptionDeleteView(ManagedDeskSubobjectMixin, DeleteView):
|
|||
|
||||
def get_success_url(self):
|
||||
referer = self.request.META.get('HTTP_REFERER')
|
||||
success_url = reverse('chrono-manager-time-period-exception-list', kwargs={'pk': self.desk.agenda_id})
|
||||
success_url = reverse('chrono-manager-time-period-exception-list', kwargs={'pk': self.desk.pk})
|
||||
if success_url in referer:
|
||||
return success_url
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ def some_data(time_zone, mock_now):
|
|||
event = Event(start_datetime=first_date + datetime.timedelta(days=i), places=20, agenda=agenda)
|
||||
event.save()
|
||||
|
||||
agenda2 = Agenda(label=u'Foo bar2')
|
||||
agenda2 = Agenda(label=u'Foo bar 2')
|
||||
agenda2.save()
|
||||
first_date = localtime(now()).replace(hour=20, minute=0, second=0, microsecond=0)
|
||||
first_date += datetime.timedelta(days=1)
|
||||
|
@ -111,7 +111,7 @@ def meetings_agenda(time_zone, mock_now):
|
|||
|
||||
def test_agendas_api(app, some_data, meetings_agenda):
|
||||
agenda1 = Agenda.objects.filter(label=u'Foo bar')[0]
|
||||
agenda2 = Agenda.objects.filter(label=u'Foo bar2')[0]
|
||||
agenda2 = Agenda.objects.filter(label=u'Foo bar 2')[0]
|
||||
resp = app.get('/api/agenda/')
|
||||
assert resp.json == {
|
||||
'data': [
|
||||
|
@ -127,6 +127,18 @@ def test_agendas_api(app, some_data, meetings_agenda):
|
|||
'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % agenda1.slug,
|
||||
},
|
||||
},
|
||||
{
|
||||
'text': 'Foo bar 2',
|
||||
'id': u'foo-bar-2',
|
||||
'kind': 'events',
|
||||
'slug': 'foo-bar-2',
|
||||
'minimal_booking_delay': 1,
|
||||
'maximal_booking_delay': 56,
|
||||
'api': {
|
||||
'datetimes_url': 'http://testserver/api/agenda/%s/datetimes/' % agenda2.slug,
|
||||
'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % agenda2.slug,
|
||||
},
|
||||
},
|
||||
{
|
||||
'text': 'Foo bar Meeting',
|
||||
'id': u'foo-bar-meeting',
|
||||
|
@ -140,18 +152,6 @@ def test_agendas_api(app, some_data, meetings_agenda):
|
|||
'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % meetings_agenda.slug,
|
||||
},
|
||||
},
|
||||
{
|
||||
'text': 'Foo bar2',
|
||||
'id': u'foo-bar2',
|
||||
'kind': 'events',
|
||||
'slug': 'foo-bar2',
|
||||
'minimal_booking_delay': 1,
|
||||
'maximal_booking_delay': 56,
|
||||
'api': {
|
||||
'datetimes_url': 'http://testserver/api/agenda/%s/datetimes/' % agenda2.slug,
|
||||
'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % agenda2.slug,
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -257,7 +257,7 @@ def test_datetime_api_fr(app, some_data):
|
|||
|
||||
|
||||
def test_datetime_api_label(app, some_data):
|
||||
agenda_id = Agenda.objects.filter(label=u'Foo bar2')[0].id
|
||||
agenda_id = Agenda.objects.filter(label=u'Foo bar 2')[0].id
|
||||
event = Event.objects.filter(agenda=agenda_id)[0]
|
||||
event.label = 'Hello world'
|
||||
event.save()
|
||||
|
@ -266,7 +266,7 @@ def test_datetime_api_label(app, some_data):
|
|||
|
||||
|
||||
def test_datetime_api_status_url(app, some_data):
|
||||
agenda = Agenda.objects.get(label=u'Foo bar2')
|
||||
agenda = Agenda.objects.get(label=u'Foo bar 2')
|
||||
resp = app.get('/api/agenda/%s/datetimes/' % agenda.slug)
|
||||
for datum in resp.json['data']:
|
||||
assert urlparse.urlparse(datum['api']['status_url']).path == '/api/agenda/%s/status/%s/' % (
|
||||
|
@ -468,7 +468,7 @@ def test_booking_api(app, some_data, user):
|
|||
|
||||
resp = app.post('/api/agenda/foobar/fillslot/%s/' % event.id, status=404)
|
||||
|
||||
resp = app.post('/api/agenda/233/fillslot/%s/' % event.id, status=404)
|
||||
resp = app.post('/api/agenda/0/fillslot/%s/' % event.id, status=404)
|
||||
|
||||
|
||||
def test_booking_ics(app, some_data, meetings_agenda, user):
|
||||
|
@ -614,7 +614,7 @@ def test_booking_api_fillslots(app, some_data, user):
|
|||
assert urlparse.urlparse(resp.json['api']['cancel_url']).netloc
|
||||
assert Booking.objects.count() == 3
|
||||
# these 3 bookings are related, the first is the primary one
|
||||
bookings = Booking.objects.all().order_by('primary_booking')
|
||||
bookings = Booking.objects.all().order_by('pk')
|
||||
assert bookings[0].primary_booking is None
|
||||
assert bookings[1].primary_booking.id == bookings[0].id == primary_booking_id
|
||||
assert bookings[2].primary_booking.id == bookings[0].id == primary_booking_id
|
||||
|
@ -698,7 +698,7 @@ def test_booking_api_fillslots(app, some_data, user):
|
|||
|
||||
# unknown agendas
|
||||
resp = app.post('/api/agenda/foobar/fillslots/', status=404)
|
||||
resp = app.post('/api/agenda/233/fillslots/', status=404)
|
||||
resp = app.post('/api/agenda/0/fillslots/', status=404)
|
||||
|
||||
|
||||
def test_booking_api_fillslots_slots_string_param(app, some_data, user):
|
||||
|
@ -1144,7 +1144,7 @@ def test_booking_cancellation_post_api(app, some_data, user):
|
|||
assert Booking.objects.filter(cancellation_datetime__isnull=False).count() == 1
|
||||
|
||||
# cancel an object that doesn't exist
|
||||
resp = app.post('/api/booking/%s/cancel/' % 9999, status=404)
|
||||
resp = app.post('/api/booking/%s/cancel/' % 0, status=404)
|
||||
|
||||
# cancel an event that was already cancelled
|
||||
resp = app.post('/api/booking/%s/cancel/' % booking_id, status=200)
|
||||
|
@ -1208,7 +1208,7 @@ def test_status(app, some_data, user):
|
|||
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, event.id), status=401)
|
||||
|
||||
app.authorization = ('Basic', ('john.doe', 'password'))
|
||||
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, 9999), status=404)
|
||||
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, 0), status=404)
|
||||
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, 'xx'), status=404)
|
||||
|
||||
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, event.id))
|
||||
|
@ -1324,7 +1324,7 @@ def test_accept_booking(app, some_data, user):
|
|||
assert Booking.objects.filter(in_waiting_list=False).count() == 1
|
||||
|
||||
# accept a booking that doesn't exist
|
||||
resp = app.post('/api/booking/%s/accept/' % 9999, status=404)
|
||||
resp = app.post('/api/booking/%s/accept/' % 0, status=404)
|
||||
|
||||
# accept a booking that was not in the waiting list
|
||||
resp = app.post('/api/booking/%s/accept/' % booking.id, status=200)
|
||||
|
@ -1636,7 +1636,7 @@ def test_agenda_detail_api(app, some_data):
|
|||
|
||||
def test_agenda_api_date_range(app, some_data):
|
||||
# test range limitation
|
||||
agenda2 = Agenda.objects.get(slug='foo-bar2')
|
||||
agenda2 = Agenda.objects.get(slug='foo-bar-2')
|
||||
base_date = agenda2.event_set.last().start_datetime.date()
|
||||
base_date = base_date + datetime.timedelta(days=1)
|
||||
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
import datetime
|
||||
import pytest
|
||||
|
||||
import django
|
||||
from django.db import connection
|
||||
from django.db.migrations.executor import MigrationExecutor
|
||||
from django.utils.timezone import make_aware
|
||||
|
||||
from chrono.agendas.models import MeetingType
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
def test_meeting_type_slug_migration():
|
||||
if connection.vendor == 'sqlite' and django.VERSION > (1, 11, 0):
|
||||
pytest.skip('SQLite schema editor cannot be used while foreign key constraint checks are enabled.')
|
||||
return
|
||||
executor = MigrationExecutor(connection)
|
||||
migrate_from = [('agendas', '0011_meetingtype_slug')]
|
||||
migrate_to = [('agendas', '0013_auto_20161028_1603')]
|
||||
executor.migrate(migrate_from)
|
||||
executor.loader.build_graph()
|
||||
|
||||
old_apps = executor.loader.project_state(migrate_from).apps
|
||||
OldAgenda = old_apps.get_model('agendas', 'Agenda')
|
||||
OldMeetingType = old_apps.get_model('agendas', 'MeetingType')
|
||||
|
||||
agenda = OldAgenda(label=u'Foo bar')
|
||||
agenda.save()
|
||||
|
||||
meeting_type = OldMeetingType(agenda=agenda, label=u'Baz')
|
||||
meeting_type.save()
|
||||
|
||||
executor.migrate(migrate_to)
|
||||
|
||||
assert MeetingType.objects.get(id=meeting_type.id).slug == 'baz'
|
||||
|
||||
|
||||
def test_timeperiod_data_migrations():
|
||||
if connection.vendor == 'sqlite' and django.VERSION > (1, 11, 0):
|
||||
pytest.skip('SQLite schema editor cannot be used while foreign key constraint checks are enabled.')
|
||||
return
|
||||
executor = MigrationExecutor(connection)
|
||||
app = 'agendas'
|
||||
migrate_from = [(app, '0016_desk')]
|
||||
migrate_to = [(app, '0018_event_desk')]
|
||||
executor.migrate(migrate_from)
|
||||
old_apps = executor.loader.project_state(migrate_from).apps
|
||||
Agenda = old_apps.get_model(app, 'Agenda')
|
||||
MeetingType = old_apps.get_model(app, 'MeetingType')
|
||||
TimePeriod = old_apps.get_model(app, 'TimePeriod')
|
||||
Event = old_apps.get_model(app, 'Event')
|
||||
agenda = Agenda.objects.create(label='foo', slug='foo', kind='meetings')
|
||||
agenda2 = Agenda.objects.create(label='bar', slug='bar', kind='events')
|
||||
TimePeriod.objects.create(
|
||||
agenda=agenda, weekday=1, start_time=datetime.time(8, 0), end_time=datetime.time(12, 0)
|
||||
)
|
||||
TimePeriod.objects.create(
|
||||
agenda=agenda, weekday=2, start_time=datetime.time(8, 0), end_time=datetime.time(10, 0)
|
||||
)
|
||||
TimePeriod.objects.create(
|
||||
agenda=agenda, weekday=3, start_time=datetime.time(9, 0), end_time=datetime.time(12, 0)
|
||||
)
|
||||
meeting_type = MeetingType.objects.create(agenda=agenda, label='foo', slug='foo', duration=60)
|
||||
Event.objects.create(
|
||||
agenda=agenda,
|
||||
places=1,
|
||||
meeting_type=meeting_type,
|
||||
start_datetime=make_aware(datetime.datetime(2017, 5, 22, 9, 30)),
|
||||
)
|
||||
Event.objects.create(
|
||||
agenda=agenda,
|
||||
places=1,
|
||||
meeting_type=meeting_type,
|
||||
start_datetime=make_aware(datetime.datetime(2017, 5, 22, 10, 0)),
|
||||
)
|
||||
Event.objects.create(
|
||||
agenda=agenda2, places=5, start_datetime=make_aware(datetime.datetime(2017, 5, 22, 10, 0))
|
||||
)
|
||||
executor.loader.build_graph()
|
||||
executor.migrate(migrate_to)
|
||||
new_apps = executor.loader.project_state(migrate_to).apps
|
||||
Agenda = new_apps.get_model(app, 'Agenda')
|
||||
agenda = Agenda.objects.get(slug='foo')
|
||||
TimePeriod = new_apps.get_model(app, 'TimePeriod')
|
||||
for time_period in TimePeriod.objects.all():
|
||||
assert time_period.desk.label == 'Guichet 1'
|
||||
assert time_period.desk.slug == 'guichet-1'
|
||||
|
||||
Event = new_apps.get_model(app, 'Event')
|
||||
for event in Event.objects.filter(agenda=agenda):
|
||||
assert event.desk.label == 'Guichet 1'
|
||||
assert event.desk.slug == 'guichet-1'
|
|
@ -91,6 +91,7 @@ def test_import_export(app, some_data, meetings_agenda):
|
|||
|
||||
event = Event(agenda=agenda1, start_datetime=make_aware(datetime.datetime.now()), places=10)
|
||||
event.save()
|
||||
desk, _ = Desk.objects.get_or_create(agenda=agenda2, label='Desk A', slug='desk-a')
|
||||
timeperiod = TimePeriod(
|
||||
weekday=2, desk=desk, start_time=datetime.time(10, 0), end_time=datetime.time(11, 0)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue