Пример #1
0
    def test_count_objects(self):

        # Create first
        note_data = {'note': 'asdfgh', 'number': 1, 'alias':'bb'}
        Notebook(**note_data).save()

        self.assertCountObject(1, Notebook)

        # Create second
        note_data['number'] = 2
        Notebook(**note_data).save()

        self.assertCountObject(2, Notebook)

        # Change first
        note = Notebook.objects.all()[0]
        note.alias = 'aa'
        note.save()

        self.assertCountObject(2, Notebook)

        # Remove second
        Notebook.objects.all()[1].delete()

        self.assertCountObject(1, Notebook)
Пример #2
0
    def test_save(self):
        note_data = self.notebook_data_generator(1)
        note_main = Notebook(**note_data)
        start_date, end_date, null = self.time_start_stop(note_main.save)

        note1_rev1 = Notebook.objects_raw.filter(note=note_main.note,
                                                 version_unique_on=True)[0]

        note_main = Notebook.objects.get(pk=note_main.pk)

        dg = self.notebook_data_generator(1)
        self.assertEqual([dg['note'], dg['number'], dg['alias']],
                         [note1_rev1.note, note1_rev1.number, note1_rev1.alias])
        self.assertEqual([note_main.note, note_main.number, note_main.alias],
                         [note1_rev1.note, note1_rev1.number, note1_rev1.alias])
        self.assertVersionStatus(note_main,
                        version_parent_pk=None,
                        version_parent_rev_pk=note1_rev1,
                        version_have_children=False,
                        version_date_pre=start_date,
                        version_date_post=end_date,
                        version_hash='',
                        version_unique_on=False,
                        version_in_trash=False,
                        version_counter=1,
                        info='main, copy rev1')

        with self.assertRaises(VersionDisabledMethodException):
            note1_rev1.save()

        note1_rev2_new = self.notebook_generator_rev_new(3, note_main)
        with self.assertRaises(VersionDisabledMethodException):
            note1_rev2_new.save()
Пример #3
0
    def test_unique_together(self):

#        item = { 'page_number':10,
#                 'book':Book.objects_raw.get(pk=1),
#                 'chapter':Chapter.objects.get(pk=1),
#                 'section':Section.objects_raw.get(pk=1),
#                 'contents':'asdasd',
#                 'notes' : 'oooo' }
#
#        Page(**item).save()
#        with self.assertRaises(IntegrityError):
#            Page(**item).save()
#        transaction.rollback()

        note_data = {'note': 'qwerty', 'number': 1, 'alias':'aa'}
        Notebook(**note_data).save()
        with self.assertRaises(IntegrityError):
            Notebook(**note_data).save()
        transaction.rollback()
Пример #4
0
 def notebook_generator_rev_new(self, number, pk_main, pk_rev_old=None):
     note_data = self.notebook_data_generator(number)
     note = Notebook(**note_data)
     note.version_parent_pk = pk_main
     note.version_parent_rev_pk = pk_rev_old
     note.version_have_children = False
     note.version_date = timezone.localtime(timezone.now())
     note.version_hash = ''
     note.version_unique_on = None
     note.version_in_trash = False
     note._save()
     return note
Пример #5
0
 def notebook_generator_rev(self, number, pk_main, pk_rev_old=None,
                            have_children=False):
     '''
     * number - a unique sequence number generated data
     '''
     note_data = self.notebook_data_generator(number)
     note = Notebook(**note_data)
     note.version_parent_pk = pk_main
     note.version_parent_rev_pk = pk_rev_old
     note.version_have_children = have_children
     note.version_date = timezone.localtime(timezone.now())
     note.version_hash = self.notebook_hash_generator(number)
     note.version_unique_on = True
     note.version_in_trash = False
     note._save()
     return note
Пример #6
0
    def test_trash(self):

        note_data = {'note': 'asdfgh', 'number': 31, 'alias':'bb'}
        note1 = Notebook(**note_data)
        note1.save()

        note_data['number'] = 33
        note2 = Notebook(**note_data)
        note2.save()

        # Trash is empty
        self.assertCountObjectInTrash(0, Notebook)
        self.assertCountObject(2, Notebook)

        note1.delete()
        # Trash something already has.
        self.assertCountObjectInTrash(1, Notebook)
        self.assertCountObject(1, Notebook)

        # Restore from trash
        note1_from_trash = Notebook.objects.in_trash()[0]
        note1_from_trash.restore_from_trash()

        # Trash now is empty
        self.assertCountObjectInTrash(0, Notebook)
        self.assertCountObject(2, Notebook)

        note1.delete(hard=True)
        self.assertCountObjectInTrash(0, Notebook)
        self.assertCountObject(1, Notebook)