def test_get_tasks(self):
        factory = APIRequestFactory()
        view = TaskList.as_view()

        project = Project.objects.create(title='TestProject 1')
        tasks = Task.objects.bulk_create([(Task(id=1,
                                                title='Test1',
                                                project=project)),
                                          (Task(id=2,
                                                title='Test2',
                                                project=project)),
                                          (Task(id=3,
                                                title='Test3',
                                                project=project))])

        request = factory.get('/api/tasks')
        force_authenticate(request,
                           user=self.test_user,
                           token=self.full_access_token)
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 3)

        for i in range(3):
            # Reverse comparison because tasks are ordered by created date.
            self.assertEqual(tasks[i].title, response.data[2 - i]['title'])
            self.assertEqual(tasks[i].description,
                             response.data[2 - i]['description'])
            self.assertEqual(tasks[i].project.id,
                             response.data[2 - i]['project']['id'])
            self.assertEqual(tasks[i].project.title,
                             response.data[2 - i]['project']['title'])
            self.assertEqual(tasks[i].project.description,
                             response.data[2 - i]['project']['description'])

        force_authenticate(request,
                           user=self.test_user,
                           token=self.read_access_token)
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 3)

        for i in range(3):
            self.assertEqual(tasks[i].title, response.data[2 - i]['title'])
            self.assertEqual(tasks[i].description,
                             response.data[2 - i]['description'])
            self.assertEqual(tasks[i].project.id,
                             response.data[2 - i]['project']['id'])
            self.assertEqual(tasks[i].project.title,
                             response.data[2 - i]['project']['title'])
            self.assertEqual(tasks[i].project.description,
                             response.data[2 - i]['project']['description'])
    def test_create_task_fail_by_user_with_read_scope_only(self):
        project = Project.objects.create(id=1, title='TestProject')
        data = {
            'title': 'TestTask',
            'description': 'Test',
            'project_id': project.id
        }

        factory = APIRequestFactory()
        view = TaskList.as_view()

        request = factory.post('/api/tasks/', data=data)
        force_authenticate(request,
                           user=self.test_user,
                           token=self.read_access_token)
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
    def test_create_task(self):
        project = Project.objects.create(id=1, title='TestProject')
        data = {
            'title': 'TestTask',
            'description': 'Test',
            'project_id': project.id
        }

        factory = APIRequestFactory()
        view = TaskList.as_view()

        request = factory.post('/api/tasks/', data=data)
        force_authenticate(request,
                           user=self.test_user,
                           token=self.full_access_token)
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(data['title'], response.data.get('title'))
        self.assertEqual(data['description'], response.data.get('description'))
    def test_assign_task_to_user_after_task_creation(self):
        factory = APIRequestFactory()
        view = TaskList.as_view()

        project = Project.objects.create(id=1, title='TestProject 1')
        user = User.objects.create(id=1, username='******', password='******')

        task_data = {
            'title': 'Task 5',
            'description': 'test',
            'project_id': project.id,
            'user_id': user.id
        }

        request = factory.post('/api/tasks/', task_data)
        force_authenticate(request,
                           user=self.test_user,
                           token=self.full_access_token)
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.data['user']['id'], user.id)
        self.assertEqual(response.data['project']['id'], project.id)
Beispiel #5
0
from django.conf.urls import patterns, include, url

# Function based API views
# from api.views import task_list, task_detail

# Class based API views
from api.views import TaskList, TaskDetail

urlpatterns = patterns('',

    # Regular URLs
	# url(r'^tasks/$', task_list, name='task_list'),
    # url(r'^tasks/(?P<pk>[0-9]+)$', task_detail, name='task_detail'),

    # Class based URLs,
    url( r'^tasks/$', TaskList.as_view(), name = 'task_list' ),
    url( r'^tasks/(?P<pk>[0-9]+)$', TaskDetail.as_view(), name = 'task_detail' ),
)
Beispiel #6
0
# urlpatterns = patterns('',
# 
#     # Regular URLs
# 	# url(r'^tasks/$', task_list, name='task_list'),
#     # url(r'^tasks/(?P<pk>[0-9]+)$', task_detail, name='task_detail'),
# 
#     # Class based URLs,
#     url( r'^tasks/$', TaskList.as_view(), name = 'task_list' ),
#     url( r'^tasks/(?P<pk>[0-9]+)$', TaskDetail.as_view(), name = 'task_detail' ),
#     url( r'^tasks/task_id/(?P<task_id>.+)/$', TaskIDList.as_view()),



