Example #1
0
 def test_delete_remarks_update_cache(self):
     note = NoteFactory(author=self.user1,
                        document=self.doc,
                        revision=self.revision.revision)
     self.assertEqual(get_discussion_length(self.revision), 1)
     note.delete()
     self.assertEqual(get_discussion_length(self.revision), 0)
Example #2
0
 def test_delete_remarks_update_cache(self):
     note = NoteFactory(
         author=self.user1,
         document=self.doc,
         revision=self.revision.revision)
     self.assertEqual(get_discussion_length(self.revision), 1)
     note.delete()
     self.assertEqual(get_discussion_length(self.revision), 0)
Example #3
0
    def test_update_deleted_message(self):
        """A soft deleted item cannot be edited."""
        note = NoteFactory(
            document=self.doc,
            revision=1,
            author=self.user1)
        note.soft_delete()
        note.save()

        url = reverse('note-detail', args=[self.doc.document_key, 1, note.id])
        res = self.client.put(url, {'body': 'Update message'})
        self.assertEqual(res.status_code, 403)
Example #4
0
    def test_notes_are_deleted_when_review_is_canceled(self):
        for _ in range(10):
            NoteFactory(author=self.user1, document=self.doc, revision=1)
        self.assertEqual(Note.objects.all().count(), 10)

        self.revision.cancel_review()
        self.assertEqual(Note.objects.all().count(), 0)
Example #5
0
    def setUp(self):
        self.category = CategoryFactory()
        user = UserFactory(
            email='*****@*****.**',
            password='******',
            is_superuser=True,
            category=self.category)
        self.client.login(email=user.email, password='******')

        user2 = UserFactory(email='*****@*****.**', category=self.category)

        doc = DocumentFactory(
            document_key='hazop-report-1',
            category=self.category,
            revision={
                'leader': user,
            }

        )
        doc.latest_revision.start_review()

        for _ in range(5):
            for u in (user, user2):
                NoteFactory(
                    author=u,
                    document=doc,
                    revision=1)

        review_url = reverse('review_document', args=[doc.document_key])
        self.url = '%s%s' % (self.live_server_url, review_url)
        self.test_file = os.path.join(
            os.path.dirname(__file__),
            'casper_tests',
            'tests.js'
        )
Example #6
0
 def test_other_user(self):
     """An user cannot update someone else's message."""
     note = NoteFactory(document=self.doc, revision=1, author=self.user2)
     url = reverse('note-detail', args=[self.doc.document_key, 1, note.id])
     res = self.client.put(url, {'body': 'Update message'},
                           content_type='application/json')
     self.assertEqual(res.status_code, 403)
Example #7
0
 def test_new_remarks_update_cache(self):
     for _ in range(10):
         NoteFactory(
             author=self.user1,
             document=self.doc,
             revision=self.revision.revision,
         )
     self.assertEqual(get_discussion_length(self.revision), 10)
Example #8
0
 def test_cancel_review_updates_cache(self):
     for _ in range(10):
         NoteFactory(
             author=self.user1,
             document=self.doc,
             revision=self.revision.revision,
         )
     self.revision.cancel_review()
     self.assertEqual(get_discussion_length(self.revision), 0)
Example #9
0
    def test_message_owner(self):
        """The message owner can delete it"""
        note = NoteFactory(document=self.doc, revision=1, author=self.user1)
        self.assertIsNone(note.deleted_on)
        url = reverse('note-detail', args=[self.doc.document_key, 1, note.id])
        res = self.client.delete(url)
        self.assertEqual(res.status_code, 200)

        note = Note.objects.get(pk=note.pk)
        self.assertIsNotNone(note.deleted_on)
Example #10
0
    def test_update_deleted_message(self):
        """A soft deleted item cannot be edited."""
        note = NoteFactory(document=self.doc, revision=1, author=self.user1)
        note.soft_delete()
        note.save()

        url = reverse('note-detail', args=[self.doc.document_key, 1, note.id])
        res = self.client.put(url, {'body': 'Update message'})
        self.assertEqual(res.status_code, 403)
Example #11
0
 def create_note(self, body):
     return NoteFactory(body=body,
                        document=self.doc,
                        author=self.user1,
                        revision=1)
Example #12
0
 def test_message_owner(self):
     """The message owner can update it."""
     note = NoteFactory(document=self.doc, revision=1, author=self.user1)
     url = reverse('note-detail', args=[self.doc.document_key, 1, note.id])
     res = self.client.put(url, {'body': 'Update message'})
     self.assertEqual(res.status_code, 200)
Example #13
0
 def test_other_user(self):
     """One cannot delete someone else's messages."""
     note = NoteFactory(document=self.doc, revision=1, author=self.user2)
     url = reverse('note-detail', args=[self.doc.document_key, 1, note.id])
     res = self.client.delete(url)
     self.assertEqual(res.status_code, 403)