<commit_before>
from django.core.urlresolvers import reverse
from django.test import TestCase
from rest_framework import status
from rest_framework.test import APIClient

from ..models import Note, NoteBook, NoteRevision, User


class TestNoteRevisionAPI(TestCase):
    def setUp(self):
        self.client = APIClient()
        self.user = User.objects.create(username='user', password='<PASSWORD>')
        self.notebook = NoteBook.objects.create(title='a title', created_by=self.user)
        self.note = Note.objects.create(title='a title for note', created_by=self.user, notebook=self.notebook)
        self.client.force_authenticate(user=self.user)

    def test_create_without_params(self):
        self.assertEquals(status.HTTP_400_BAD_REQUEST, self.client.post(reverse('note-list')).status_code)
        self.assertEquals(0, NoteRevision.objects.count())

    def test_create(self):
        response = self.client.post(
            reverse('revision-list'),
            {'content': 'a content for note', 'note': self.note.id}
        )
        self.assertEquals(status.HTTP_201_CREATED, response.status_code, response.content)
        self.assertEquals(1, NoteRevision.objects.count())
        self.assertEquals(self.user.username, NoteRevision.objects.get(pk=1).created_by.username)

    def test_create_without_note(self):
        response = self.client.post(
            reverse('revision-list'),
            {'content': 'a content for note'}
        )
        self.assertEquals(status.HTTP_400_BAD_REQUEST, response.status_code, response.content)

    def test_update(self):
        revision = NoteRevision.objects.create(content='a title for note', created_by=self.user, note=self.note)
        response = self.client.put(
            reverse('revision-detail', args=[revision.id]),
            {'content': 'new content', 'note': self.note.id}
        )
        self.assertEquals(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code, response.content)
        self.assertEquals(revision.content, NoteRevision.objects.all()[0].content)

    def test_patch(self):
        revision = NoteRevision.objects.create(content='a title for note', created_by=self.user, note=self.note)
        response = self.client.put(
            reverse('revision-detail', args=[revision.id]),
            {'content': 'new content'}
        )
        self.assertEquals(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code, response.content)
        self.assertEquals(revision.content, NoteRevision.objects.all()[0].content)<commit_msg>add test for delete note revision<commit_after>
from django.core.urlresolvers import reverse
from django.test import TestCase
from rest_framework import status
from rest_framework.test import APIClient

from ..models import Note, NoteBook, NoteRevision, User


class TestNoteRevisionAPI(TestCase):
    def setUp(self):
        self.client = APIClient()
        self.user = User.objects.create(username='user', password='<PASSWORD>')
        self.notebook = NoteBook.objects.create(title='a title', created_by=self.user)
        self.note = Note.objects.create(title='a title for note', created_by=self.user, notebook=self.notebook)
        self.client.force_authenticate(user=self.user)

    def test_create_without_params(self):
        self.assertEquals(status.HTTP_400_BAD_REQUEST, self.client.post(reverse('note-list')).status_code)
        self.assertEquals(0, NoteRevision.objects.count())

    def test_create(self):
        response = self.client.post(
            reverse('revision-list'),
            {'content': 'a content for note', 'note': self.note.id}
        )
        self.assertEquals(status.HTTP_201_CREATED, response.status_code, response.content)
        self.assertEquals(1, NoteRevision.objects.count())
        self.assertEquals(self.user.username, NoteRevision.objects.get(pk=1).created_by.username)

    def test_create_without_note(self):
        response = self.client.post(
            reverse('revision-list'),
            {'content': 'a content for note'}
        )
        self.assertEquals(status.HTTP_400_BAD_REQUEST, response.status_code, response.content)

    def test_update(self):
        revision = NoteRevision.objects.create(content='a content for note', created_by=self.user, note=self.note)
        response = self.client.put(
            reverse('revision-detail', args=[revision.id]),
            {'content': 'new content', 'note': self.note.id}
        )
        self.assertEquals(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code, response.content)
        self.assertEquals(revision.content, NoteRevision.objects.all()[0].content)

    def test_patch(self):
        revision = NoteRevision.objects.create(content='a content for note', created_by=self.user, note=self.note)
        response = self.client.put(
            reverse('revision-detail', args=[revision.id]),
            {'content': 'new content'}
        )
        self.assertEquals(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code, response.content)
        self.assertEquals(revision.content, NoteRevision.objects.all()[0].content)

    def test_delete(self):
        revision = NoteRevision.objects.create(content='a content for note', created_by=self.user, note=self.note)
        response = self.client.delete(reverse('revision-detail', args=[revision.id]))
        self.assertEquals(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code, response.content)
        self.assertEquals(1, NoteRevision.objects.count())
{'fraction_non_alphanumeric': 0.12075884713608172, 'fraction_numerical': 0.008026267785479753, 'mean_word_length': 3.572977481234362, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2469837', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1551, 'n_words': 275}