コード例 #1
0
    def testExistQuestionWithFailureOrdering(self):
        q = Question.objects.get(desc="Descripcion")
        q.save()

        q_order1 = QuestionOrdering(question=q,
                                    option="esta va a salir segunda",
                                    ordering=1)
        q_order1.save()
        q_order2 = QuestionOrdering(question=q,
                                    option="esta va a salir primera",
                                    ordering=2)
        q_order2.save()

        v = Voting(name="Prueba votacion ordenada", question=q)
        v.save()

        q_order1_postgres = Voting.objects.get(
            name="Prueba votacion ordenada").question.options_ordering.filter(
                option="esta va a salir segunda").get()
        q_order2_postgres = Voting.objects.get(
            name="Prueba votacion ordenada").question.options_ordering.filter(
                option="esta va a salir primera").get()

        self.assertNotEquals(q_order1_postgres.ordering, 2)
        self.assertNotEquals(q_order2_postgres.ordering, 1)
コード例 #2
0
    def test_get_voting_per_user(self):

        for i in range(2):
            q = Question(desc='test question')
            q.save()
            for j in range(5):
                opt = QuestionOption(question=q,
                                     option='option {}'.format(j + 1))
                opt.save()
            v = Voting(name='test voting', question=q, tipe='testType')
            v.save()

            a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                              defaults={
                                                  'me': True,
                                                  'name': 'test auth'
                                              })
            a.save()
            v.auths.add(a)

        u, _ = User.objects.get_or_create(username='******')
        u.is_active = True
        u.save()

        for v in Voting.objects.all():
            c = Census(voter_id=u.id, voting_id=v.id)
            c.save()

        response = self.client.get('/voting/user/?id={}'.format(u.id))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 2)
コード例 #3
0
ファイル: views.py プロジェクト: josvilgar1/decide-defensa
    def post(self, request, *args, **kwargs):
        self.permission_classes = (UserIsStaff, )
        self.check_permissions(request)
        for data in ['name', 'desc', 'question', 'question_opt']:
            if not data in request.data:
                return Response({}, status=status.HTTP_400_BAD_REQUEST)

        question = Question(desc=request.data.get('question'))
        question.save()
        for idx, q_opt in enumerate(request.data.get('question_opt')):
            opt = QuestionOption(question=question, option=q_opt, number=idx)
            opt.save()
        voting = Voting(name=request.data.get('name'),
                        desc=request.data.get('desc'),
                        question=question)
        voting.save()

        auth, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                             defaults={
                                                 'me': True,
                                                 'name': 'test auth'
                                             })
        auth.save()
        voting.auths.add(auth)
        return Response({}, status=status.HTTP_201_CREATED)
コード例 #4
0
    def create_voting(self):
        # Creation of questions test for the voting
        q = Question(desc='test question')
        q2 = Question(desc='test question 2')

        # Saving the questions before adding them to the voting
        q.save()
        q2.save()

        # Creation of question options per each question previouly created
        for i in range(5):
            opt = QuestionOption(question=q, option='option {}'.format(i + 1))
            opt.save()

        for n in range(5):
            opt2 = QuestionOption(question=q2, option='option {}'.format(n + 1))
            opt2.save()

        # Creation and storage of voting
        v = Voting(name='test voting', desc='testeo de voting')
        v.save()

        # Addition of the questions created to the voting
        v.questions.add(q)

        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={'me': True, 'name': 'test auth'})
        a.save()
        v.auths.add(a)

        return v
コード例 #5
0
ファイル: tests.py プロジェクト: davtorcueEGC/decide
 def test_create_multiquestion_preferences_voting(self):
     q1 = Question(desc='question1')
     q1.save()
     for i in range(5):
         opt = QuestionOption(question=q1, option='option {}'.format(i + 1))
         opt.save()
     q2 = Question(desc='preferences', preferences=True)
     q2.save()
     for i in range(5):
         opt = QuestionOption(question=q2, option='option {}'.format(i + 1))
         opt.save()
     v = Voting(name='test voting')
     v.save()
     a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                       defaults={
                                           'me': True,
                                           'name': 'test auth'
                                       })
     a.save()
     v.auths.add(a)
     v.question.add(q1)
     v.question.add(q2)
     a = v.question.all().count() == 2
     b = v.question.all()[1].preferences == True
     self.assertTrue(a, b)
