Ejemplo n.º 1
0
    def test_list_ajax_view_filters(self):
        query_kwargs = {
            "start": '0',
            "draw": '1',
            "length": '10',
            "order[0][column]": "1",
            "order[0][dir]": "desc",
        }

        tender1 = TenderFactory(source="TED")
        tender2 = TenderFactory(source="UNGM")
        vendor1 = VendorFactory()
        vendor2 = VendorFactory()
        award1 = AwardFactory(tender=tender1)
        award2 = AwardFactory(tender=tender2)
        award1.vendors.add(vendor1)
        award2.vendors.add(vendor2)

        url = '{}?{}'.format(reverse('contract_awards_list_ajax_view'),
                             urlencode(query_kwargs))
        response = self.client.get(url)
        data = json.loads(response.content)['data']
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(data), 2)
        self.assertEqual(data[0]['title'], award2.tender.title)
        self.assertEqual(data[0]['source'], award2.tender.source)
        self.assertEqual(data[0]['organization'], award2.tender.organization)
        self.assertEqual(data[0]['value'], str(award2.value))
        self.assertEqual(data[0]['currency'], award2.currency)
Ejemplo n.º 2
0
 def setUp(self):
     super(AddTenderTestCase, self).setUp()
     self.keyword = KeywordFactory()
     self.tender_1 = TenderFactory(title='Tender_1 python')
     self.tender_2 = TenderFactory(title='Tender_2', source='TED')
     self.doc_1 = TenderDocumentFactory(tender=self.tender_2)
     self.doc_2 = TenderDocumentFactory(tender=self.tender_2)
Ejemplo n.º 3
0
 def test_list_view_two_tenders(self):
     tender_1 = TenderFactory(title='Tender1')
     tender_2 = TenderFactory(title='Tender2', source='TED')
     url = reverse('tenders_list_view')
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
     self.assertQuerysetEqual(list(response.context['tenders']),
                              ['<Tender: Tender1>', '<Tender: Tender2>'])
     self.assertEqual(response.context['tenders'][0].reference,
                      tender_1.reference)
     self.assertEqual(response.context['tenders'][1].source,
                      tender_2.source)
Ejemplo n.º 4
0
    def setUp(self):
        super(SearchTestCase, self).setUp()

        user = User.objects.create(username='******')
        user.set_password('12345')
        user.save()
        logged_in = self.client.login(username='******', password='******')
        self.assertEqual(logged_in, True)

        self.keyword = KeywordFactory()
        self.tender_1 = TenderFactory(title='Tender_1')
        self.tender_2 = TenderFactory(title='Tender_2')

        with open(os.devnull, 'w') as f:
            call_command('search_index', '--rebuild', '-f', stdout=f)
Ejemplo n.º 5
0
 def test_detail_view_one_tender(self):
     new_tender = TenderFactory()
     url = reverse('tender_detail_view', kwargs={'pk': new_tender.id})
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, new_tender.title)
     self.assertContains(response, new_tender.reference)
Ejemplo n.º 6
0
 def test_list_ajax_view_filters(self):
     query_kwargs = {
         "start": '0',
         "draw": '1',
         "length": '10',
         "source": "TED",
         "organization": "Test organization",
         "value": "2",
     }
     tender = TenderFactory(source="TED",
                            organization="Test organization",
                            value="45000")
     vendor1 = VendorFactory()
     vendor2 = VendorFactory()
     award_meeting_filters = AwardFactory(tender=tender)
     award_meeting_filters.vendors.add(vendor1)
     award_not_meeting_filters = AwardFactory()
     award_not_meeting_filters.vendors.add(vendor2)
     url = '{}?{}'.format(reverse('contract_awards_list_ajax_view'),
                          urlencode(query_kwargs))
     response = self.client.get(url)
     data = json.loads(response.content)['data']
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(data), 1)
     self.assertEqual(data[1]['title'], award_meeting_filters.tender.title)
     self.assertEqual(data[1]['source'],
                      award_meeting_filters.tender.source)
     self.assertEqual(data[1]['organization'],
                      award_meeting_filters.tender.organization)
     self.assertEqual(data[1]['value'], award_meeting_filters.value)
     self.assertEqual(data[1]['currency'], award_meeting_filters.currency)
Ejemplo n.º 7
0
 def test_delete_tender(self):
     new_tender = TenderFactory()
     url = reverse('tender_delete_view', kwargs={'pk': new_tender.id})
     response = self.client.post(url, {})
     self.assertEqual(response.status_code, 200)
     tender_deleted = Tender.objects.filter(reference=new_tender.reference)
     self.assertQuerysetEqual(tender_deleted, [])
