Esempio n. 1
0
    def handle(self, *args, **options):
        if len(args) != 2:
            print(
                'Usage: ./manage.py create_wordlist <wordlist> <wordlist.txt>')
            quit()

        with open(args[1], 'rU') as handle:
            words = self.parse(handle, options['create'])
        sys.stdout.write("%d words loaded from %s" % (len(words), args[1]))

        if 'run' in options and options['run']:
            ed = User.objects.get(pk=1)
            # create wordlist.
            with reversion.create_revision():
                wl = Wordlist.objects.create(editor=ed, name=args[0])
                wl.save()

            # go through words and add them to wordlist
            for order in sorted(words):
                with reversion.create_revision():
                    m = WordlistMember(wordlist=wl,
                                       word=words[order],
                                       order=order)
                    m.save()

            if wl.words.count() != len(words):
                m = "Words in wordlist doesn't match expected (%d != %d)"
                raise AssertionError(m % (wl.words.count(), len(words)))
            sys.stdout.write("Wordlist %s created with %d entries" %
                             (wl, wl.words.count()))
        else:
            sys.stdout.write(
                "Dry-run complete. Use --run to save changes. Rolling back.")
Esempio n. 2
0
    def test_wordlist_orders_not_by_id(self):
        WL = Wordlist.objects.create(name="test2", editor=self.editor)
        WL.save()

        words = self.words[:]
        words.reverse()
        assert words != self.words

        for i, w in enumerate(words, 1):
            m = WordlistMember(wordlist=WL, word=w, order=i)
            m.save()

        t = Task.objects.create(
            editor=self.editor,
            name="Test Task 2",
            description=" ",
            source=self.source,
            wordlist=WL,
            done=False,
            view="WordlistView",
            records=1,
        )
        t.save()

        self.client.login(username="******", password="******")
        response = self.client.get(t.get_absolute_url())
        self.assertEqual(response.status_code, 200)
        formdata = [f.initial for f in response.context['formset'].forms]

        # and is it correct?
        for i in range(len(words)):
            assert formdata[i][
                'order_id'] == i + 1  # ordering starts at 1 not 0
            assert formdata[i]['word'] == words[i]
 def handle(self, *args, **options):
     if len(args) != 2:
         print('Usage: ./manage.py create_wordlist <wordlist> </path/to/wordlist.txt>')
         quit()
     
     with open(args[1], 'rU') as handle:
         words = self.parse(handle, options['create'] )
     sys.stdout.write("%d words loaded from %s" % (len(words), args[1]))
     
     if 'run' in options and options['run']:
         ed = User.objects.get(pk=1)
         # create wordlist.
         with reversion.create_revision():
             wl = Wordlist.objects.create(
                 editor=ed, 
                 name=args[0]
             )
             wl.save()
         
         # go through words and add them to wordlist
         for order in sorted(words):
             with reversion.create_revision():
                 m = WordlistMember(wordlist=wl, word=words[order], order=order)
                 m.save()
         
         if wl.words.count() != len(words):
             raise AssertionError(
                 "Number of words in wordlist doesn't match expected (%d != %d)" % \
                 (wl.words.count(), len(words))
             )
         sys.stdout.write("Wordlist %s created with %d entries" % (wl, wl.words.count()))
     else:
         sys.stdout.write("Dry-run complete. Use --run to save changes. Rolling back.")
Esempio n. 4
0
 def test_wordlist_orders_not_by_id(self):
     WL = Wordlist.objects.create(name="test2", editor=self.editor)
     WL.save()
     
     words = self.words[:]
     words.reverse()
     assert words != self.words
     
     for i, w in enumerate(words, 1):
         m = WordlistMember(wordlist=WL, word=w, order=i)
         m.save()
     
     t = Task.objects.create(
         editor=self.editor,
         name="Test Task 2",
         description=" ",
         source=self.source,
         wordlist=WL,
         done=False,
         view="WordlistView",
         records=1, 
     )
     t.save()
     
     self.client.login(username="******", password="******")
     response = self.client.get(t.get_absolute_url())
     self.assertEqual(response.status_code, 200)
     formdata = [f.initial for f in response.context['formset'].forms]
             
     # and is it correct?
     for i in range(len(words)):
         assert formdata[i]['order_id'] == i + 1 # ordering starts at 1 not 0
         assert formdata[i]['word'] == words[i]
Esempio n. 5
0
 def test_wordlist_overrides_records_in_model(self):
     """
     Tests that the number of records is set to the number of items
     """
     assert self.task.records == self.wordlist.words.count()
     m = WordlistMember(wordlist=self.wordlist, word=self.words[0], order=5) # add another
     m.save()
     self.task.save() # need to save to update.
     assert self.task.records == len(self.wordlist.words.all())
