diff --git a/country/tests/commands/test_evaluate_contract_red_flag.py b/country/tests/commands/test_evaluate_contract_red_flag.py index 9ecce47..fe8148b 100644 --- a/country/tests/commands/test_evaluate_contract_red_flag.py +++ b/country/tests/commands/test_evaluate_contract_red_flag.py @@ -2,7 +2,46 @@ from django.core.management.base import CommandError from django.test import TransactionTestCase -from country.models import Country +from country.models import Buyer, Country, Supplier, Tender + + +def setUpModule(): + Country.objects.all().delete() + country = Country.objects.create(name="Mexico", country_code="MEX", country_code_alpha_2="MX", currency="MXN") + + supplier = Supplier.objects.create( + supplier_id="1", + supplier_name="sample supplier", + supplier_address="kathmandu", + ) + + buyer = Buyer.objects.create( + buyer_id="1", + buyer_name="sample buyer", + buyer_address="kathmandu", + ) + + Tender.objects.create( + country=country, + supplier=supplier, + buyer=buyer, + contract_id=1, + contract_date="2021-01-01", + procurement_procedure="open", + status="active", + link_to_contract="http://test.com", + link_to_tender="http://test.com", + data_source="http://test.com", + no_of_bidders=1, + contract_title="test", + contract_value_local=1.0, + contract_value_usd=1.0, + contract_desc="test description", + tender_value_local=1.0, + tender_value_usd=1.0, + award_value_local=1.0, + award_value_usd=1.0, + ) class EvaluateContractRedFlagTests(TransactionTestCase): @@ -11,6 +50,7 @@ def test_without_country_code(self): call_command("evaluate_contract_red_flag") def test_with_country_code(self): - Country.objects.all().delete() - Country.objects.create(name="Mexico", country_code="MEX", country_code_alpha_2="MX", currency="MXN") self.assertEquals(call_command("evaluate_contract_red_flag", "mx"), None) + + def test_with_country_wrong_code(self): + self.assertEquals(call_command("evaluate_contract_red_flag", "mxss"), None) diff --git a/country/tests/commands/test_fill_contract_values.py b/country/tests/commands/test_fill_contract_values.py index 25a4e72..68dfc5b 100644 --- a/country/tests/commands/test_fill_contract_values.py +++ b/country/tests/commands/test_fill_contract_values.py @@ -1,6 +1,47 @@ from django.core.management import call_command from django.test import TransactionTestCase +from country.models import Buyer, Country, Supplier, Tender + + +def setUpModule(): + Country.objects.all().delete() + Country.objects.create(name="Mexico", country_code="MEX", country_code_alpha_2="MX", currency="MXN") + + supplier = Supplier.objects.create( + supplier_id="1", + supplier_name="sample supplier", + supplier_address="kathmandu", + ) + + buyer = Buyer.objects.create( + buyer_id="1", + buyer_name="sample buyer", + buyer_address="kathmandu", + ) + + Tender.objects.create( + country=Country.objects.all().first(), + supplier=supplier, + buyer=buyer, + contract_id=1, + contract_date="2021-01-01", + procurement_procedure="open", + status="active", + link_to_contract="http://test.com", + link_to_tender="http://test.com", + data_source="http://test.com", + no_of_bidders=1, + contract_title="test", + contract_value_local=1.0, + contract_value_usd=1.0, + contract_desc="test description", + tender_value_local=1.0, + tender_value_usd=1.0, + award_value_local=1.0, + award_value_usd=1.0, + ) + class FillContractValuesTests(TransactionTestCase): def test_command(self): diff --git a/country/tests/commands/test_generate_excel_summary.py b/country/tests/commands/test_generate_excel_summary.py index 6b22770..bf65f41 100644 --- a/country/tests/commands/test_generate_excel_summary.py +++ b/country/tests/commands/test_generate_excel_summary.py @@ -1,6 +1,47 @@ from django.core.management import call_command from django.test import TransactionTestCase +from country.models import Buyer, Country, Supplier, Tender + + +def setUpModule(): + Country.objects.all().delete() + country = Country.objects.create(name="Mexico", country_code="MEX", country_code_alpha_2="MX", currency="MXN") + + supplier = Supplier.objects.create( + supplier_id="1", + supplier_name="sample supplier", + supplier_address="kathmandu", + ) + + buyer = Buyer.objects.create( + buyer_id="1", + buyer_name="sample buyer", + buyer_address="kathmandu", + ) + + Tender.objects.create( + country=country, + supplier=supplier, + buyer=buyer, + contract_id=1, + contract_date="2021-01-01", + procurement_procedure="open", + status="active", + link_to_contract="http://test.com", + link_to_tender="http://test.com", + data_source="http://test.com", + no_of_bidders=1, + contract_title="test", + contract_value_local=1.0, + contract_value_usd=1.0, + contract_desc="test description", + tender_value_local=1.0, + tender_value_usd=1.0, + award_value_local=1.0, + award_value_usd=1.0, + ) + class GenerateExcelSummaryTests(TransactionTestCase): def test_command(self): diff --git a/country/tests/commands/test_import_tender_from_id.py b/country/tests/commands/test_import_tender_from_id.py index 16de56c..c1e1e84 100644 --- a/country/tests/commands/test_import_tender_from_id.py +++ b/country/tests/commands/test_import_tender_from_id.py @@ -1,8 +1,56 @@ from django.core.management import CommandError, call_command from django.test import TransactionTestCase +from country.models import Buyer, Country, Supplier, Tender + + +def setUpModule(): + Country.objects.all().delete() + country = Country.objects.create(name="Mexico", country_code="MEX", country_code_alpha_2="MX", currency="MXN") + + supplier = Supplier.objects.create( + supplier_id="1", + supplier_name="sample supplier", + supplier_address="kathmandu", + ) + + buyer = Buyer.objects.create( + buyer_id="1", + buyer_name="sample buyer", + buyer_address="kathmandu", + ) + + Tender.objects.create( + country=country, + supplier=supplier, + buyer=buyer, + contract_id=1, + contract_date="2021-01-01", + procurement_procedure="open", + status="active", + link_to_contract="http://test.com", + link_to_tender="http://test.com", + data_source="http://test.com", + no_of_bidders=1, + contract_title="test", + contract_value_local=1.0, + contract_value_usd=1.0, + contract_desc="test description", + tender_value_local=1.0, + tender_value_usd=1.0, + award_value_local=1.0, + award_value_usd=1.0, + ) + class TenderImportCommand(TransactionTestCase): def test_command_without_country_batch(self): with self.assertRaises(CommandError): call_command("import_tender_from_id") + + def test_command_with_wrong_country_batch(self): + with self.assertRaises(AttributeError): + call_command("import_tender_from_id", "no_country", 1) + + def test_command_with_country_batch(self): + self.assertEquals(call_command("import_tender_from_id", "Mexico", 1), None)