コード例 #6
0
ファイル: tests.py プロジェクト: davtorcueEGC/decide
 def test_delete_yes_no_question_relacionada_stopped(self):
     q = Question(desc='si/no question', si_no=True)
     q.save()
     v = Voting(name='test voting')
     v.save()
     a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                       defaults={
                                           'me': True,
                                           'name': 'test auth'
                                       })
     a.save()
     v.auths.add(a)
     v.question.add(q)
     self.assertEqual(v.question.all().count(), 1)
     self.login()
     data = {'action': 'start'}
     response = self.client.put('/voting/{}/'.format(v.pk),
                                data,
                                format='json')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.json(), 'Voting started')
     data2 = {'action': 'stop'}
     response2 = self.client.put('/voting/{}/'.format(v.pk),
                                 data2,
                                 format='json')
     self.assertEqual(response2.status_code, 200)
     self.assertEqual(response2.json(), 'Voting stopped')
     q.delete()
     self.assertEqual(v.question.all().count(), 0)
コード例 #7
0
 def gen_voting(self, pk):
     voting = Voting(pk=pk,
                     name='v1',
                     question=self.question,
                     start_date=timezone.now(),
                     end_date=timezone.now() + datetime.timedelta(days=1))
     voting.save()
コード例 #8
0
ファイル: tests.py プロジェクト: davtorcueEGC/decide
 def setUp(self):
     q1 = Question(desc="test question1")
     q1.save()
     q2 = Question(desc="test question2")
     q2.save()
     q3 = Question(desc="test question3")
     q3.save()
     QuestionOption(question=q1, option="option1")
     QuestionOption(question=q1, option="option2")
     QuestionOption(question=q2, option="option3")
     QuestionOption(question=q2, option="option4")
     QuestionOption(question=q3, option="option5")
     QuestionOption(question=q3, option="option6")
     v = Voting(name="Votacion")
     v.save()
     a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                       defaults={
                                           'me': True,
                                           'name': 'test auth'
                                       })
     v.auths.add(a)
     v.question.add(q1)
     v.question.add(q2)
     v.question.add(q3)
     super().setUp()
コード例 #9
0
    def save(self):
        candidate_file = self.cleaned_data.get('candidate_file', None)
        df = Voting.checkInputFile(candidate_file)
        auth = Auth.objects.get_or_create(url=settings.BASEURL, name='Sys')[0]

        for name, group in df.groupby(['Provincia']):
            count = 2

            quest = Question(desc='Elige un máximo de 2 personas para las '
                             'listas al senado por ' + name)
            quest.save()

            voting_name = 'Votación Senado ' + name
            voting_desc = 'Listas al Senado por ' + name
            voting = Voting(name=voting_name, desc=voting_desc, question=quest)
            voting.save()
            voting.auths.add(auth)

            for row in group.iterrows():
                count += 1
                desc_option = row[1][5] + ': ' + \
                              row[1][0] + ' ' + row[1][1] + ' ' + row[1][2]

                quest_option = QuestionOption(number=count, option=desc_option)
                quest_option.question = quest
                quest_option.save()
コード例 #10
0
    def setUp(self):

        user = User(username='******', password='******')
        user.save()

        auth = Auth(name='prueba', url='localhost:8000')
        question = Question(desc='prueba')
        auth.save()
        question.save()
        voting = Voting(name='prueba', question=question)
        user.save()
        auth.save()
        question.save()
        voting.save()
        voting.auths.add(auth)
        voting.save()

        self.users = [
            user,
        ]
        self.test_auths = [
            auth,
        ]
        self.test_question = question
        self.test_census = Census(name='Prueba', voting_id=voting)
        self.test_census.save()
        self.test_census.voter_id.add(user)
        self.test_census.save()
