# Path: fossevents/events/services.py
# def get_event_review_url(event):
#     return reverse('events:review', kwargs={'slug': event.slug, 'pk': event.id.hex, 'token': event.auth_token})


import pytest
from django.core.urlresolvers import reverse
from django.utils import timezone
from fossevents.events.services import get_event_review_url
from .. import factories as f


def test_homepage(client):
    event = f.EventFactory(is_published=False)
    event2 = f.EventFactory(is_published=False, start_date=timezone.now()-timezone.timedelta(days=9),
                            end_date=timezone.now()-timezone.timedelta(days=8))
    url = reverse('home')
    response = client.get(url)
    assert response.status_code == 200

    # should have 'events' in the template context
    assert 'events' in response.context
    assert 'upcoming_events' in response.context
    assert 'past_events' in response.context

    # should not display any event, if none are published
    assert len(response.context['events']) == 0
    assert len(response.context['upcoming_events']) == 0
    assert len(response.context['past_events']) == 0

    # should now contain one event, after it's published
    event.is_published = True
    event.save()
    event2.is_published = True
    event2.save()
    response = client.get(url)
    assert len(response.context['events']) == 0
    assert len(response.context['upcoming_events']) == 1
    assert len(response.context['past_events']) == 1
    assert response.context['upcoming_events'][0].id == event.id

# Path: fossevents/events/services.py
# def get_event_review_url(event):
#     return reverse('events:review', kwargs={'slug': event.slug, 'pk': event.id.hex, 'token': event.auth_token})


# Path: tests/integrations/test_events_views.py
import pytest
from django.core.urlresolvers import reverse
from django.utils import timezone
from fossevents.events.services import get_event_review_url
from .. import factories as f



def test_homepage(client):
    event = f.EventFactory(is_published=False)
    event2 = f.EventFactory(is_published=False, start_date=timezone.now()-timezone.timedelta(days=9),
                            end_date=timezone.now()-timezone.timedelta(days=8))
    url = reverse('home')
    response = client.get(url)
    assert response.status_code == 200

    # should have 'events' in the template context
    assert 'events' in response.context
    assert 'upcoming_events' in response.context
    assert 'past_events' in response.context

    # should not display any event, if none are published
    assert len(response.context['events']) == 0
    assert len(response.context['upcoming_events']) == 0
    assert len(response.context['past_events']) == 0

    # should now contain one event, after it's published
    event.is_published = True
    event.save()
    event2.is_published = True
    event2.save()
    response = client.get(url)
    assert len(response.context['events']) == 0
    assert len(response.context['upcoming_events']) == 1
    assert len(response.context['past_events']) == 1
    assert response.context['upcoming_events'][0].id == event.id

    assert response.context['past_events'][0].id == event2.id