def test_delete_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) v.save() a, _ = Auth.objects.get_or_create(url=settings.BASEURL, defaults={ 'me': True, 'name': 'test auth' }) a.save() v.auths.add(a) v.delete()
def create_voting_custom_url(self): q = Question(desc='new test question') q.save() for i in range(5): opt = QuestionOption(question=q, option='option {}'.format(i + 1)) opt.save() v = Voting(name='new test voting', question=q, customURL='custom') 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
def setUp(self): q = Question(desc='question') q.save() opt1 = QuestionOption(question=q, option='uno') opt1.save() opt2 = QuestionOption(question=q, option='dos') opt2.save() v = Voting(name='VotingTest', desc='Description', question=q) self.v = v self.v.save() super().setUp()
def test_no_political_party_voting_senate(self): u = User(username='******') u.set_password('senator') u.save() q = Question(desc='Choose') q.save() opt = QuestionOption(question=q, option='senator') opt.save() political_party = PoliticalParty(name='Partido Popular', acronym='PP', description='test', headquarters='test') political_party.save() birthdate = date(2000, 2, 28) userProfile = UserProfile(related_political_party=political_party, birthdate=birthdate, sex='F', related_user=u, province='S', employment='S') userProfile.save() v = Voting(name='test voting', question=q, tipe='S', province='S', political_party=political_party) v.save() a, _ = Auth.objects.get_or_create(url=settings.BASEURL, defaults={ 'me': True, 'name': 'test auth' }) a.save() v.auths.add(a) self.assertRaises(ValidationError, v.clean)
def create_voting(self): self.q = Question(desc='Prueba votación') self.q.save() for i in range(2): opt = QuestionOption(question=self.q, option='Opción {}'.format(i + 1)) opt.save() self.v = Voting(name='Prueba votación', question=self.q, slug="prueba") self.v.save() self.a, _ = Auth.objects.get_or_create(url=settings.BASEURL, defaults={ 'me': True, 'name': 'test auth' }) self.a.save() self.v.auths.add(self.a) self.v.create_pubkey() self.v.start_date = timezone.now() self.v.save()
def test_transform_question_in_voting_with_one_option_to_yes_no(self): q = Question(desc='si_no question', si_no=False) q.save() opt = QuestionOption(question=q, option='option 3', number='3') 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(q) self.assertTrue(q.si_no == False) q.si_no = True self.assertTrue(q.si_no == True) self.assertRaises(ValidationError, opt.clean)
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)
def create_voting_senate_primaries(self): u = User(username='******') u.set_password('123') u.save() q = Question(desc='test question') q.save() opt = QuestionOption(question=q, option='senator') opt.save() political_party = PoliticalParty(name='for senator', acronym='test', description='test', headquarters='test') political_party.save() birthdate = date(2000, 2, 28) userProfile = UserProfile(related_political_party=political_party, birthdate=birthdate, sex='F', related_user=u, province='S', employment='B') userProfile.save() v = Voting(name='test voting', question=q, tipe='SP', political_party=political_party) 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
def setUp(self): q = Question(desc="Descripcion") q.save() opt1 = QuestionOption(question=q, option="option1") opt1.save() opt2 = QuestionOption(question=q, option="option2") opt2.save() self.v = ReadonlyVoting(name="Votacion", question=q, desc="example") self.v.save() super().setUp()
def create_wrong_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, min_age="0", max_age="354") 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
def setUp(self): super().setUp() self.question = Question(id=1, desc='test question', option_types=2) self.question.save() for i in range(5): opt = QuestionOption(question=self.question, option='option {}'.format(i + 1)) opt.save() self.voting = Voting(id=5001, name='test voting') self.voting.save() self.voting.question.add(self.question) a, _ = Auth.objects.get_or_create(url=settings.BASEURL, defaults={ 'me': True, 'name': 'test auth' }) a.save() self.voting.auths.add(a)
def setUp(self): q = Question(desc="Descripción") q.save() opt1 = QuestionOption(question=q, option="option1") opt1.save() opt2 = QuestionOption(question=q, option="option2") opt2.save() self.v = Voting(name="Votación", question=q) self.v.save() super().setUp()
def create_voting(self): q = Question(desc='test question', scopes='Geography') 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, themeVotation='Survey', preference='Low') 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
def test_delete_preferences_question(self): q = Question(desc='Preferences question', preferences=True) q.save() for i in range(2): optPref = QuestionOption(question=q, option='option {}'.format(i + 1)) optPref.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) v.save() self.assertTrue(v.question.count() == 1) v.question.remove(q) self.assertTrue(v.question.count() == 0)
def test_adding_question_to_voting_multiquestion(self): q1 = Question(desc="test question1") q1.save() q2 = Question(desc="test question2") q2.save() QuestionOption(question=q1, option="option1") QuestionOption(question=q1, option="option2") QuestionOption(question=q2, option="option3") QuestionOption(question=q2, option="option4") 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) self.assertEquals(v.question.all().count(), 1) v.question.add(q2) self.assertEquals(v.question.all().count(), 2)
def setUp(self): q = Question(desc="Descripcion") q.save() que1 = Question(desc="Descripcion1") que1.save() que2 = Question(desc="Descripcion2") que2.save() opt1 = QuestionOption(question=q, option="option1") opt1.save() opt2 = QuestionOption(question=q, option="option2") opt2.save() q_prefer = QuestionPrefer(question=q, prefer="YES", number=4, option="option1") q_prefer.save() q_ordering = QuestionOrdering(question=q, number=5, option="prueba de ordenacion", ordering=1) q_ordering.save() party1 = Party(abreviatura="PC") party1.save() self.candidate1 = Candidate(name="test", age=21, number=1, auto_community="AN", sex="H", political_party=party1) self.candidate1.save() self.v1 = ReadonlyVoting(name="VotacionRO", question=que1, desc="example") self.v2 = MultipleVoting(name="VotacionM", desc="example") self.v2.save() self.v2.question.add(que1) self.v2.question.add(que2) self.v = Voting(name="Votacion", question=q) self.v.save() self.v1.save() self.v2.save() super().setUp()
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()
def test_automatic_number_assignment_of_question_and_questionoption(self): v = Voting(name='test voting', postproc_type=PostProcType.IDENTITY) v.save() for q in range(3): quest = Question(voting=v, desc='question {}'.format(q)) quest.save() for o in range(3): opt = QuestionOption(question=quest, option='option {}'.format(o)) opt.save() questions = list(v.questions.all()) q1 = questions[0] q1opts = list(q1.options.all()) self.assertEqual(q1.number, 1) self.assertEqual(q1opts[0].number, 1) self.assertEqual(q1opts[1].number, 2) self.assertEqual(q1opts[2].number, 3) q2 = questions[1] q2opts = list(q2.options.all()) self.assertEqual(q2.number, 2) self.assertEqual(q2opts[0].number, 4) self.assertEqual(q2opts[1].number, 5) self.assertEqual(q2opts[2].number, 6) q3 = questions[2] q3opts = list(q3.options.all()) self.assertEqual(q3.number, 3) self.assertEqual(q3opts[0].number, 7) self.assertEqual(q3opts[1].number, 8) self.assertEqual(q3opts[2].number, 9)
def test_create_multiquestion_si_no_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='question si/no', si_no=True) q2.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].si_no == True self.assertTrue(a, b)
class QuestionOptionTest(TestCase): def setUp(self): self.test_question = Question(desc = "Descripción de prueba", escaños = 360) self.test_question.save() self.test_questionOption = QuestionOption(question = self.test_question, number = 2, option="Prueba option", sexo = 'MUJER') self.test_questionOption.save() def test_quiestionoption_creation(self): self.assertEquals(self.test_questionOption.question, self.test_question) self.assertEquals(self.test_questionOption.number, 2 ) self.assertEquals(self.test_questionOption.option, "Prueba option") self.assertEquals(self.test_questionOption.sexo, "MUJER") def test_str_question(self): self.assertEquals(str(self.test_questionOption), "Prueba option (2)") def tearDown(self): self.test_question.delete() self.test_questionOption.delete()
def test_unique_voting_preference(self): q = Question(desc='Preferences question', preferences=True) q.save() for i in range(2): optPref = QuestionOption(question=q, option='option {}'.format(i + 1)) optPref.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) v.save() self.assertTrue(v.question.all()[0].preferences == True) self.assertEquals(v.question.all()[0].options.all()[0].option, "option 1") self.assertEquals(v.question.all()[0].options.all()[1].option, "option 2")
def create_voting_other(self): q = Question(desc='test yes/no question', yes_no_question=True) q.save() opt = QuestionOption(question=q) opt.save() v = Voting(name='test Other voting', desc='vamos a realizar una encuesta popular', question=q, tipe='O') 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
def test_create_presidential_voting(self): self.create_user() q = Question(desc='Who do you want to be the president?') q.save() opt = QuestionOption(question=q, option='president') opt.save() v = Voting(name='Presidential Voting', question=q, tipe='P') v.save() a, _ = Auth.objects.get_or_create(url=settings.BASEURL, defaults={ 'me': True, 'name': 'test auth' }) a.save() v.auths.add(a) v.clean() v.save() self.assertEqual(True, True)
def create_binary_voting(self): q = Question(desc='binary question') q.save() opt = QuestionOption(question=q, option='', yes=True, no=False) opt.save() opt2 = QuestionOption(question=q, option='', yes=False, no=True) opt2.save() v = Voting(name='test 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
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) v.questions.add(q2) a, _ = Auth.objects.get_or_create(url=settings.BASEURL, defaults={ 'me': True, 'name': 'test auth' }) a.save() v.auths.add(a) return v
class VotingTestCase(BaseTestCase): def setUp(self): super().setUp() self.newObject = Question(desc='test') self.newObject.save() self.opt = QuestionOption(question=self.newObject, option='1', yes=True, no=False) self.opt.save() self.opt2 = QuestionOption(question=self.newObject, option='2', yes=False, no=True) self.opt2.save() def tearDown(self): super().tearDown() self.question = None self.questionOption = None def test_store_question(self): self.assertEqual(Question.objects.count(), 1) def test_store_questionOptions(self): self.assertEqual(QuestionOption.objects.count(), 2) def encrypt_msg(self, msg, v, bits=settings.KEYBITS): pk = v.pub_key p, g, y = (pk.p, pk.g, pk.y) k = MixCrypt(bits=bits) k.k = ElGamal.construct((p, g, y)) return k.encrypt(msg) 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), yes=False, no=False) opt.save() v = Voting(name='test 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 def create_binary_voting(self): q = Question(desc='binary question') q.save() opt = QuestionOption(question=q, option='', yes=True, no=False) opt.save() opt2 = QuestionOption(question=q, option='', yes=False, no=True) opt2.save() v = Voting(name='test 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 def create_voters(self, v): for i in range(100): u, _ = User.objects.get_or_create(username='******'.format(i)) u.is_active = True u.save() c = Census(voter_id=u.id, voting_id=v.id) c.save() def get_or_create_user(self, pk): user, _ = User.objects.get_or_create(pk=pk) user.username = '******'.format(pk) user.set_password('qwerty') user.save() return user def store_votes(self, v): voters = list(Census.objects.filter(voting_id=v.id)) voter = voters.pop() clear = {} for opt in v.question.options.all(): clear[opt.number] = 0 for i in range(random.randint(0, 5)): a, b = self.encrypt_msg(opt.number, v) data = { 'voting': v.id, 'voter': voter.voter_id, 'vote': { 'a': a, 'b': b }, } clear[opt.number] += 1 user = self.get_or_create_user(voter.voter_id) self.login(user=user.username) voter = voters.pop() mods.post('store', json=data) return clear def test_complete_voting(self): v = self.create_voting() self.create_voters(v) v.create_pubkey() v.start_date = timezone.now() v.save() clear = self.store_votes(v) self.login() # set token v.tally_votes(self.token) tally = v.tally tally.sort() tally = {k: len(list(x)) for k, x in itertools.groupby(tally)} for q in v.question.options.all(): self.assertEqual(tally.get(q.number, 0), clear.get(q.number, 0)) for q in v.postproc: self.assertEqual(tally.get(q["number"], 0), q["votes"]) def test_complete_binary_voting(self): v = self.create_binary_voting() self.create_voters(v) v.create_pubkey() v.start_date = timezone.now() v.save() clear = self.store_votes(v) self.login() # set token v.tally_votes(self.token) tally = v.tally tally.sort() tally = {k: len(list(x)) for k, x in itertools.groupby(tally)} for q in v.question.options.all(): self.assertEqual(tally.get(q.number, 0), clear.get(q.number, 0)) for q in v.postproc: self.assertEqual(tally.get(q["number"], 0), q["votes"]) def test_create_voting_from_api(self): data = {'name': 'Example'} response = self.client.post('/voting/', data, format='json') self.assertEqual(response.status_code, 401) # login with user no admin self.login(user='******') response = mods.post('voting', params=data, response=True) self.assertEqual(response.status_code, 403) # login with user admin self.login() response = mods.post('voting', params=data, response=True) self.assertEqual(response.status_code, 400) data = { 'name': 'Example', 'desc': 'Description example', 'question': 'I want a ', 'question_opt': ['cat', 'dog', 'horse'] } response = self.client.post('/voting/', data, format='json') self.assertEqual(response.status_code, 201) def test_update_voting(self): voting = self.create_voting() data = {'action': 'start'} #response = self.client.post('/voting/{}/'.format(voting.pk), data, format='json') #self.assertEqual(response.status_code, 401) # login with user no admin self.login(user='******') response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 403) # login with user admin self.login() data = {'action': 'bad'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) # STATUS VOTING: not started for action in ['stop', 'tally']: data = {'action': action} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting is not started') data = {'action': 'start'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 200) self.assertEqual(response.json(), 'Voting started') # STATUS VOTING: started data = {'action': 'start'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting already started') data = {'action': 'tally'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting is not stopped') data = {'action': 'stop'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 200) self.assertEqual(response.json(), 'Voting stopped') # STATUS VOTING: stopped data = {'action': 'start'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting already started') data = {'action': 'stop'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting already stopped') data = {'action': 'tally'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 200) self.assertEqual(response.json(), 'Voting tallied') # STATUS VOTING: tallied data = {'action': 'start'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting already started') data = {'action': 'stop'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting already stopped') data = {'action': 'tally'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting already tallied') def test_update_binary_voting(self): voting = self.create_binary_voting() #Nota: en esencia es el mismo test que update_voting, pero es necesario para probar las # diferentes posibles interacciones del sistema con las nuevas opciones en las pregutas. data = {'action': 'start'} #response = self.client.post('/voting/{}/'.format(voting.pk), data, format='json') #self.assertEqual(response.status_code, 401) # login with user no admin self.login(user='******') response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 403) # login with user admin self.login() data = {'action': 'bad'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) # STATUS VOTING: not started for action in ['stop', 'tally']: data = {'action': action} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting is not started') data = {'action': 'start'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 200) self.assertEqual(response.json(), 'Voting started') # STATUS VOTING: started data = {'action': 'start'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting already started') data = {'action': 'tally'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting is not stopped') data = {'action': 'stop'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 200) self.assertEqual(response.json(), 'Voting stopped') # STATUS VOTING: stopped data = {'action': 'start'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting already started') data = {'action': 'stop'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting already stopped') data = {'action': 'tally'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 200) self.assertEqual(response.json(), 'Voting tallied') # STATUS VOTING: tallied data = {'action': 'start'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting already started') data = {'action': 'stop'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting already stopped') data = {'action': 'tally'} response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), 'Voting already tallied')
def setUp(self): self.booth = BoothTests() self.booth.setUp() options = webdriver.ChromeOptions() options.headless = True self.driver = webdriver.Chrome(options=options) 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() 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() 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() a, _ = Auth.objects.get_or_create(url=settings.BASEURL, defaults={ 'me': True, 'name': 'base' }) a.save() v2 = Voting(id=2, name='Rank question voting', desc='Rank question voting...', points=1, start_date=timezone.now()) v2.save() v2.question.add(q3) v3 = Voting(id=3, name='Multiple question voting', desc='Multiple question voting...', points=1, start_date=timezone.now()) v3.save() v3.question.add(q2) v2.auths.add(a) Voting.create_pubkey(v2) #Add user to census census = Census(voting_id=v2.id, voter_id=u.id) census.save() v3.auths.add(a) Voting.create_pubkey(v3) #Add user to census census = Census(voting_id=v3.id, voter_id=u.id) census.save() super().setUp()
def setUp(self): self.test_question = Question(desc = "Descripción de prueba", escaños = 360) self.test_question.save() self.test_questionOption = QuestionOption(question = self.test_question, number = 2, option="Prueba option", sexo = 'MUJER') self.test_questionOption.save()
def setUp(self): #Create user 1 self.client = APIClient() mods.mock_query(self.client) u1 = UserProfile(id=1, username='******', sex='M') u1.set_password('123') u1.save() token1 = mods.post('authentication', entry_point='/login/', json={'username':'******', 'password': '******'}) #Add session token 1 session = self.client.session session['user_token'] = token1 session['voter_id'] = u1.id session.save() #Create voting 1 #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() v1 = Voting(id=1, name='Single question voting',desc='Single question voting...', points=1, start_date=timezone.now()) v1.save() v1.question.add(q1), v1.question.add(q2), v1.question.add(q3) a, _ = Auth.objects.get_or_create(url=settings.BASEURL, defaults={'me': True, 'name': 'base'}) a.save() v1.auths.add(a) Voting.create_pubkey(v1) #Create voting 2 #Create question 4 q4 = Question(id=4, desc='Unique option question 2', option_types=1) q4.save() for i in range(3): opt = QuestionOption(question=q4, option='option {}'.format(i+1)) opt.save() #Create question 5 q5 = Question(id=5, desc='Multiple option question 2', option_types=2) q5.save() for i in range(4): opt = QuestionOption(question=q5, option='option {}'.format(i+1)) opt.save() #Create question 6 q6 = Question(id=6, desc='Rank order scale question 2', option_types=3) q6.save() for i in range(5): opt = QuestionOption(question=q6, option='option {}'.format(i+1)) opt.save() v2 = Voting(id=2, name='Single question voting 2',desc='Single question voting...', points=1, start_date=M_DATE, end_date=E_DATE) v2.save() v2.question.add(q4), v2.question.add(q5), v2.question.add(q6) v2.auths.add(a) Voting.create_pubkey(v2) #Add user to census census1 = Census(voting_id=v1.id, voter_id=u1.id) census1.save() census2 = Census(voting_id=v2.id, voter_id=u1.id) census2.save() #Create suggestion 1 s1 = SuggestingForm(id=1, user_id=u1.id, title="Suggesting title", suggesting_date=S_DATE, content="Suggesting content...", send_date=NOW_DATE, is_approved=True) s1.save()
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()