Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
test-coverage-2021-05-06
Browse files Browse the repository at this point in the history
* [x] Command test refactored
  • Loading branch information
bikramtuladhar committed May 6, 2021
1 parent 91cc268 commit 8b54b3f
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 3 deletions.
46 changes: 43 additions & 3 deletions country/tests/commands/test_evaluate_contract_red_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
41 changes: 41 additions & 0 deletions country/tests/commands/test_fill_contract_values.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
41 changes: 41 additions & 0 deletions country/tests/commands/test_generate_excel_summary.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
48 changes: 48 additions & 0 deletions country/tests/commands/test_import_tender_from_id.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 8b54b3f

Please sign in to comment.