# Path: disparity/apps/salary/utils.py
# def unsign_survey_token(token):
#     data = signing.loads(
#         token, salt=SURVEY_TOKEN_SALT, max_age=SURVEY_TOKEN_MAX_AGE,
#     )
#     expires_at_str = data.pop('expires_at')
#     data['expires_at'] = parser.parse(expires_at_str)
#     return data


from django.core.urlresolvers import reverse
from disparity.apps.salary.utils import (
    unsign_survey_token,
)



def test_survey_creation_page(webtest_client, factories):
    url = reverse('survey-create')

    response = webtest_client.get(url)
    assert response.status_code == 200


def test_survey_creation(webtest_client, factories, models):
    url = reverse('survey-create')

    response = webtest_client.get(url)
    assert response.status_code == 200

    participant_emails = factories.EmailAddressFactory.create_batch(5)

    response.form['owner_email'] = 'owner@example.com'
    response.form['owner_salary'] = 12345
    response.form['participant_emails'] = ','.join(participant_emails)

    create_response = response.form.submit()

    assert create_response.status_code == 302

    detail_response = webtest_client.get(create_response.location)
    assert detail_response.status_code == 200

    token = detail_response.context['token']

# Path: disparity/apps/salary/utils.py
# def unsign_survey_token(token):
#     data = signing.loads(
#         token, salt=SURVEY_TOKEN_SALT, max_age=SURVEY_TOKEN_MAX_AGE,
#     )
#     expires_at_str = data.pop('expires_at')
#     data['expires_at'] = parser.parse(expires_at_str)
#     return data


# Path: tests/salary/test_survey_creation.py
from django.core.urlresolvers import reverse
from disparity.apps.salary.utils import (
    unsign_survey_token,
)




def test_survey_creation_page(webtest_client, factories):
    url = reverse('survey-create')

    response = webtest_client.get(url)
    assert response.status_code == 200


def test_survey_creation(webtest_client, factories, models):
    url = reverse('survey-create')

    response = webtest_client.get(url)
    assert response.status_code == 200

    participant_emails = factories.EmailAddressFactory.create_batch(5)

    response.form['owner_email'] = 'owner@example.com'
    response.form['owner_salary'] = 12345
    response.form['participant_emails'] = ','.join(participant_emails)

    create_response = response.form.submit()

    assert create_response.status_code == 302

    detail_response = webtest_client.get(create_response.location)
    assert detail_response.status_code == 200

    token = detail_response.context['token']

    data = unsign_survey_token(token)