コード例 #11
0
    def create_voting(self):
        v = Voting(name='test voting', postproc_type=PostProcType.IDENTITY)
        v.save()

        q1 = Question(desc='test question 1', voting=v)
        q1.save()
        for i in range(5):
            opt = QuestionOption(question=q1, option='option {}'.format(i + 1))
            opt.save()

        q2 = Question(desc='test question 2', voting=v)
        q2.save()
        for i in range(5):
            opt = QuestionOption(question=q2, option='option {}'.format(i + 1))
            opt.save()

        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={
                                              'me': True,
                                              'name': 'test auth'
                                          })
        a.save()
        v.auths.add(a)

        return v, q1, q2
コード例 #12
0
class VotingModelTC(BaseTestCase):
    def setUp(self):
        q = Question(desc="Descripcion", scopes="Geography")
        q.save()

        opt1 = QuestionOption(question=q, option="option1")
        opt1.save()

        opt2 = QuestionOption(question=q, option="option2")
        opt2.save()

        self.v = Voting(name="Votacion", question=q)
        self.v.save()
        super().setUp()

    def tearDown(self):
        super().tearDown()
        self.v = None

    def testExist(self):
        v = Voting.objects.get(name="Votacion")
        self.assertEquals(v.question.options.all()[0].option, "option1")
        self.assertEquals(v.question.options.all()[1].option, "option2")
        self.assertEquals(len(v.question.options.all()), 2)
        self.assertEquals(v.question.scopes, "Geography")

    def testCreateVotingAPI(self):
        self.login()
        data = {
            'name': 'Example',
            'themeVotation': 'Knowledge',
            'preference': 'High',
            'desc': 'Descripcion',
            'question': 'I wanna',
            'question_scopes': 'Geography',
            'question_opt': ['car', 'house', 'party']
        }

        response = self.client.post('/voting/', data, format='json')
        self.assertEqual(response.status_code, 201)

        v = Voting.objects.get(name="Example")
        self.assertEqual(v.desc, 'Descripcion')
        self.assertEqual(v.themeVotation, 'Knowledge')
        self.assertEqual(v.preference, 'High')
        self.assertEqual(v.question.scopes, 'Geography')

    def testCreateVotingUrlErroneaAPI(self):
        self.login()
        data = {
            'name': 'Example',
            'preference': 'High',
            'desc': 'Descripcion',
            'question': 'I wanna',
            'question_scopes': 'Geography',
            'question_opt': ['car', 'house', 'party']
        }

        response = self.client.post('/voting/edit/', data, format='json')
        self.assertEqual(response.status_code, 404)
コード例 #13
0
 def gen_voting(self, pk):
     voting = Voting(pk=pk,
                     name='v' + str(pk),
                     start_date=timezone.now(),
                     end_date=timezone.now() + datetime.timedelta(days=1))
     voting.save()
     voting.question.add(self.question)
     return voting
コード例 #14
0
 def gen_voting(self, pk):
     voting = Voting(pk=pk,
                     name='v1',
                     postproc_type=PostProcType.IDENTITY,
                     start_date=timezone.now(),
                     end_date=timezone.now() + datetime.timedelta(days=1))
     voting.save()
     q = Question(desc='qwerty', voting=voting)
     q.save()
コード例 #15
0
def view_article(request, pk):
    """
	A function to view an article. The function will check if the article belongs to group or
	community before displaying it. It displays whether the article belongs
	to group or community
	"""
    law = Law.objects.filter(article_id=pk)
    if (law.count() == 0):
        law = Law(article_id=pk)
        law.save()
    law = Law.objects.get(article_id=pk)
    if request.user.is_authenticated:
        voting = Voting.objects.filter(article_id=pk, user_id=request.user.id)
        if (voting.count() == 0):
            voting = Voting()
            voting.article_id = pk
            voting.user = request.user
            voting.upflag = False
            voting.downflag = False
            voting.save()
        voting = Voting.objects.get(article_id=pk, user_id=request.user.id)
    else:
        voting = Voting()
        voting.article_id = pk
        voting.upflag = False
        voting.downflag = False
    try:
        article = CommunityArticles.objects.get(article_id=pk)
        if article.article.state == States.objects.get(
                name='draft') and article.article.created_by != request.user:
            return redirect('home')
        count = article_watch(request, article.article)
    except CommunityArticles.DoesNotExist:
        try:
            article = GroupArticles.objects.get(article_id=pk)
            if article.article.state == States.objects.get(
                    name='draft'
            ) and article.article.created_by != request.user:
                return redirect('home')
            count = article_watch(request, article.article)
        except GroupArticles.DoesNotExist:
            raise Http404
    is_fav = ''
    if request.user.is_authenticated:
        is_fav = favourite.objects.filter(user=request.user,
                                          resource=pk,
                                          category='article').exists()

    return render(
        request, 'view_article.html', {
            'article': article,
            'count': count,
            'is_fav': is_fav,
            'art': voting,
            'law': law
        })
