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 fd0a61c
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 12 deletions.
17 changes: 8 additions & 9 deletions country/management/commands/save_database_equity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ def add_arguments(self, parser):
def handle(self, *args, **kwargs):
country_name = kwargs["country"]
self.stdout.write(f"Fetching equity data for {country_name}")
if country_name:
try:
if Country.objects.filter(name=country_name).exists():
fetch_equity_data.apply_async(args=(country_name,), queue="covid19")
self.stdout.write("Created task: import_equity_data")
except Exception as e:
self.stderr.write(e)

else:
self.stderr.write("Enter country name as arguments")
try:
if Country.objects.filter(name=country_name).exists():
fetch_equity_data.apply_async(args=(country_name,), queue="covid19")
self.stdout.write("Created task: import_equity_data")
except Exception as e:
self.stderr.write(e)
return

self.stdout.write("Done")
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)
64 changes: 64 additions & 0 deletions country/tests/commands/test_process_currency_conversion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,70 @@
from django.core.management import call_command
from django.test import TransactionTestCase

from country.models import Buyer, Country, GoodsServices, GoodsServicesCategory, Supplier, Tender


def setUpModule():
Country.objects.all().delete()
country = Country.objects.create(name="Mexico", country_code="MEX", country_code_alpha_2="MX", currency="MXN")
category = GoodsServicesCategory.objects.create(
category_name="name",
category_desc="desc",
)
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 = 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,
)

GoodsServices.objects.create(
country=country,
goods_services_category=category,
contract=tender,
classification_code="code",
no_of_bidders=112,
contract_title="title",
contract_desc="desc",
supplier=supplier,
buyer=buyer,
quantity_units=1233,
ppu_including_vat=1234.0,
tender_value_local=1234.0,
tender_value_usd=None,
award_value_local=1234.0,
award_value_usd=None,
contract_value_local=1234.0,
contract_value_usd=None,
)


class ProcessCurrencyConversionCommandTest(TransactionTestCase):
def test_command(self):
Expand Down
13 changes: 13 additions & 0 deletions country/tests/commands/test_save_database_equity.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
from django.core.management import CommandError, call_command
from django.test import TransactionTestCase

from country.models import Country


def setUpModule():
Country.objects.all().delete()
Country.objects.create(name="Mexico", country_code="MEX", country_code_alpha_2="MX", currency="MXN")


class SaveDatabaseEquityCommand(TransactionTestCase):
def test_command_without_country_batch(self):
with self.assertRaises(CommandError):
call_command("save_database_equity")

def test_command_with_country_batch(self):
self.assertEquals(call_command("save_database_equity", "Mexico"), None)

def test_command_with_wrong_country_batch(self):
self.assertEquals(call_command("save_database_equity", "no_country"), None)

0 comments on commit fd0a61c

Please sign in to comment.