Exemple #1
0
def test_set_user_questionnaire_answer_invalid(api_client):
    user = factories.UserFactory()
    api_client.force_authenticate(user=user)

    set_data = {'service': 'great', 'question_id': 99, 'answer': ''}

    response = api_client.post(reverse('api:user-questionnaire'),
                               set_data,
                               format='json')
    assert response.status_code == 200
Exemple #2
0
def test_get_user_questionnaire(api_client):
    user = factories.UserFactory()
    api_client.force_authenticate(user=user)

    data = {'service': 'great'}

    response = api_client.get(reverse('api:user-questionnaire'),
                              data,
                              format='json')

    assert response.status_code == 200
Exemple #3
0
def test_create_user_api_duplicated_email(mocked_notifications, api_client):
    user = factories.UserFactory()
    new_email = user.email
    password = '******'

    response = api_client.post(reverse('api:user'), {
        'email': new_email,
        'password': password
    },
                               format='json')
    assert response.status_code == 409

    assert models.User.objects.filter(email=new_email).count() == 1
Exemple #4
0
def test_create_user_api_email_case_insensitive(api_client):
    factories.UserFactory(email='*****@*****.**')

    new_email = '*****@*****.**'
    password = '******'

    response = api_client.post(reverse('api:user'), {
        'email': new_email,
        'password': password
    },
                               format='json')

    assert response.status_code == 409
    assert models.User.objects.filter(email__iexact=new_email).count() == 1
Exemple #5
0
def test_create_user_profile(api_client):
    user = factories.UserFactory()
    data = {
        'first_name': 'john',
        'last_name': 'smith',
        'mobile_phone_number': '0203044213',
        'job_title': 'Director',
    }

    assert models.UserProfile.objects.filter(user=user).count() == 0
    api_client.force_authenticate(user=user)
    response = api_client.post(reverse('api:user-create-profile'),
                               data,
                               format='json')

    instance = models.UserProfile.objects.last()
    assert response.status_code == 201
    assert instance.first_name == data['first_name']
    assert instance.last_name == data['last_name']
    assert instance.job_title == data['job_title']
    assert instance.mobile_phone_number == data['mobile_phone_number']
Exemple #6
0
def admin_user():
    admin_user = factories.UserFactory(is_staff=False)
    admin_user.save()
    return admin_user
Exemple #7
0
def test_get_and_set_user_data(api_client):
    user = factories.UserFactory()
    api_client.force_authenticate(user=user)
    url = reverse('api:user-data')

    # Call set twice to put two objects in db
    response = api_client.post(url, {
        'name': 'data-object1',
        'data': {
            'test': 1
        }
    },
                               format='json')
    assert response.status_code == 200

    response = api_client.post(url, {
        'name': 'data-object2',
        'data': {
            'test': 2
        }
    },
                               format='json')
    assert response.status_code == 200

    # Read them back
    assert api_client.get(url, {
        'name': 'data-object1'
    }, format='json').json().get('data-object1') == {
        'test': 1
    }
    assert api_client.get(url, {
        'name': 'data-object2'
    }, format='json').json().get('data-object2') == {
        'test': 2
    }

    # Update one and check the change
    response = api_client.post(url, {
        'name': 'data-object1',
        'data': {
            'test': 'updated'
        }
    },
                               format='json')
    assert api_client.get(url, {
        'name': 'data-object1'
    }, format='json').json().get('data-object1') == {
        'test': 'updated'
    }
    assert api_client.get(url, {
        'name': 'data-object2'
    }, format='json').json().get('data-object2') == {
        'test': 2
    }

    # Read them back in one request
    both = api_client.get(url, {
        'name': ['data-object1', 'data-object2']
    },
                          format='json').json()
    assert both.get('data-object1') == {'test': 'updated'}
    assert both.get('data-object2') == {'test': 2}

    # test nonexistant object
    assert api_client.get(url, {
        'name': 'data-object-unknown'
    }, format='json').json() == {}