コード例 #16
0
ファイル: tests.py プロジェクト: javdc/prueba-decide
 def gen_voting(self, pk):
     voting = Voting(pk=pk,
                     blank_vote=1,
                     name='v1',
                     start_date=timezone.now(),
                     end_date=timezone.now() + datetime.timedelta(days=1))
     voting.save()
     politicalParty = PoliticalParty(name='Test Political Party',
                                     voting=voting)
     politicalParty.save()
コード例 #17
0
 def test_identity_view(self):
     voting = Voting(name='test 1', desc='r')
     voting.save()
     self.driver.get(f'{self.live_server_url}/admin/login/?next=/admin/')
     self.driver.set_window_size(1920, 1000)
     self.driver.find_element(By.ID, "id_username").click()
     self.driver.find_element(By.ID, "id_username").send_keys("admin")
     self.driver.find_element(By.ID, "id_password").send_keys("qwerty")
     self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER)
     self.driver.get(f'{self.live_server_url}/visualizer/100/')
コード例 #18
0
ファイル: tests.py プロジェクト: antnolang/decide
    def setUp(self):
        q1 = Question(desc='Elige un máximo de 2 personas para las listas del '
                           'senado por Ávila')
        q1.save()
        opt11 = QuestionOption(question=q1, option='PSOE: García Mata, Jaime',
                               gender='H')
        opt11.save()
        opt12 = QuestionOption(question=q1, option='PP: López Ugarte, Mohamed',
                               gender='H')
        opt12.save()
        opt13 = QuestionOption(question=q1, option='PP: Samaniego Nolé, María',
                               gender='M')
        opt13.save()
        opt14 = QuestionOption(question=q1, option='PP: Llanos  Plana, Josefa',
                               gender='M')
        opt14.save()
        opt15 = QuestionOption(question=q1, option='PP: Encinas Cuervo, Gonzo',
                               gender='H')
        opt15.save()

        q2 = Question(desc='Elige un máximo de 2 personas para las listas del '
                           'senado por Sevilla')
        q2.save()
        opt21 = QuestionOption(question=q2, option='PSOE: Núñez Mata, Mohamed',
                               gender='H')
        opt21.save()
        opt22 = QuestionOption(question=q2, option='PP: López Ugarte, Mohamed',
                               gender='H')
        opt22.save()
        opt23 = QuestionOption(question=q2, option='PP: Anguita Ruiz, María',
                               gender='M')
        opt23.save()
        opt24 = QuestionOption(question=q2, option='PP: Girón Plana, Jaime',
                               gender='H')
        opt24.save()
        opt25 = QuestionOption(question=q2, option='PP: Encinas Cuevas, Gonzo',
                               gender='H')
        opt25.save()

        v1 = Voting(name='Votación Senado Ávila', question=q1,
                    desc='Listas al Senado por Ávila')
        v1.save()

        v2 = Voting(name='Votación Senado Sevilla', question=q2,
                    desc='Listas al Senado por Sevilla')
        v2.save()

        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={'me': True,
                                                    'name': 'test auth'})
        a.save()
        v1.auths.add(a)
        v2.auths.add(a)
        super().setUp()
コード例 #19
0
 def test_statisticsWithLogin(self):
     voting = Voting(name='test 1', desc='r')
     voting.save()
     self.driver.get(f'{self.live_server_url}/admin/login/?next=/admin/')
     self.driver.set_window_size(1920, 1000)
     self.driver.find_element(By.ID, "id_username").click()
     self.driver.find_element(By.ID, "id_username").send_keys("decide")
     self.driver.find_element(By.ID,
                              "id_password").send_keys("practica1234")
     self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER)
     self.driver.get(f'{self.live_server_url}/visualizer/1/statistics')
