def test_parse_csv_file(self): header, data_rows = publish_hits.parse_csv_file(self.csv_file) rows = [row for row in data_rows] self.assertEqual( [u'h0', u'h1'], header ) self.assertEqual( [ [u'é0', u'ñ0'], [u'é1, e1', u'ñ1'], ], rows ) ht = HitTemplate(name='test', form="<p></p>") ht.save() hit = Hit.objects.create( template=ht, input_csv_fields=dict(zip(header, rows[1])), ) expect = {u"h0": u"é1, e1", u"h1": u"ñ1"} actual = hit.input_csv_fields self.assertEqual(expect, actual)
def setUp(self): with open('hits/tests/resources/form_0.html') as f: form = f.read().decode('utf-8') self.hit_template = HitTemplate(name="filepath", form=form) self.hit_template.save() field_names = u"tweet0_id,tweet0_entity,tweet0_before_entity,tweet0_after_entity,tweet0_word0,tweet0_word1,tweet0_word2,tweet1_id,tweet1_entity,tweet1_before_entity,tweet1_after_entity,tweet1_word0,tweet1_word1,tweet1_word2,tweet2_id,tweet2_entity,tweet2_before_entity,tweet2_after_entity,tweet2_word0,tweet2_word1,tweet2_word2,tweet3_id,tweet3_entity,tweet3_before_entity,tweet3_after_entity,tweet3_word0,tweet3_word1,tweet3_word2,tweet4_id,tweet4_entity,tweet4_before_entity,tweet4_after_entity,tweet4_word0,tweet4_word1,tweet4_word2,tweet5_id,tweet5_entity,tweet5_before_entity,tweet5_after_entity,tweet5_word0,tweet5_word1,tweet5_word2", values = u"268,SANTOS, Muy bien America ......... y lo siento mucho , un muy buen rival,mucho, , ,2472,GREGORY, Ah bueno , tampoco andes pidiendo ese tipo de milagros . @jcabrerac @CarlosCabreraR,bueno, , ,478,ALEJANDRO, @aguillen19 , un super abrazo mi querido , , mis mejores deseos para este 2012 ... muakkk !,querido, , ,906_control, PF, Acusan camioneros extorsiones de, : Transportistas acusaron que deben pagar entre 13 y 15 mil pesos a agentes que .. http://t.co/d8LUVvhP,acusaron, , ,2793_control, CHICARO, Me gusta cuando chicharo hace su oracion es lo que lo hace especial ., ,gusta, , ,357,OSCAR WILDE", " @ ifilosofia : Las pequeñas acciones de cada día son las que hacen o deshacen el carácter." , bueno !!!! Es así,bueno, , ", self.hit = Hit( template=self.hit_template, input_csv_fields=dict(zip(field_names, values)) ) self.hit.save()
def setUp(self): """ Sets up HitTemplate, Hit objects, and saves them to the DB. The HitTemplate is bare, the Hit has inputs and answers and refers to the HitTemplate form. """ form = HitTemplate(name='test', form="<p></p>") form.save() hit = Hit( template=form, input_csv_fields={u'foo': u'bar'}, answers={ u"comment": u"\u221e", u"userDisplayLanguage": u"", u"sentence_textbox_3_verb1": u"", u"city": u"", u"sentence_textbox_1_verb6": u"", u"sentence_textbox_1_verb7": u"", u"sentence_textbox_1_verb4": u"", u"sentence_textbox_1_verb5": u"", u"sentence_textbox_1_verb2": u"", u"sentence_textbox_1_verb3": u"", u"sentence_textbox_1_verb1": u"", u"sentence_textbox_2_verb4": u"", u"csrfmiddlewaretoken": u"7zxQ9Yyug6Nsnm4nLky9p8ObJwNipdu8", u"sentence_drop_2_verb3": u"foo", u"sentence_drop_2_verb2": u"foo", u"sentence_drop_2_verb1": u"foo", u"sentence_textbox_2_verb1": u"", u"sentence_textbox_2_verb3": u"", u"sentence_drop_2_verb4": u"foo", u"sentence_textbox_2_verb2": u"", u"submitit": u"Submit", u"browserInfo": u"", u"sentence_drop_1_verb1": u"foo", u"sentence_drop_1_verb2": u"foo", u"sentence_drop_1_verb3": u"foo", u"sentence_drop_1_verb4": u"foo", u"sentence_drop_1_verb5": u"foo", u"sentence_drop_1_verb6": u"foo", u"sentence_drop_1_verb7": u"foo", u"country": u"", u"sentence_drop_3_verb1": u"foo", u"ipAddress": u"", u"region": u"" }, completed=True, ) hit.save() self.hit = hit
def test_map_fields_csv_row(self): hit_template = HitTemplate( name='test', form=u"""</select> con relación a <span style="color: rgb(0, 0, 255);">${tweet0_entity}</span> en este mensaje.</p>""" ) hit_template.save() hit = Hit( template=hit_template, input_csv_fields=dict( zip( [u"tweet0_id", u"tweet0_entity"], [u"268", u"SANTOS"], ) ), ) hit.save() expect = """<div style=" width:100%; border:2px solid black; margin-top:10px"><div style="width:100%; margin:10px"></select> con relación a <span style="color: rgb(0, 0, 255);">SANTOS</span> en este mensaje.</p></div></div>""" actual = hit.generate_form() self.assertEqual(expect, actual)
class TestGenerateForm(django.test.TestCase): def setUp(self): with open('hits/tests/resources/form_0.html') as f: form = f.read().decode('utf-8') self.hit_template = HitTemplate(name="filepath", form=form) self.hit_template.save() field_names = u"tweet0_id,tweet0_entity,tweet0_before_entity,tweet0_after_entity,tweet0_word0,tweet0_word1,tweet0_word2,tweet1_id,tweet1_entity,tweet1_before_entity,tweet1_after_entity,tweet1_word0,tweet1_word1,tweet1_word2,tweet2_id,tweet2_entity,tweet2_before_entity,tweet2_after_entity,tweet2_word0,tweet2_word1,tweet2_word2,tweet3_id,tweet3_entity,tweet3_before_entity,tweet3_after_entity,tweet3_word0,tweet3_word1,tweet3_word2,tweet4_id,tweet4_entity,tweet4_before_entity,tweet4_after_entity,tweet4_word0,tweet4_word1,tweet4_word2,tweet5_id,tweet5_entity,tweet5_before_entity,tweet5_after_entity,tweet5_word0,tweet5_word1,tweet5_word2", values = u"268,SANTOS, Muy bien America ......... y lo siento mucho , un muy buen rival,mucho, , ,2472,GREGORY, Ah bueno , tampoco andes pidiendo ese tipo de milagros . @jcabrerac @CarlosCabreraR,bueno, , ,478,ALEJANDRO, @aguillen19 , un super abrazo mi querido , , mis mejores deseos para este 2012 ... muakkk !,querido, , ,906_control, PF, Acusan camioneros extorsiones de, : Transportistas acusaron que deben pagar entre 13 y 15 mil pesos a agentes que .. http://t.co/d8LUVvhP,acusaron, , ,2793_control, CHICARO, Me gusta cuando chicharo hace su oracion es lo que lo hace especial ., ,gusta, , ,357,OSCAR WILDE", " @ ifilosofia : Las pequeñas acciones de cada día son las que hacen o deshacen el carácter." , bueno !!!! Es así,bueno, , ", self.hit = Hit( template=self.hit_template, input_csv_fields=dict(zip(field_names, values)) ) self.hit.save() def test_generate_form(self): with open('hits/tests/resources/form_0_filled.html') as f: form = f.read().decode('utf-8') expect = form actual = self.hit.generate_form() self.assertNotEqual(expect, actual) def test_map_fields_csv_row(self): hit_template = HitTemplate( name='test', form=u"""</select> con relación a <span style="color: rgb(0, 0, 255);">${tweet0_entity}</span> en este mensaje.</p>""" ) hit_template.save() hit = Hit( template=hit_template, input_csv_fields=dict( zip( [u"tweet0_id", u"tweet0_entity"], [u"268", u"SANTOS"], ) ), ) hit.save() expect = """<div style=" width:100%; border:2px solid black; margin-top:10px"><div style="width:100%; margin:10px"></select> con relación a <span style="color: rgb(0, 0, 255);">SANTOS</span> en este mensaje.</p></div></div>""" actual = hit.generate_form() self.assertEqual(expect, actual)
def test_parse_csv_file(self): header, data_rows = publish_hits.parse_csv_file(self.csv_file) rows = [row for row in data_rows] self.assertEqual([u'h0', u'h1'], header) self.assertEqual([ [u'é0', u'ñ0'], [u'é1, e1', u'ñ1'], ], rows) ht = HitTemplate(name='test', form="<p></p>") ht.save() hit = Hit.objects.create( template=ht, input_csv_fields=dict(zip(header, rows[1])), ) expect = {u"h0": u"é1, e1", u"h1": u"ñ1"} actual = hit.input_csv_fields self.assertEqual(expect, actual)
def setUp(self): template = HitTemplate(name='foo', form='<p></p>') template.save() self.hit = Hit(template=template, input_csv_fields='{}') self.hit.save()