Esempio n. 1
0
def test_delete_for_mutliple_lesson_completed(api_client,
                                              set_lesson_completed):
    """
    This test where multiple user completed same lesson and delete should delete user specific lesson
    """

    data = json.loads(set_lesson_completed.content)
    assert set_lesson_completed.status_code == 200

    profile = factories.UserProfileFactory()
    api_client.force_authenticate(user=profile.user)

    set_data = {
        'user': profile.user.pk,
        'lesson_page': 'my-new-lesson',
        'lesson': 99,
        'module': 1,
        'service': 'great'
    }
    api_client.post(reverse('api:user-lesson-completed'),
                    set_data,
                    format='json')
    data = {
        'service': 'great',
        'user_id': data['lesson_completed']['user'],
        'lesson': data['lesson_completed']['lesson'],
    }

    response = api_client.delete(
        reverse('api:user-lesson-completed', ),
        data=data,
        format='json',
    )
    assert response.status_code == 200
Esempio n. 2
0
def test_update_partial_user_profile(api_client, user_partial_profile_data):

    profile = factories.UserProfileFactory()
    api_client.force_authenticate(user=profile.user)

    response = api_client.patch(reverse('api:user-update-profile'),
                                user_partial_profile_data,
                                format='json')
    profile.refresh_from_db()
    assert response.status_code == 200
    assert profile.first_name == user_partial_profile_data['first_name']
    assert profile.last_name == user_partial_profile_data['last_name']
Esempio n. 3
0
def set_lesson_completed(api_client):
    profile = factories.UserProfileFactory()
    api_client.force_authenticate(user=profile.user)

    set_data = {
        'user': profile.user.pk,
        'lesson_page': 'my-new-lesson',
        'lesson': 99,
        'module': 1,
        'service': 'great'
    }
    return api_client.post(reverse('api:user-lesson-completed'),
                           set_data,
                           format='json')
Esempio n. 4
0
def test_create_user_profile_already_exists(api_client):
    profile = factories.UserProfileFactory()
    data = {
        'first_name': 'john',
        'last_name': 'smith',
        'mobile_phone_number': '0203044213',
        'job_title': 'Director',
    }

    api_client.force_authenticate(user=profile.user)
    response = api_client.post(reverse('api:user-create-profile'),
                               data,
                               format='json')

    assert response.status_code == 200
Esempio n. 5
0
def test_get_not_existing_lesson(api_client):

    profile = factories.UserProfileFactory()
    api_client.force_authenticate(user=profile.user)

    data = {
        'service': 'great',
        'user': profile.user.pk,
        'lesson_page': 'dummy-page',
    }
    response = api_client.get(reverse('api:user-lesson-completed'),
                              data,
                              format='json')

    assert response.status_code == 200
    assert response.json().get('lessson_completed') is None
Esempio n. 6
0
def test_delete_endpoint_for_lesson_completed_for_non_owner(
        api_client, set_lesson_completed):
    other_user = factories.UserProfileFactory()

    data = json.loads(set_lesson_completed.content)
    assert set_lesson_completed.status_code == 200

    data = {
        'service': 'great',
        'user_id': other_user.id,
        'lesson': data['lesson_completed']['lesson'],
    }

    response = api_client.delete(
        reverse('api:user-lesson-completed', ),
        data=data,
        format='json',
    )
    assert response.status_code == 200
Esempio n. 7
0
def test_set_page_view(api_client, page_view_data):
    def set_view(data):
        set_response = api_client.post(reverse('api:user-page-views'),
                                       data,
                                       format='json')
        assert set_response.status_code == 200
        page_view = set_response.json().get('page_view')
        assert page_view['page'] == data['page']
        assert page_view['service'] == data['service']
        return page_view

    def get_view(data):
        response = api_client.get(reverse('api:user-page-views'),
                                  data,
                                  format='json')
        assert response.status_code == 200
        return response.json().get('page_views')

    profile = factories.UserProfileFactory()
    api_client.force_authenticate(user=profile.user)

    # Page not viewed
    page_views = get_view(page_view_data['page1'])
    assert page_views is None

    # Set a different to viewed - check our first page is not affected
    set_view(page_view_data['page2'])
    assert get_view(page_view_data['page1']) is None

    # Set first page to viewed and check
    set_view(page_view_data['page1'])
    page_views = get_view(page_view_data['page1'])
    assert len(page_views) == 1
    page_view = page_views[page_view_data['page1']['page']]
    assert page_view.get('service') == page_view_data['page1']['service']

    # get all page_views for service
    page_views = get_view(page_view_data['service_only'])
    assert len(page_views) == 2
    assert page_views[page_view_data['page1']['page']] is not None
    assert page_views[page_view_data['page2']['page']] is not None