Esempio n. 1
0
 def test_assess_coding_neutral_and_empty(self):
     j1 = JobAd("irrelevant words")
     self.assertFalse(j1.masculine_word_count)
     self.assertFalse(j1.feminine_word_count)
     self.assertEqual(j1.coding, "empty")
     j2 = JobAd("sharing versus aggression")
     self.assertEqual(j2.masculine_word_count, j2.feminine_word_count)
     self.assertEqual(j2.coding, "neutral")
Esempio n. 2
0
    def test_list_words(self):
        text = Text(u"leader leader leader, ambition, ambition, competition")
        j1 = JobAd(text, "", "", "")

        masc_words, fem_words = j1.list_words()
        self.assertEqual(
            masc_words,
            ['leader (3 times)', 'ambition (2 times)', 'competition'])
Esempio n. 3
0
    def test_process_ad(self):
        ad = JobAd(u"Sharing: ambition\tkindness&empathy(never more than frou)"
                   " Who is Connect@HBS? leader-supporter-follower "
                   "aggresive/responsible;understand? connect")
        CodedWordCounter.process_ad(ad)
        counters = CodedWordCounter.query.filter_by(ad_hash=ad.hash).all()
        self.assertEqual(len(counters), 9)

        masc_coded_words = sorted([
            counter.word for counter in counters
            if counter.coding == 'masculine'
        ])
        fem_coded_words = sorted([
            counter.word for counter in counters
            if counter.coding == 'feminine'
        ])
        self.assertEqual(masc_coded_words, ['ambition', 'leader'])
        self.assertEqual(fem_coded_words, [
            'connect', 'empathy', 'kindness', 'responsible', 'sharing',
            'supporter', 'understand'
        ])

        # test the deletion step works
        CodedWordCounter.process_ad(ad)
        counters = CodedWordCounter.query.filter_by(ad_hash=ad.hash).all()
        self.assertEqual(len(counters), 9)
        total_count = sum([counter.count for counter in counters])
        self.assertEqual(total_count, 10)
Esempio n. 4
0
 def test_clean_up_word_list_in_another_language(self):
     translated_wordlists = TranslatedWordlist("test")
     caps = JobAd("Fancy some sourdough, sake&glendronach or a sun-downer?")
     self.assertEqual(
         caps.clean_up_word_list(translated_wordlists),
         [
             "fancy",
             "some",
             "sourdough",
             "sake",
             "glendronach",
             "or",
             "a",
             "sun-downer",
         ],
     )
Esempio n. 5
0
def home():
    form = JobAdForm()
    if request.method == "POST" and form.validate_on_submit():
        ad = JobAd(form.texttotest.data, form.language.data)
        return redirect("results/{0}".format(ad.hash))
    return render_template(
        "home.html", form=form, number_of_languages=len(wordlists.__all__)
    )
Esempio n. 6
0
 def test_extract_coded_words(self):
     j1 = JobAd(u"Ambition:competition–decisiveness, empathy&kindness")
     self.assertEqual(j1.masculine_coded_words,
         "ambition,competition,decisiveness")
     self.assertEqual(j1.masculine_word_count, 3)
     self.assertEqual(j1.feminine_coded_words, "empathy,kindness")
     self.assertEqual(j1.feminine_word_count, 2)
     j2 = JobAd(u"empathy&kindness")
     self.assertEqual(j2.masculine_coded_words, "")
     self.assertEqual(j2.masculine_word_count, 0)
     self.assertEqual(j2.feminine_coded_words, "empathy,kindness")
     self.assertEqual(j2.feminine_word_count, 2)
     j3 = JobAd(u"empathy irrelevant words kindness")
     self.assertEqual(j3.masculine_coded_words, "")
     self.assertEqual(j3.masculine_word_count, 0)
     self.assertEqual(j3.feminine_coded_words, "empathy,kindness")
     self.assertEqual(j3.feminine_word_count, 2)
Esempio n. 7
0
 def test_assess_coding_feminine(self):
     j1 = JobAd(u"Ambition:competition, empathy&kindness, co-operation")
     self.assertEqual(j1.masculine_word_count, 2)
     self.assertEqual(j1.feminine_word_count, 3)
     self.assertEqual(j1.coding, "feminine-coded")
     j2 = JobAd(u"empathy&kindness, co-operation and some other words")
     self.assertEqual(j2.masculine_word_count, 0)
     self.assertEqual(j2.feminine_word_count, 3)
     self.assertEqual(j2.coding, "feminine-coded")
     j3 = JobAd(u"empathy&kindness, co-operation, trust and other words")
     self.assertEqual(j3.masculine_word_count, 0)
     self.assertEqual(j3.feminine_word_count, 4)
     self.assertEqual(j3.coding, "strongly feminine-coded")
     j4 = JobAd(u"Ambition:competition, empathy&kindness and"
         " responsibility, co-operation, honesty, trust and other words")
     self.assertEqual(j4.masculine_word_count, 2)
     self.assertEqual(j4.feminine_word_count, 6)
     self.assertEqual(j4.coding, "strongly feminine-coded")