Esempio n. 6
0
 def test_wordlist_overrides_records_in_model(self):
     """
     Tests that the number of records is set to the number of items
     """
     assert self.task.records == self.wordlist.words.count()
     m = WordlistMember(wordlist=self.wordlist, word=self.words[0],
                        order=5)  # add another
     m.save()
     self.task.save()  # need to save to update.
     assert self.task.records == len(self.wordlist.words.all())
Esempio n. 7
0
    def setUpTestData(cls):
        cls.client = Client()
        cls.editor = User.objects.create_user('admin', '*****@*****.**',
                                              "test")
        cls.source = Source.objects.create(year="1991",
                                           author='Smith',
                                           slug='Smith1991',
                                           reference='S2',
                                           comment='c1',
                                           editor=cls.editor)
        cls.lang = Language.objects.create(language='A',
                                           slug='langa',
                                           information='i.1',
                                           classification='a, b',
                                           isocode='aaa',
                                           editor=cls.editor)

        cls.words = []
        cls.words_in_wordlist = []
        cls.wordlist = Wordlist.objects.create(name="test", editor=cls.editor)
        for i in range(5):
            w = Word.objects.create(editor=cls.editor,
                                    word="WORD %d" % i,
                                    slug=str(i))
            cls.words.append(w)
            # BUT only add the first 3 words to wordlist
            if i < 3:
                m = WordlistMember(wordlist=cls.wordlist, word=w, order=i)
                m.save()
                cls.words_in_wordlist.append(w)

        cls.task = Task.objects.create(
            editor=cls.editor,
            name="Test Task",
            description="A Test of Data Entry",
            source=cls.source,
            wordlist=cls.wordlist,
            done=False,
            view="WordlistView",
            records=1,
        )

        # for formset validation
        cls.form_data = {
            'form-TOTAL_FORMS': u'3',
            'form-INITIAL_FORMS': u'3',
            'form-MAX_NUM_FORMS': u'1000',
            # form 0
            'form-0-language': cls.lang.id,
            'form-0-source': cls.source.id,
            'form-0-word': cls.words[0].id,
            'form-0-entry': 'entry-0',
            'form-0-annotation': 'comment-0',
            # form 1
            'form-1-language': cls.lang.id,
            'form-1-source': cls.source.id,
            'form-1-word': cls.words[1].id,
            'form-1-entry': 'entry-1',
            'form-1-annotation': 'comment-1',
            # form 2
            'form-2-language': cls.lang.id,
            'form-2-source': cls.source.id,
            'form-2-word': cls.words[2].id,
            'form-2-entry': 'entry-2',
            'form-2-annotation': 'comment-2',
            'submit': 'true',
        }
        # and for partial validation...
        cls.bad_form_data = cls.form_data.copy()
        del (cls.bad_form_data['form-2-language'])
Esempio n. 8
0
 def setUp(self, *args):
     self.client = Client()
     self.editor = User.objects.create_user('admin',
                                            '*****@*****.**', "test")
     self.source = Source.objects.create(
             year="1991",
             author='Smith',
             slug='Smith1991',
             reference='S2',
             comment='c1',
             editor=self.editor
     )
     self.lang = Language.objects.create(language='A', slug='langa', 
         information='i.1', classification='a, b',
         isocode='aaa', editor=self.editor)
     
     self.words = []
     self.words_in_wordlist = []
     self.wordlist = Wordlist.objects.create(name="test", editor=self.editor)
     for i in range(5):
         w = Word.objects.create(
             editor=self.editor, 
             word="WORD %d" % i,
             slug=str(i)
         )
         self.words.append(w)
         # BUT only add the first 3 words to wordlist
         if i < 3:
             m = WordlistMember(wordlist=self.wordlist, word=w, order=i)
             m.save()
             self.words_in_wordlist.append(w)
             
     self.task = Task.objects.create(
         editor=self.editor,
         name="Test Task",
         description="A Test of Data Entry",
         source=self.source,
         wordlist=self.wordlist,
         done=False,
         view="WordlistView",
         records=1, 
     )
     
     # for formset validation
     self.form_data = {
         'form-TOTAL_FORMS': u'3',
         'form-INITIAL_FORMS': u'3',
         'form-MAX_NUM_FORMS': u'1000',
         # form 0
         'form-0-language': self.lang.id,
         'form-0-source': self.source.id,
         'form-0-word': self.words[0].id,
         'form-0-entry': 'entry-0',
         'form-0-annotation': 'comment-0',
         # form 1
         'form-1-language': self.lang.id,
         'form-1-source': self.source.id,
         'form-1-word': self.words[1].id,
         'form-1-entry': 'entry-1',
         'form-1-annotation': 'comment-1',
         # form 2
         'form-2-language': self.lang.id,
         'form-2-source': self.source.id,
         'form-2-word': self.words[2].id,
         'form-2-entry': 'entry-2',
         'form-2-annotation': 'comment-2',
         'submit': 'true',
     }
     # and for partial validation...
     self.bad_form_data = self.form_data.copy()
     del(self.bad_form_data['form-2-language'])