def test_update_published_event(admin_client): group = factories.GroupFactory() start_date = make_aware(dt.datetime(2030, 1, 1, 10)) duration = 120 end_date = start_date + dt.timedelta(minutes=duration) data = {'description': 'descrición evento test', 'group': group, 'start': start_date, 'duration': duration, 'end': end_date, 'google_calendar_published': True, 'google_event_id': 102, 'google_event_htmllink': 'http://test.local', 'status': 'published'} event = factories.EventFactory(**data) assert event.status == 'published' new_start_date = make_aware(dt.datetime(2030, 1, 1, 11)) data = {'start': new_start_date, 'duration': duration} response = admin_client.patch(f'/api/events/{event.id}/', data, content_type='application/json') assert response.status_code == 200 assert response.json()['google_calendar_published'] is True assert response.json()['start'] == \ new_start_date.strftime('%Y-%m-%dT%H:%M:%SZ')
def test_create_event_with_required_fields(admin_client): group = factories.GroupFactory() data = {'description': 'descrición evento test', 'group': group.id} response = admin_client.post('/api/events/', data) assert response.status_code == 201
def test_create_draft_event(admin_client): group = factories.GroupFactory() data = {'description': 'descrición evento test', 'group': group.id} response = admin_client.post('/api/events/', data) assert response.status_code == 201 assert response.json()['status'] == 'draft'
def test_prevent_create_event_with_only_start_date(admin_client): group = factories.GroupFactory() start_date = make_aware(dt.datetime(2019, 1, 1, 10)) data = {'group': group.id, 'description': 'descrición evento test', 'start': start_date} response = admin_client.post('/api/events/', data) assert response.status_code == 400 assert response.json()['non_field_errors'] == [ _('If you enter start date you must enter the duration')]
def test_prevent_publish_gcal_event_without_duration(admin_client): group = factories.GroupFactory() data = {'description': 'descrición evento test', 'group': group.id, 'end': dt.datetime.now(), 'google_calendar_published': True} response = admin_client.post('/api/events/', data) assert response.status_code == 400 assert response.json()['non_field_errors'] == [ _('To publish in Google Calendar you must enter start ' 'time and duration')]
def test_create_published_event(admin_client): group = factories.GroupFactory() start_date = make_aware(dt.datetime(2030, 1, 1, 10)) data = {'description': 'descrición evento test', 'group': group.id, 'start': start_date, 'duration': 2, 'google_calendar_published': True} response = admin_client.post('/api/events/', data) assert response.status_code == 201 assert response.json()['status'] == 'published' assert response.json()['google_event_id'] == '101'
def test_remove_published_event(admin_client): group = factories.GroupFactory() start_date = make_aware(dt.datetime(2030, 1, 1, 10)) data = {'description': 'descrición evento test', 'group': group, 'start': start_date, 'duration': 2, 'google_calendar_published': True, 'google_event_id': 102, 'google_event_htmllink': 'http://test.local', 'status': 'published'} event = factories.EventFactory(**data) response = admin_client.get(f'/api/events/{event.id}/') assert response.json()['status'] == 'published' assert response.json()['google_calendar_published'] is True data = {'google_calendar_published': False} response = admin_client.patch(f'/api/events/{event.id}/', data, content_type='application/json') assert response.status_code == 200 assert response.json()['google_calendar_published'] is False assert response.json()['status'] == 'draft' assert response.json()['google_event_id'] is None assert response.json()['google_event_htmllink'] is None
def test_prevent_create_event_without_description(admin_client): group = factories.GroupFactory() data = {'group': group.id} response = admin_client.post('/api/events/', data) assert response.status_code == 400