예제 #1
0
    def test_forbidden_delete(self):
        data = {'task_id': self.task.id, 'task_name': self.task.name}
        kwargs = {'method': 'delete'}
        request = self.factory.post(path='/task_crud/delete/', data=data, )
        request.user = self.user2
        response = TaskCrud.as_view()(request, **kwargs)

        assert response.status_code == HttpResponseForbidden.status_code
예제 #2
0
    def test_unexisting_id_request(self):
        data = {'task_id': 999, 'task_name': self.task.name}
        kwargs = {'method': 'edit'}
        request = self.factory.post(path='/task_crud/edit/', data=data, )
        request.user = self.user
        response = TaskCrud.as_view()(request, **kwargs)

        assert response.status_code == HttpResponseNotFound.status_code
예제 #3
0
    def test_empty_delete_request(self):
        data = {}
        kwargs = {'method': 'delete'}
        request = self.factory.post(path='/task_crud/delete/', data=data, )
        request.user = self.user
        response = TaskCrud.as_view()(request, **kwargs)

        assert response.status_code == HttpResponseBadRequest.status_code
예제 #4
0
    def test_invalid_method(self):
        data = {}
        kwargs = {'method': 'invalid method'}
        request = self.factory.post(path='/task_crud/create/', data=data, )
        request.user = self.user
        response = TaskCrud.as_view()(request, **kwargs)

        assert response.status_code == HttpResponseBadRequest.status_code
예제 #5
0
    def test_edit(self):
        data = {'task_id': self.task.id, 'task_name': 'new_task_name'}
        kwargs = {'method': 'edit'}
        request = self.factory.post(path='/task_crud/edit/', data=data, )
        request.user = self.user
        response = TaskCrud.as_view()(request, **kwargs)

        modified_task = Task.objects.get(id=self.task.id)
        assert modified_task.name == data['task_name']
        assert response.status_code == HttpResponse.status_code
예제 #6
0
    def test_create_method(self):
        data = {'task_name': 'new_task_name'}
        kwargs = {'method': 'create'}
        request = self.factory.post(path='/task_crud/create/', data=data, )
        request.user = self.user
        response = TaskCrud.as_view()(request, **kwargs)

        created_task = Task.objects.filter(owner=self.user, name=data['task_name'])
        assert len(created_task) is 1
        assert response.status_code == HttpResponse.status_code
예제 #7
0
    def test_mark_undone(self):
        data = {'task_id': self.done_task.id}
        kwargs = {'method': 'undone'}
        request = self.factory.post(path='/task_crud/undone/', data=data, )
        request.user = self.user
        response = TaskCrud.as_view()(request, **kwargs)

        modified_task = Task.objects.get(id=self.done_task.id)
        assert modified_task.is_done is False
        assert modified_task.marked_done_by is None
        assert response.status_code == HttpResponse.status_code
예제 #8
0
    def test_delete_method(self):
        task_id = self.task.id
        data = {'task_id': task_id}
        kwargs = {'method': 'delete'}
        request = self.factory.post(path='/task_crud/delete/', data=data, )
        request.user = self.user
        response = TaskCrud.as_view()(request, **kwargs)

        deleted_task = Task.objects.filter(id=task_id)
        assert len(deleted_task) is 0
        assert response.status_code == HttpResponse.status_code
예제 #9
0
"""online_manager URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url

from task_list.views import Index
from task_list.task_crud import TaskCrud

urlpatterns = [
    path('admin/', admin.site.urls),
    path('accounts/', include('django.contrib.auth.urls')),
    path('', Index.as_view(), name='index'),
    url(r'^task_crud/(?P<method>create|edit|delete|done|undone)/',
        TaskCrud.as_view(),
        name='task_crud'),
]