コード例 #20
0
 def test_model_ejercicio1(self):
     q = Question(desc='Pregunta ejercicio 1')
     q.save()
     opt = QuestionOption(question=q, option='option 1')
     opt.save()
     opt2 = QuestionOption(question=q, option= 'option 2')
     opt2.save()
     v = Voting(name='Votacion ejercicio 1', question=q)
     v.save()
     vTest=Voting.objects.get(name='Votacion ejercicio 1')
     self.assertEqual(vTest.question,v.question)
     self.assertEqual(vTest.name,v.name)
コード例 #21
0
ファイル: tests.py プロジェクト: davtorcueEGC/decide
 def test_create_voting_with_yes_no_question(self):
     q = Question(desc='si/no question', si_no=True)
     q.save()
     v = Voting(name='test voting')
     v.save()
     a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                       defaults={
                                           'me': True,
                                           'name': 'test auth'
                                       })
     a.save()
     v.auths.add(a)
     v.question.add(q)
     self.assertEqual(v.question.all().count(), 1)
コード例 #22
0
    def test_yes_no_question(self):
        v = Voting(name='test voting', postproc_type=PostProcType.IDENTITY)
        v.save()

        q = Question(voting=v,
                     desc='yes/no test question',
                     yes_no_question=True)
        q.save()

        opts = list(q.options.all())

        self.assertEqual(len(opts), 2)
        self.assertEqual(opts[0].option, 'Si')
        self.assertEqual(opts[1].option, 'No')
コード例 #23
0
ファイル: tests.py プロジェクト: alvcascac/decide-votacion
    def create_voting(self):
        q = Question(desc='test question')
        q.save()
        for i in range(5):
            opt = QuestionOption(question=q, option='option {}'.format(i+1))
            opt.save()
        v = Voting(name='test voting', question=q, tipe='testType')
        v.save()

        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={'me': True, 'name': 'test auth'})
        a.save()
        v.auths.add(a)

        return v
コード例 #24
0
ファイル: tests.py プロジェクト: edubotdom/decide
    def create_order_voting(self):
        q = Question(desc='test ordering question')
        q.save()
        for i in range(5):
            opt = QuestionOrder(question=q, option='ordering option {}'.format(i+1), order_number='{}'.format(i+1))
            opt.save()
        v = Voting(name='test ordering voting', question=q)
        v.save()

        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={'me': True, 'name': 'test auth'})
        a.save()
        v.auths.add(a)

        return v
コード例 #25
0
ファイル: tests.py プロジェクト: davtorcueEGC/decide
 def test_transform_empty_question_in_voting_to_yes_no(self):
     q = Question(desc='si_no question', si_no=False)
     q.save()
     v = Voting(name='test voting')
     v.save()
     a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                       defaults={
                                           'me': True,
                                           'name': 'test auth'
                                       })
     a.save()
     v.auths.add(a)
     v.question.add(q)
     self.assertTrue(q.si_no == False)
     q.si_no = True
     self.assertTrue(q.si_no == True)
コード例 #26
0
ファイル: tests.py プロジェクト: davtorcueEGC/decide
 def test_edit_yes_no_question_desc_in_voting(self):
     q = Question(desc='si_no question', si_no=True)
     q.save()
     v = Voting(name='test voting')
     v.save()
     a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                       defaults={
                                           'me': True,
                                           'name': 'test auth'
                                       })
     a.save()
     v.auths.add(a)
     v.question.add(q)
     self.assertTrue(q.si_no == True)
     q.desc = 'si_no question modificada'
     self.assertTrue(q.desc == 'si_no question modificada')
コード例 #27
0
ファイル: tests.py プロジェクト: davtorcueEGC/decide
 def test_edit_yes_no_question_in_voting_add_opt(self):
     q = Question(desc='si_no question', si_no=True)
     q.save()
     v = Voting(name='test voting')
     v.save()
     a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                       defaults={
                                           'me': True,
                                           'name': 'test auth'
                                       })
     a.save()
     v.auths.add(a)
     v.question.add(q)
     self.assertTrue(q.si_no == True)
     opt = QuestionOption(question=q, option='option 3', number='3')
     self.assertRaises(ValidationError, opt.clean)