Esempio n. 8
0
    def test_results_view(self):
        j1 = JobAd(Text(u"analytical, empathy, sharing"), "fritz", "fritz AG",
                   "*****@*****.**")

        data = self.client.get('/results/' + j1.hash)
        self.assert200(data)
        self.assert_template_used('results.html')
        self.assert_context("feminine_coded_words", ['empathy', 'sharing'])
        self.assert_context("masculine_coded_words", ['analytical'])
Esempio n. 9
0
 def test_assess_coding_masculine(self):
     j1 = JobAd(u"Ambition:competition–decisiveness, empathy&kindness")
     self.assertEqual(j1.masculine_word_count, 3)
     self.assertEqual(j1.feminine_word_count, 2)
     self.assertEqual(j1.coding, "masculine-coded")
     j2 = JobAd(u"Ambition:competition–decisiveness, other words")
     self.assertEqual(j2.masculine_word_count, 3)
     self.assertEqual(j2.feminine_word_count, 0)
     self.assertEqual(j2.coding, "masculine-coded")
     j3 = JobAd(u"Ambition:competition–decisiveness&leadership, other words")
     self.assertEqual(j3.masculine_word_count, 4)
     self.assertEqual(j3.feminine_word_count, 0)
     self.assertEqual(j3.coding, "strongly masculine-coded")
     # NB: repeated "decisiveness" in j4
     j4 = JobAd(u"Ambition:competition–decisiveness&leadership,"
         " decisiveness, stubborness, sharing and empathy")
     self.assertEqual(j4.masculine_word_count, 6)
     self.assertEqual(j4.feminine_word_count, 2)
     self.assertEqual(j4.coding, "strongly masculine-coded")
Esempio n. 10
0
 def test_analyse(self):
     j1 = JobAd(u"Ambition:competition–decisiveness&leadership,"
         " decisiveness, stubborness, sharing and empathy")
     self.assertEqual(j1.ad_text, u"Ambition:competition–decisiveness"
         "&leadership, decisiveness, stubborness, sharing and empathy")
     self.assertTrue(j1.coding == "strongly masculine-coded")
     self.assertEqual(j1.masculine_word_count, 6)
     self.assertEqual(j1.masculine_coded_words, "ambition,competition,"
             "decisiveness,leadership,decisiveness,stubborness")
     self.assertEqual(j1.feminine_word_count, 2)
     self.assertEqual(j1.feminine_coded_words,"sharing,empathy")
Esempio n. 11
0
 def test_analyse_in_other_language(self):
     j1 = JobAd(u"Sourdough-toast with a sake sake manhattan sun-downer",
                "test")
     self.assertEqual(
         j1.ad_text, u"Sourdough-toast with a sake sake "
         "manhattan sun-downer")
     self.assertTrue(j1.coding == "masculine-coded")
     self.assertEqual(j1.masculine_word_count, 4)
     self.assertEqual(j1.masculine_coded_words, "sake,sake,manhattan,"
                      "sun-downer")
     self.assertEqual(j1.feminine_word_count, 1)
     self.assertEqual(j1.feminine_coded_words, "sourdough")
Esempio n. 12
0
def home():
    form = JobAdForm()
    if request.method == "POST" and form.validate_on_submit():
        text = Text(form.texttotest.data)
        ad = JobAd(text, form.name.data, form.company.data, form.email.data)

        send_email(
            app.config['EMAIL_TO_NOTIFY'],
            dict(text=ad.ad_text,
                 name=ad.name,
                 company=ad.company,
                 email=ad.email,
                 hash=ad.hash))

        return redirect('results/{0}'.format(ad.hash))
    return render_template('home.html', form=form)
