def test_fixedsentencesaver_saves_link_and_connects_to_words(self):
        saver = FixedSentenceSaver(timezone.datetime.today(), timezone.datetime.now().time(), 'WP')
        link = 'http://wiadomosci.wp.pl/adres'
        sentence = 'Szydło zapewnia: w 2017 r. w budżecie nie zabraknie pieniędzy'

        fixed_sentence = SentenceFixer(sentence).fix()
        saver.save_sentence_and_link(fixed_sentence, link, sentence)

        links = Link.objects.all()
        self.assertEqual(1, len(links))

        link_ = links[0]

        self.assertEqual('http://wiadomosci.wp.pl/adres', link_.link)
        self.assertEqual('Szydło zapewnia: w 2017 r. w budżecie nie zabraknie pieniędzy', link_.title)
        self.assertEqual('WP', link_.origin.source)

        word_1 = WordDetails.objects.filter(word__text='Szydło')[0]
        link = Link.objects.filter(words__text__in=[word_1.word.text])[0]
        self.assertEqual(link, link_)

        self.assertEqual(1, len(Link.objects.filter(words__text__in=['Szydło', 'zapewnia', '2017', 'budżecie',
                                                                     'zabraknie', 'pieniędzy']).distinct()))
    def test_fixedsentencesaver_saves_two_links_connects_to_words_and_counts_word_occured_num_right(self):
        datetime = timezone.datetime.today()
        time = timezone.datetime.now().time()
        saver = FixedSentenceSaver(datetime, time, 'WP')

        link1 = 'http://wiadomosci.wp.pl/adres1'
        sentence1 = "Ekstraklasa: koszmar Wisły Kraków, Biała Gwiazda na miejscu spadkowym"
        link2 = 'http://wiadomosci.wp.pl/adres2'
        sentence2 = "Ekstraklasa. Gwizdy przy Reymonta, dziewiąta porażka Wisły"
        link3 = 'http://wiadomosci.wp.pl/adres3'
        sentence3 = "Blamaż Wisły Kraków! Tego dawno nie było"

        fixed_sentence1 = SentenceFixer(sentence1).fix()
        saver.save_sentence_and_link(fixed_sentence1, link1, sentence1)

        fixed_sentence2 = SentenceFixer(sentence2).fix()
        saver.save_sentence_and_link(fixed_sentence2, link2, sentence2)

        fixed_sentence3 = SentenceFixer(sentence3).fix()
        saver.save_sentence_and_link(fixed_sentence3, link3, sentence3)

        ekstraklasa_words_details = WordDetails.objects.filter(word__text='Ekstraklasa')
        self.assertEqual(1, len(ekstraklasa_words_details))
        self.assertEqual(2, ekstraklasa_words_details[0].occured_num)

        wisly_words_details = WordDetails.objects.filter(word__text='Wisły')
        self.assertEqual(1, len(wisly_words_details))
        self.assertEqual(3, wisly_words_details[0].occured_num)

        bialy_words_details = WordDetails.objects.filter(word__text='Biała')
        self.assertEqual(1, len(bialy_words_details))
        self.assertEqual(1, bialy_words_details[0].occured_num)

        links_to_ekstraklasa = Link.objects.filter(words__text__in=['Ekstraklasa']).values('link')
        self.assertIn(link1, [link['link'] for link in links_to_ekstraklasa])
        self.assertIn(link2, [link['link'] for link in links_to_ekstraklasa])
        self.assertNotIn(link3, [link['link'] for link in links_to_ekstraklasa])

        links_to_wisly = Link.objects.filter(words__text__in=['Wisły']).values('link')
        self.assertIn(link1, [link['link'] for link in links_to_wisly])
        self.assertIn(link2, [link['link'] for link in links_to_wisly])
        self.assertIn(link3, [link['link'] for link in links_to_wisly])

        links_to_biala = Link.objects.filter(words__text__in=['Biała']).values('link')
        self.assertIn(link1, [link['link'] for link in links_to_biala])
        self.assertNotIn(link2, [link['link'] for link in links_to_biala])
        self.assertNotIn(link3, [link['link'] for link in links_to_biala])