コード例 #28
0
ファイル: tests.py プロジェクト: josvilgar1/decide-defensa
    def setUp(self):
        # Create user
        self.client = APIClient()
        mods.mock_query(self.client)
        u = UserProfile(id=1, username='******', sex='M')
        u.set_password('123')
        u.save()
        token= mods.post('authentication', entry_point='/login/', json={'username':'******', 'password': '******'})
        # Add session token
        session = self.client.session
        session['user_token'] = token
        session.save()

        #Create voting

        #Create question 1
        q1 = Question(id=1,desc='Unique option question', option_types=1)
        q1.save()
        for i in range(3):
            opt = QuestionOption(question=q1, option='option {}'.format(i+1))
            opt.save()

        #Create question 2
        q2 = Question(id=2,desc='Multiple option question', option_types=2)
        q2.save()
        for i in range(4):
            opt = QuestionOption(question=q2, option='option {}'.format(i+1))
            opt.save()

        #Create question 3
        q3 = Question(id=3,desc='Rank order scale question', option_types=3)
        q3.save()
        for i in range(5):
            opt = QuestionOption(question=q3, option='option {}'.format(i+1))
            opt.save()

        v = Voting(id=1, name='Single question voting',desc='Single question voting...', points=1, start_date=timezone.now())
        v.save()
        v.question.add(q1), v.question.add(q2), v.question.add(q3)
        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={'me': True, 'name': 'base'})
        a.save()
        v.auths.add(a)
        Voting.create_pubkey(v)
        #Add user to census
        census = Census(voting_id=v.id, voter_id=u.id)
        census.save()
コード例 #29
0
ファイル: tests_selenium.py プロジェクト: davtorcueEGC/decide
    def setUp(self):

        self.client = APIClient()
        mods.mock_query(self.client)

        voter1 = User(username='******', id="2")
        voter1.set_password('voter')
        voter1.save()

        admin = User(username='******', is_staff=True)
        admin.set_password('admin')
        admin.is_superuser = True
        admin.save()

        q = Question(desc='Preferences question', preferences=True)
        q.save()
        for i in range(3):
            optPref = QuestionOption(question=q, option='option {}'.format(i+1))
            optPref.save()

        q1 = Question(desc='Simple question')
        q1.save()
        for i in range(3):
            optPref = QuestionOption(question=q1, option='option {}'.format(i+1))
            optPref.save()

        q2 = Question(desc='yes/no question', si_no=True)
        q2.save()

        v = Voting(name='test voting', id="2")
        v.save()

        v2= Voting(name='test voting yes no', id="3")
        v2.save()

        a, _ = Auth.objects.get_or_create(url=settings.BASEURL, defaults={'me': True, 'name': 'test auth'})
        a.save()

        v.auths.add(a)
        v.question.add(q)
        v2.auths.add(a)
        v2.question.add(q2)
        v.save()
        v2.save()

        census = Census(voting_id=2, voter_id=2)
        census.save()
        census2 = Census(voting_id=3, voter_id=2)
        census2.save()

        options = webdriver.ChromeOptions()
        options.add_argument('--no-sandbox')
        options.headless = True
        self.driver = webdriver.Chrome(options=options)

        super().setUp()
コード例 #30
0
ファイル: tests.py プロジェクト: davtorcueEGC/decide
 def test_create_onequestion_voting(self):
     q1 = Question(desc='question1')
     q1.save()
     for i in range(5):
         opt = QuestionOption(question=q1, option='option {}'.format(i + 1))
         opt.save()
     v = Voting(name='test voting')
     v.save()
     a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                       defaults={
                                           'me': True,
                                           'name': 'test auth'
                                       })
     a.save()
     v.auths.add(a)
     v.question.add(q1)
     self.assertEqual(v.question.all().count(), 1)
コード例 #31
0
ファイル: views.py プロジェクト: xoneco/ajax_pusher_voting
def new_counter(request):
    row_add = Voting(total_votes=0, score=0)
    row_add.save()
    return render(request, "voting/done.html")