Esempio n. 13
0
    def test_increment_or_create(self):
        ad = JobAd(u"sharing leader sharing")
        sharing_counter = CodedWordCounter.query.filter_by(
            ad_hash=ad.hash).filter_by(word='sharing').all()
        self.assertEqual(len(sharing_counter), 1)
        self.assertEqual(sharing_counter[0].count, 2)

        leader_counter = CodedWordCounter.query.filter_by(
            ad_hash=ad.hash).filter_by(word='leader').all()
        self.assertEqual(len(leader_counter), 1)
        self.assertEqual(leader_counter[0].count, 1)

        CodedWordCounter.increment_or_create(ad, "leader", "masculine")
        leader_counter = CodedWordCounter.query.filter_by(
            ad_hash=ad.hash).filter_by(word='leader').all()
        self.assertEqual(len(leader_counter), 1)
        self.assertEqual(leader_counter[0].count, 2)
Esempio n. 14
0
    def test_job_ad_saved(self):
        j1 = JobAd(Text(u"analytical, empathy, sharing"), "fritz", "fritz AG",
                   "*****@*****.**")

        self.assertEqual(1, JobAd.query.count())
        dbjobad = JobAd.query.first()

        self.assertEqual("analytical, empathy, sharing", dbjobad.ad_text)
        self.assertEqual(1, dbjobad.masculine_word_count)
        self.assertEqual(2, dbjobad.feminine_word_count)
        self.assertEqual("empathy,sharing", dbjobad.feminine_coded_words)
        self.assertEqual("analytical", dbjobad.masculine_coded_words)
        self.assertEqual("fritz", dbjobad.name)
        self.assertEqual("fritz AG", dbjobad.company)
        self.assertEqual("*****@*****.**", dbjobad.email)
        self.assertIsNotNone(dbjobad.hash)
        self.assertIsNotNone(dbjobad.date)
Esempio n. 15
0
    def test_process_ad_in_other_language(self):
        ad = JobAd(u"Sourdough-toast with a sake sake manhattan sun-downer",
                   "test")
        CodedWordCounter.process_ad(ad)
        counters = CodedWordCounter.query.filter_by(ad_hash=ad.hash).all()
        self.assertEqual(len(counters), 4)
        total_count = sum([counter.count for counter in counters])
        self.assertEqual(total_count, 5)

        masc_coded_words = sorted([
            counter.word for counter in counters
            if counter.coding == "masculine"
        ])
        fem_coded_words = sorted([
            counter.word for counter in counters
            if counter.coding == "feminine"
        ])
        self.assertEqual(masc_coded_words, ["manhattan", "sake", "sun-downer"])
        self.assertEqual(fem_coded_words, ["sourdough"])
Esempio n. 16
0
    def test_process_ad(self):
        ad = JobAd(u"Sharing: ambition\tkindness&empathy(never more than frou)"
                   " Who is Connect@HBS? leader-supporter-follower "
                   "aggresive/responsible;understand? connect")
        CodedWordCounter.process_ad(ad)
        counters = CodedWordCounter.query.filter_by(ad_hash=ad.hash).all()
        self.assertEqual(len(counters), 9)

        masc_coded_words = sorted([
            counter.word for counter in counters
            if counter.coding == "masculine"
        ])
        fem_coded_words = sorted([
            counter.word for counter in counters
            if counter.coding == "feminine"
        ])
        self.assertEqual(masc_coded_words, ["ambition", "leader"])
        self.assertEqual(
            fem_coded_words,
            [
                "connect",
                "empathy",
                "kindness",
                "responsible",
                "sharing",
                "supporter",
                "understand",
            ],
        )

        # test the deletion step works
        CodedWordCounter.process_ad(ad)
        counters = CodedWordCounter.query.filter_by(ad_hash=ad.hash).all()
        self.assertEqual(len(counters), 9)
        total_count = sum([counter.count for counter in counters])
        self.assertEqual(total_count, 10)