Ejemplo n.º 8
0
 def test_remove_from_favourites(self):
     new_tender = TenderFactory(favourite=True)
     url = reverse('tender_favourite_view', kwargs={'pk': new_tender.id})
     response = self.client.post(url, {'favourite': 'false'})
     self.assertEqual(response.status_code, 200)
     tender_added = Tender.objects.get(reference=new_tender.reference)
     self.assertEqual(tender_added.favourite, False)
     tender_added.delete()
Ejemplo n.º 9
0
 def test_detail_view_one_tender_has_keywords_with_no_keywords_set(self):
     new_tender = TenderFactory(title='Tender_2 python', description='Tender_2 drupal')
     url = reverse('tender_detail_view', kwargs={'pk': new_tender.id})
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, new_tender.title)
     self.assertContains(response, new_tender.reference)
     self.assertContains(response, 'Tender_2 python')
     self.assertContains(response, 'Tender_2 drupal')
Ejemplo n.º 10
0
    def setUp(self):
        super(AddAwardTestCase, self).setUp()

        self.expected_vendor_name = 'test_vendor'

        tender = TenderFactory(title='test_title')
        vendor = VendorFactory(name=self.expected_vendor_name)
        award = AwardFactory(tender=tender)
        award.vendors.add(vendor)
        award.save()
Ejemplo n.º 11
0
 def test_list_view_has_keywords(self):
     KeywordFactory()
     tender = TenderFactory(title='Tender1 python')
     url = reverse('tenders_list_view')
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
     self.assertQuerysetEqual(list(response.context['tenders']),
                              ['<Tender: Tender1 python>'])
     self.assertEqual(response.context['tenders'][0].reference,
                      tender.reference)
Ejemplo n.º 12
0
    def setUp(self):
        super(AwardsViewTest, self).setUp()
        user = User.objects.create(username="******")
        user.set_password("12345")
        user.save()

        vendor = VendorFactory(name="test_vendor")
        self.tender = TenderFactory(title="test_title")
        self.award = AwardFactory(tender=self.tender)
        self.award.vendors.add(vendor)
Ejemplo n.º 13
0
    def setUp(self):
        super(SendMailTest, self).setUp()
        self.keyword = KeywordFactory()
        self.tender1 = TenderFactory(
            reference='RFQ 47-2019',
            title='test_title1',
            url='https://www.ungm.org/Public/Notice/94909',
            favourite=True,
            published=datetime.now(timezone.utc) - timedelta(days=2),
            deadline=datetime.now(timezone.utc) + timedelta(days=3) -
            timedelta(hours=1),
        )

        self.tender2 = TenderFactory(
            reference='2019/FLCHI/FLCHI/102665',
            title='test_title2 python',
            url='https://www.ungm.org/Public/Notice/94920',
            published=datetime.now(timezone.utc) - timedelta(days=3),
            deadline=datetime.now(timezone.utc) + timedelta(days=7) -
            timedelta(hours=1),
        )

        self.tender3 = TenderFactory(
            reference='RFP 56956',
            title='test_title3',
            url='https://www.ungm.org/Public/Notice/92850',
            published=datetime.now(timezone.utc) - timedelta(days=1),
            deadline=datetime.now(timezone.utc) + timedelta(days=1) -
            timedelta(hours=1),
        )

        self.notified_user1 = EmailAddressFactory()
        self.notified_user2 = EmailAddressFactory()
Ejemplo n.º 14
0
    def test_detail_view_one_tender_has_keywords(self):
        KeywordFactory(value='python')
        KeywordFactory(value='drupal')
        new_tender = TenderFactory(title='Tender_1 python', description='Tender_1 drupal')
        url = reverse('tender_detail_view', kwargs={'pk': new_tender.id})
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Tender_1 <mark>python</mark>')
        self.assertContains(response, 'Tender_1 <mark>drupal</mark>')

        soup = BeautifulSoup(response.content.decode(), 'html.parser')
        response.content = soup.get_text()

        self.assertContains(response, new_tender.title)
        self.assertContains(response, new_tender.reference)
