def handle(self, *args, **options):
     election = Election.objects.get(slug=options["election_slug"])
     sc = SecondRoundCreator(election)
     for candidate_slug in options["candidates_slug"]:
         candidate = election.candidates.get(id=candidate_slug)
         sc.pick_one(candidate)
     second_round = sc.get_second_round()
     self.stdout.write("Clone created with name %s and slug %s" % (second_round.name, second_round.slug))
     self.stdout.write("The url for it is %s" % (second_round.get_absolute_url()))
예제 #2
0
 def handle(self, *args, **options):
     election = Election.objects.get(slug=options['election_slug'])
     sc = SecondRoundCreator(election)
     for candidate_slug in options['candidates_slug']:
         candidate = election.candidates.get(id=candidate_slug)
         sc.pick_one(candidate)
     second_round = sc.get_second_round()
     self.stdout.write("Clone created with name %s and slug %s" %
                       (second_round.name, second_round.slug))
     self.stdout.write("The url for it is %s" %
                       (second_round.get_absolute_url()))
예제 #3
0
    def test_copy_messages_and_answers(self):
        candidate3 = Candidate.objects.get(id=6)
        message = Message.objects.create(election=self.tarapaca,
                                         author_name='author',
                                         author_email='*****@*****.**',
                                         subject='subject',
                                         content='content',
                                         slug='subject-slugified',
                                         accepted=True)
        message.people.add(self.adela)
        message.people.add(self.carlos)
        message.people.add(candidate3)

        answer = Answer.objects.create(
            content=
            u'Hey I\'ve had to speak english in the last couple of days',
            message=message,
            person=self.adela)
        sc = SecondRoundCreator(self.tarapaca)
        sc.pick_one(self.adela)
        sc.pick_one(self.carlos)
        second_round = sc.get_second_round()
        the_copied_message = second_round.messages.get()
        self.assertNotEquals(the_copied_message.id, message.id)
        self.assertEquals(the_copied_message.author_name, message.author_name)
        self.assertEquals(the_copied_message.subject, message.subject)
        self.assertEquals(the_copied_message.content, message.content)
        the_copied_answer = the_copied_message.answers.get()
        self.assertNotEquals(the_copied_answer.id, answer.id)
        self.assertEquals(the_copied_answer.content, answer.content)
        self.assertEquals(the_copied_answer.person, self.adela)
예제 #4
0
    def test_create_a_second_round(self):
        sc = SecondRoundCreator(self.tarapaca)
        sc.pick_one(self.adela)
        sc.pick_one(self.carlos)
        self.assertEquals(sc.candidates[0], self.adela)
        self.assertEquals(sc.candidates[1], self.carlos)
        sc.set_name('second Round election')

        second_round = sc.get_second_round()

        self.assertIsInstance(second_round, Election)

        self.assertEquals(second_round.name, 'second Round election')
        self.assertNotEquals(second_round.slug, self.tarapaca.slug)
        self.assertEquals(second_round.candidates.count(), 2)
        self.assertIn(self.adela, second_round.candidates.all())
        self.assertIn(self.carlos, second_round.candidates.all())
예제 #5
0
    def test_candidate_get_absolute_url(self):
        sc = SecondRoundCreator(self.tarapaca)
        sc.pick_one(self.adela)
        sc.pick_one(self.carlos)

        second_round = sc.get_second_round()

        self.adela.refresh_from_db()

        self.assertIsNotNone(self.adela.get_absolute_url())
    def test_copy_messages_and_answers(self):
        candidate3 = Candidate.objects.get(id=6)
        message = Message.objects.create(election=self.tarapaca,
                                         author_name='author',
                                         author_email='*****@*****.**',
                                         subject='subject',
                                         content='content',
                                         slug=u'subject-slugified',
                                         accepted=True
                                         )
        message.people.add(self.adela)
        message.people.add(self.carlos)
        message.people.add(candidate3)

        answer = Answer.objects.create(content=u'Hey I\'ve had to speak english in the last couple of days',
                                       message=message,
                                       person=self.adela
                                       )
        sc = SecondRoundCreator(self.tarapaca)
        sc.pick_one(self.adela)
        sc.pick_one(self.carlos)
        second_round = sc.get_second_round()
        the_copied_message = second_round.messages.get()
        self.assertNotEquals(the_copied_message.id, message.id)
        self.assertEquals(the_copied_message.author_name, message.author_name)
        self.assertEquals(the_copied_message.subject, message.subject)
        self.assertEquals(the_copied_message.content, message.content)
        the_copied_answer = the_copied_message.answers.get()
        self.assertNotEquals(the_copied_answer.id, answer.id)
        self.assertEquals(the_copied_answer.content, answer.content)
        self.assertEquals(the_copied_answer.person, self.adela)
    def test_create_a_second_round(self):
        sc = SecondRoundCreator(self.tarapaca)
        sc.pick_one(self.adela)
        sc.pick_one(self.carlos)
        self.assertEquals(sc.candidates[0], self.adela)
        self.assertEquals(sc.candidates[1], self.carlos)
        sc.set_name('second Round election')

        second_round = sc.get_second_round()

        self.assertIsInstance(second_round, Election)

        self.assertEquals(second_round.name, 'second Round election')
        self.assertNotEquals(second_round.slug, self.tarapaca.slug)
        self.assertEquals(second_round.candidates.count(), 2)
        self.assertIn(self.adela, second_round.candidates.all())
        self.assertIn(self.carlos, second_round.candidates.all())
    def test_candidate_get_absolute_url(self):
        sc = SecondRoundCreator(self.tarapaca)
        sc.pick_one(self.adela)
        sc.pick_one(self.carlos)

        second_round = sc.get_second_round()

        self.adela.refresh_from_db()

        self.assertIsNotNone(self.adela.get_absolute_url())
 def test_copy_questions(self):
     sc = SecondRoundCreator(self.tarapaca)
     sc.pick_one(self.adela)
     sc.pick_one(self.carlos)
     second_round = sc.get_second_round()
     self.assertEquals(second_round.categories.count(), self.tarapaca.categories.count())
     for category in self.tarapaca.categories.all():
         _category = second_round.categories.get(name=category.name)
         self.assertEquals(_category.topics.count(), category.topics.count())
         for topic in category.topics.all():
             _topic = _category.topics.get(label=topic.label)
             self.assertTrue(TakenPosition.objects.filter(topic=_topic, person=self.adela))
             self.assertTrue(TakenPosition.objects.filter(topic=_topic, person=self.carlos))
             for position in topic.positions.all():
                 self.assertTrue(_topic.positions.filter(label=position.label))
예제 #10
0
 def test_copy_questions(self):
     sc = SecondRoundCreator(self.tarapaca)
     sc.pick_one(self.adela)
     sc.pick_one(self.carlos)
     second_round = sc.get_second_round()
     self.assertEquals(second_round.categories.count(),
                       self.tarapaca.categories.count())
     for category in self.tarapaca.categories.all():
         _category = second_round.categories.get(name=category.name)
         self.assertEquals(_category.topics.count(),
                           category.topics.count())
         for topic in category.topics.all():
             _topic = _category.topics.get(label=topic.label)
             self.assertTrue(
                 TakenPosition.objects.filter(topic=_topic,
                                              person=self.adela))
             self.assertTrue(
                 TakenPosition.objects.filter(topic=_topic,
                                              person=self.carlos))
             for position in topic.positions.all():
                 self.assertTrue(
                     _topic.positions.filter(label=position.label))