Esempio n. 17
0
 def test_clean_up_word_list(self):
     caps = JobAd("Sharing is as important as ambition")
     self.assertEqual(caps.clean_up_word_list(),
         ['sharing', 'is', 'as', 'important', 'as', 'ambition'])
     tab = JobAd("Qualities: sharing\tambition")
     self.assertEqual(tab.clean_up_word_list(),
         ['qualities', 'sharing', 'ambition'])
     semicolon = JobAd("Sharing;ambitious")
     self.assertEqual(semicolon.clean_up_word_list(),
         ['sharing', 'ambitious'])
     slash = JobAd(u"Sharing/ambitious")
     self.assertEqual(slash.clean_up_word_list(), ['sharing', 'ambitious'])
     hyphen = JobAd(u"Sharing, co-operative, 'servant-leader'")
     self.assertEqual(hyphen.clean_up_word_list(),
         ['sharing', 'co-operative', 'servant', 'leader'])
     mdash = JobAd(u"Sharing—ambitious")
     self.assertEqual(mdash.clean_up_word_list(), ['sharing', 'ambitious'])
     bracket = JobAd(u"Sharing(ambitious) and (leader)")
     self.assertEqual(bracket.clean_up_word_list(), ['sharing', 'ambitious',
         'and', 'leader'])
     sqbracket = JobAd(u"Sharing[ambitious] and [leader]")
     self.assertEqual(sqbracket.clean_up_word_list(), ['sharing',
         'ambitious', 'and', 'leader'])
     abracket = JobAd(u"Sharing<ambitious> and <leader>")
     self.assertEqual(abracket.clean_up_word_list(), ['sharing',
         'ambitious', 'and', 'leader'])
     space = JobAd(u"Sharing ambitious ")
     self.assertEqual(space.clean_up_word_list(), ['sharing', 'ambitious'])
     amp = JobAd(u"Sharing&ambitious, empathy&kindness,")
     self.assertEqual(amp.clean_up_word_list(),
         ['sharing', 'ambitious', 'empathy', 'kindness'])
     asterisk = JobAd(u"Sharing&ambitious*, empathy*kindness,")
     self.assertEqual(asterisk.clean_up_word_list(),
         ['sharing', 'ambitious', 'empathy', 'kindness'])
     atandquestion = JobAd(u"Lead \"Developer\" Who is Connect@HBS? We ")
     self.assertEqual(atandquestion.clean_up_word_list(),
         ['lead', 'developer', 'who', 'is', 'connect', 'hbs', 'we'])
     exclaim = JobAd(u"Lead Developer v good!")
     self.assertEqual(exclaim.clean_up_word_list(),
         ['lead', 'developer', 'v', 'good'])
     curls = JobAd(u"“Lead” ‘Developer’ v good!")
     self.assertEqual(exclaim.clean_up_word_list(),
         ['lead', 'developer', 'v', 'good'])
Esempio n. 18
0
 def test_list_words(self):
     j1 = JobAd(u"leader leader leader, ambition, ambition, competition")
     masc_words, fem_words = j1.list_words()
     self.assertEqual(
         masc_words,
         ["leader (3 times)", "ambition (2 times)", "competition"])
Esempio n. 19
0
 def test_clean_up_word_list(self):
     caps = JobAd("Sharing is as important as ambition")
     self.assertEqual(caps.clean_up_word_list(),
         ['sharing', 'is', 'as', 'important', 'as', 'ambition'])
     tab = JobAd("Qualities: sharing\tambition")
     self.assertEqual(tab.clean_up_word_list(),
         ['qualities', 'sharing', 'ambition'])
     semicolon = JobAd("Sharing;ambitious")
     self.assertEqual(semicolon.clean_up_word_list(),
         ['sharing', 'ambitious'])
     slash = JobAd(u"Sharing/ambitious")
     self.assertEqual(slash.clean_up_word_list(), ['sharing', 'ambitious'])
     hyphen = JobAd(u"Sharing, co-operative, 'servant-leader'")
     self.assertEqual(hyphen.clean_up_word_list(),
         ['sharing', 'co-operative', 'servant', 'leader'])
     mdash = JobAd(u"Sharing—ambitious")
     self.assertEqual(mdash.clean_up_word_list(), ['sharing', 'ambitious'])
     bracket = JobAd(u"Sharing(ambitious) and (leader)")
     self.assertEqual(bracket.clean_up_word_list(), ['sharing', 'ambitious',
         'and', 'leader'])
     sqbracket = JobAd(u"Sharing[ambitious] and [leader]")
     self.assertEqual(sqbracket.clean_up_word_list(), ['sharing',
         'ambitious', 'and', 'leader'])
     abracket = JobAd(u"Sharing<ambitious> and <leader>")
     self.assertEqual(abracket.clean_up_word_list(), ['sharing',
         'ambitious', 'and', 'leader'])
     space = JobAd(u"Sharing ambitious ")
     self.assertEqual(space.clean_up_word_list(), ['sharing', 'ambitious'])
     amp = JobAd(u"Sharing&ambitious, empathy&kindness,")
     self.assertEqual(amp.clean_up_word_list(),
         ['sharing', 'ambitious', 'empathy', 'kindness'])
     asterisk = JobAd(u"Sharing&ambitious*, empathy*kindness,")
     self.assertEqual(asterisk.clean_up_word_list(),
         ['sharing', 'ambitious', 'empathy', 'kindness'])
     atandquestion = JobAd(u"Lead \"Developer\" Who is Connect@HBS? We ")
     self.assertEqual(atandquestion.clean_up_word_list(),
         ['lead', 'developer', 'who', 'is', 'connect', 'hbs', 'we'])
     exclaim = JobAd(u"Lead Developer v good!")
     self.assertEqual(exclaim.clean_up_word_list(),
         ['lead', 'developer', 'v', 'good'])
     curls = JobAd(u"“Lead” ‘Developer’ v good!")
     self.assertEqual(exclaim.clean_up_word_list(),
         ['lead', 'developer', 'v', 'good'])