Ejemplo n.º 15
0
class SendMailTest(BaseTestCase):
    def setUp(self):
        super(SendMailTest, self).setUp()
        self.keyword = KeywordFactory()
        self.tender1 = TenderFactory(
            reference='RFQ 47-2019',
            title='test_title1',
            url='https://www.ungm.org/Public/Notice/94909',
            favourite=True,
            published=datetime.now(timezone.utc) - timedelta(days=2),
            deadline=datetime.now(timezone.utc) + timedelta(days=3) -
            timedelta(hours=1),
        )

        self.tender2 = TenderFactory(
            reference='2019/FLCHI/FLCHI/102665',
            title='test_title2 python',
            url='https://www.ungm.org/Public/Notice/94920',
            published=datetime.now(timezone.utc) - timedelta(days=3),
            deadline=datetime.now(timezone.utc) + timedelta(days=7) -
            timedelta(hours=1),
        )

        self.tender3 = TenderFactory(
            reference='RFP 56956',
            title='test_title3',
            url='https://www.ungm.org/Public/Notice/92850',
            published=datetime.now(timezone.utc) - timedelta(days=1),
            deadline=datetime.now(timezone.utc) + timedelta(days=1) -
            timedelta(hours=1),
        )

        self.notified_user1 = EmailAddressFactory()
        self.notified_user2 = EmailAddressFactory()

    def test_mailing(self):
        subject = 'New tenders available'
        addresses = EmailAddress.objects.filter(notify=True)
        recipients = [address.email for address in addresses]

        html_content = render_to_string(
            'mails/new_tenders.html',
            {
                'tenders': [self.tender1, self.tender2, self.tender3],
                'domain': settings.BASE_URL,
            },
        )

        email = build_email(subject, recipients, None, html_content)
        email.send()

        self.assertEqual(len(mail.outbox), 1)

        body = mail.outbox[0].body
        alt_body = mail.outbox[0].alternatives[0][0]

        self.assertEqual(self.tender1.title in body, True)
        self.assertEqual(self.tender2.title in body, True)
        self.assertEqual(self.tender3.title in body, True)

        self.assertEqual(self.tender1.organization in alt_body, True)
        self.assertEqual(self.tender2.organization in alt_body, True)
        self.assertEqual(self.tender3.organization in alt_body, True)

    def test_notify_tenders(self):
        management.call_command('notify_tenders')
        self.assertEqual(len(mail.outbox), 3)

        mail1 = mail.outbox[0].alternatives[0][0]
        mail2 = mail.outbox[1].alternatives[0][0]
        mail3 = mail.outbox[2].alternatives[0][0]

        self.assertEqual(self.tender3.title in mail1, True)
        self.assertEqual(self.tender1.title in mail2, True)
        self.assertEqual(self.tender2.title in mail3, True)

    def test_notify_tenders_digest(self):
        management.call_command('notify_tenders', digest=True)
        self.assertEqual(len(mail.outbox), 1)

        alt_body = mail.outbox[0].alternatives[0][0]
        soup = BeautifulSoup(alt_body, 'html.parser')

        tender_list = soup.find('ol', {'class': 'tender-list'}).find_all('a')
        self.assertEqual(len(tender_list), 3)
        self.assertEqual(tender_list[0]['href'], self.tender3.url)
        self.assertEqual(tender_list[1]['href'], self.tender1.url)
        self.assertEqual(tender_list[2]['href'], self.tender2.url)

    def test_notify_awards(self):
        award1 = AwardFactory()
        award2 = AwardFactory()
        award3 = AwardFactory()
        management.call_command('notify_awards')
        self.assertEqual(len(mail.outbox), 3)

        mail1 = mail.outbox[0].alternatives[0][0]
        mail2 = mail.outbox[1].alternatives[0][0]
        mail3 = mail.outbox[2].alternatives[0][0]

        self.assertEqual(award1.tender.title in mail1, True)
        self.assertEqual(award2.tender.title in mail2, True)
        self.assertEqual(award3.tender.title in mail3, True)

    def test_notify_awards_digest(self):
        award1 = AwardFactory()
        award2 = AwardFactory()
        award3 = AwardFactory()
        management.call_command('notify_awards', digest=True)
        self.assertEqual(len(mail.outbox), 1)

        alt_body = mail.outbox[0].alternatives[0][0]
        soup = BeautifulSoup(alt_body, 'html.parser')

        award_list = soup.find('ol', {'class': 'award-list'}).find_all('a')
        self.assertEqual(len(award_list), 3)
        self.assertEqual(award_list[0]['href'], award1.tender.url)
        self.assertEqual(award_list[1]['href'], award2.tender.url)
        self.assertEqual(award_list[2]['href'], award3.tender.url)

    def test_mailing_favorites(self):
        original_tender1_organization = self.tender1.organization
        management.call_command('notify_favorites')
        self.assertEqual(len(mail.outbox), 1)

        self.tender1 = Tender.objects.get(reference=self.tender1.reference)
        self.tender1.organization = 'CHANGE1'
        self.tender1.save()

        management.call_command('notify_favorites')
        self.assertEqual(len(mail.outbox), 2)

        self.tender3 = Tender.objects.get(reference=self.tender3.reference)
        self.tender3.organization = 'CHANGE2'
        self.tender3.save()

        management.call_command('notify_favorites')
        self.assertEqual(len(mail.outbox), 2)

        message = mail.outbox[0].alternatives[0][0]
        self.tender1 = Tender.objects.get(reference=self.tender1.reference)
        self.tender3 = Tender.objects.get(reference=self.tender3.reference)
        self.assertEqual('Favorite tender(s) update' in message, True)
        self.assertEqual(original_tender1_organization in message, False)
        self.assertEqual(self.tender1.organization in message, True)
        self.assertEqual(self.tender3.organization in message, False)

    def test_mailing_favorites_digest(self):
        self.tender2 = Tender.objects.get(reference=self.tender2.reference)
        self.tender2.organization = 'CHANGE2'
        self.tender2.favourite = True
        self.tender2.save()

        self.tender3 = Tender.objects.get(reference=self.tender3.reference)
        self.tender3.organization = 'CHANGE3'
        self.tender3.favourite = True
        self.tender3.save()

        management.call_command('notify_favorites', digest=True)
        self.assertEqual(len(mail.outbox), 1)

        alt_body = mail.outbox[0].alternatives[0][0]
        soup = BeautifulSoup(alt_body, 'html.parser')

        tender_list = soup.find('ol', {'class': 'tender-list'}).find_all('a')
        self.assertEqual(len(tender_list), 3)
        self.assertEqual(tender_list[0]['href'], self.tender3.url)
        self.assertEqual(tender_list[1]['href'], self.tender1.url)
        self.assertEqual(tender_list[2]['href'], self.tender2.url)

    def test_mailing_keywords(self):
        management.call_command('notify_keywords')
        self.assertEqual(len(mail.outbox), 1)

        self.tender2.organization = 'CHANGE1'
        self.tender2.save()

        management.call_command('notify_keywords')
        self.assertEqual(len(mail.outbox), 2)

        self.tender3.organization = 'CHANGE2'
        self.tender3.save()

        management.call_command('notify_keywords')
        self.assertEqual(len(mail.outbox), 2)

        message = mail.outbox[0].alternatives[0][0]
        self.assertEqual('Keyword tender(s) update' in message, True)
        self.assertEqual(self.tender2.organization in message, False)
        self.assertEqual(self.tender3.organization in message, False)

    def test_mailing_keywords_digest(self):
        self.tender1 = Tender.objects.get(reference=self.tender1.reference)
        self.tender1.title = 'test_title1 python'
        self.tender1.save()

        self.tender2 = Tender.objects.get(reference=self.tender2.reference)
        self.tender2.title = 'test_title2 changed python'
        self.tender2.save()

        self.tender3 = Tender.objects.get(reference=self.tender3.reference)
        self.tender3.title = 'test_title3 python'
        self.tender3.save()

        management.call_command('notify_keywords', digest=True)
        self.assertEqual(len(mail.outbox), 1)

        alt_body = mail.outbox[0].alternatives[0][0]
        soup = BeautifulSoup(alt_body, 'html.parser')

        tender_list = soup.find('ol', {'class': 'tender-list'}).find_all('a')
        self.assertEqual(len(tender_list), 3)
        email_urls = {t['href'] for t in tender_list}
        db_urls = {self.tender1.url, self.tender2.url, self.tender3.url}
        self.assertEqual(email_urls, db_urls)

    def test_deadline_notification(self):
        self.tender2 = Tender.objects.get(reference=self.tender2.reference)
        self.tender2.favourite = True
        self.tender2.save()

        self.tender3 = Tender.objects.get(reference=self.tender3.reference)
        self.tender3.favourite = True
        self.tender3.save()

        management.call_command('deadline_notifications')
        self.assertEqual(len(mail.outbox), 3)

        mail1 = mail.outbox[0].alternatives[0][0]
        mail2 = mail.outbox[1].alternatives[0][0]
        mail3 = mail.outbox[2].alternatives[0][0]

        self.assertEqual(self.tender3.url in mail1, True)
        self.assertEqual(self.tender1.url in mail2, True)
        self.assertEqual(self.tender2.url in mail3, True)