# The API URLs are now determined automatically by the router.
# Additionally, we include the login URLs for the browseable API.
# urlpatterns = [
# url(r'^tasks/$', TaskView.as_view(), name='task-list'),
# ]

#router = DefaultRouter()
#router.register(r'tasks', TaskViewSet)

urlpatterns = patterns('',
    url( r'^tasks/task_id/(?P<task_id>.+)/$', TaskDetail.as_view()),
    url( r'^tasks/to_unit/(?P<to_unit>.+)/$', UnitList.as_view()),
    url( r'^tasks/$', TaskList.as_view()),
    #url( r'^tasks/task_id/(?P<pk>.+)/$', TaskDetail.as_view()),
    #url(r'^', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
)
Beispiel #7
0
from django.urls import path
from api.views import RegistrationAPIView, LoginAPIView, LogoutAPIView, TaskList, TaskDetails, Execution

urlpatterns = [
    path('registration/', RegistrationAPIView.as_view()),
    path('login/', LoginAPIView.as_view()),
    path('logout/', LogoutAPIView.as_view()),
    path('todo/', TaskList.as_view()),
    path('todo/<int:pk>', TaskDetails.as_view()),
    path('execution/', Execution.as_view())
]
Beispiel #8
0
from django.urls import path

from api.views import TaskList
from api.views import TaskDetail

app_name = 'api'

urlpatterns = [
    path('', TaskList.as_view(), name='task-list'),
    path('<int:pk>/', TaskDetail.as_view(), name='task-detail'),
]

Beispiel #9
0
from django.urls import path
from api import views
from api.views import ListsList, ListDetail, GenericListList, GenericListDetail, TaskList, TaskDetail, GenericTaskList, GenericTaskDetail

urlpatterns = [
    path('login/', views.login),
    path('register/', views.register),
    path('list_cbv/', ListsList.as_view()),
    path('list_cbv/<int:pk>/', ListDetail.as_view()),
    path('list_fbv/', views.lists_list),
    path('list_fbv/<int:pk>/', views.lists_detail),
    path('list_gen/', GenericListList.as_view()),
    path('list_gen/<int:pk>/', GenericListDetail.as_view()),
    path('task_cbv/', TaskList.as_view()),
    path('task_cbv/<int:pk>/', TaskDetail.as_view()),
    path('task_fbv/', views.task_list),
    path('task_fbv/<int:pk>/', views.task_detail),
    path('task_gen/', GenericTaskList.as_view()),
    path('task_gen/<int:pk>/', GenericTaskDetail.as_view()),
]
Beispiel #10
0
# urlpatterns = patterns('',
#
#     # Regular URLs
# 	# url(r'^tasks/$', task_list, name='task_list'),
#     # url(r'^tasks/(?P<pk>[0-9]+)$', task_detail, name='task_detail'),
#
#     # Class based URLs,
#     url( r'^tasks/$', TaskList.as_view(), name = 'task_list' ),
#     url( r'^tasks/(?P<pk>[0-9]+)$', TaskDetail.as_view(), name = 'task_detail' ),
#     url( r'^tasks/task_id/(?P<task_id>.+)/$', TaskIDList.as_view()),

# The API URLs are now determined automatically by the router.
# Additionally, we include the login URLs for the browseable API.
# urlpatterns = [
# url(r'^tasks/$', TaskView.as_view(), name='task-list'),
# ]

#router = DefaultRouter()
#router.register(r'tasks', TaskViewSet)

urlpatterns = patterns(
    '',
    url(r'^tasks/task_id/(?P<task_id>.+)/$', TaskDetail.as_view()),
    url(r'^tasks/to_unit/(?P<to_unit>.+)/$', UnitList.as_view()),
    url(r'^tasks/$', TaskList.as_view()),
    #url( r'^tasks/task_id/(?P<pk>.+)/$', TaskDetail.as_view()),
    #url(r'^', include(router.urls)),
    url(r'^api-auth/',
        include('rest_framework.urls', namespace='rest_framework')))