Esempio n. 20
0
 def test_list_words(self):
     j1 = JobAd(u"leader leader leader, ambition, ambition, competition")
     masc_words, fem_words = j1.list_words()
     self.assertEqual(masc_words,
                      ['leader (3 times)', 'ambition (2 times)', 
                       'competition'])
Esempio n. 21
0
 def test_clean_up_word_list(self):
     translated_wordlists = TranslatedWordlist("en")
     caps = JobAd("Sharing is as important as ambition")
     self.assertEqual(
         caps.clean_up_word_list(translated_wordlists),
         ["sharing", "is", "as", "important", "as", "ambition"],
     )
     tab = JobAd("Qualities: sharing\tambition")
     self.assertEqual(
         tab.clean_up_word_list(translated_wordlists),
         ["qualities", "sharing", "ambition"],
     )
     semicolon = JobAd("Sharing;ambitious")
     self.assertEqual(semicolon.clean_up_word_list(translated_wordlists),
                      ["sharing", "ambitious"])
     slash = JobAd(u"Sharing/ambitious")
     self.assertEqual(slash.clean_up_word_list(translated_wordlists),
                      ["sharing", "ambitious"])
     hyphen = JobAd(u"Sharing, co-operative, 'servant-leader'")
     self.assertEqual(
         hyphen.clean_up_word_list(translated_wordlists),
         ["sharing", "co-operative", "servant", "leader"],
     )
     mdash = JobAd(u"Sharing—ambitious")
     self.assertEqual(mdash.clean_up_word_list(translated_wordlists),
                      ["sharing", "ambitious"])
     bracket = JobAd(u"Sharing(ambitious) and (leader)")
     self.assertEqual(
         bracket.clean_up_word_list(translated_wordlists),
         ["sharing", "ambitious", "and", "leader"],
     )
     sqbracket = JobAd(u"Sharing[ambitious] and [leader]")
     self.assertEqual(
         sqbracket.clean_up_word_list(translated_wordlists),
         ["sharing", "ambitious", "and", "leader"],
     )
     abracket = JobAd(u"Sharing<ambitious> and <leader>")
     self.assertEqual(
         abracket.clean_up_word_list(translated_wordlists),
         ["sharing", "ambitious", "and", "leader"],
     )
     space = JobAd(u"Sharing ambitious ")
     self.assertEqual(space.clean_up_word_list(translated_wordlists),
                      ["sharing", "ambitious"])
     amp = JobAd(u"Sharing&ambitious, empathy&kindness,")
     self.assertEqual(
         amp.clean_up_word_list(translated_wordlists),
         ["sharing", "ambitious", "empathy", "kindness"],
     )
     asterisk = JobAd(u"Sharing&ambitious*, empathy*kindness,")
     self.assertEqual(
         asterisk.clean_up_word_list(translated_wordlists),
         ["sharing", "ambitious", "empathy", "kindness"],
     )
     atandquestion = JobAd(u'Lead "Developer" Who is Connect@HBS? We ')
     self.assertEqual(
         atandquestion.clean_up_word_list(translated_wordlists),
         ["lead", "developer", "who", "is", "connect", "hbs", "we"],
     )
     exclaim = JobAd(u"Lead Developer v good!")
     self.assertEqual(
         exclaim.clean_up_word_list(translated_wordlists),
         ["lead", "developer", "v", "good"],
     )
     curls = JobAd(u"“Lead” ‘Developer’ v good")
     self.assertEqual(
         curls.clean_up_word_list(translated_wordlists),
         ["lead", "developer", "v", "good"],
     )
     accents = JobAd(u"cariñoso colaboración pingüino")
     self.assertEqual(
         accents.clean_up_word_list(translated_wordlists),
         ["cariñoso", "colaboración", "pingüino"],
     )