This repository has been archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [x] Added debugbar and enabled for json response * [x] Added 404 views def test * [x] Updated requirement dev txt * [x] country view test added * [x] Added test_import_tender_from_id.py test_generate_excel_summary.py test_generate_country_contract_excel.py test_evaluate_contract_red_flag.py test * [x] refactored import_tender_from_id.py
- Loading branch information
1 parent
0b8105e
commit 46466e4
Showing
19 changed files
with
226 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.core.management import call_command | ||
from django.core.management.base import CommandError | ||
from django.test import TransactionTestCase | ||
|
||
from country.models import Country | ||
|
||
|
||
class EvaluateContractRedFlagTests(TransactionTestCase): | ||
def test_without_country_code(self): | ||
with self.assertRaises(CommandError): | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.core.management import call_command | ||
from django.test import TransactionTestCase | ||
|
||
|
||
class FillContractValuesTests(TransactionTestCase): | ||
def test_command(self): | ||
self.assertEquals(call_command("fill_contract_values"), None) |
11 changes: 11 additions & 0 deletions
11
country/tests/commands/test_generate_country_contract_excel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.core.management import CommandError, call_command | ||
from django.test import TransactionTestCase | ||
|
||
|
||
class GenerateCountryContractExcelTests(TransactionTestCase): | ||
def test_command(self): | ||
with self.assertRaises(CommandError): | ||
call_command("generate_country_contract_excel") | ||
|
||
def test_command_with_country(self): | ||
self.assertEquals(call_command("generate_country_contract_excel", "MX"), None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.core.management import call_command | ||
from django.test import TransactionTestCase | ||
|
||
|
||
class GenerateExcelSummaryTests(TransactionTestCase): | ||
def test_command(self): | ||
self.assertEquals(call_command("generate_excel_summary"), None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.core.management import CommandError, call_command | ||
from django.test import TransactionTestCase | ||
|
||
|
||
class TenderImportCommand(TransactionTestCase): | ||
def test_command_without_country_batch(self): | ||
with self.assertRaises(CommandError): | ||
call_command("import_tender_from_id") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.core.management import call_command | ||
from django.test import TransactionTestCase | ||
|
||
|
||
class ProcessCurrencyConversionCommandTest(TransactionTestCase): | ||
def test_command(self): | ||
self.assertEquals(call_command("process_currency_conversion"), None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.core.management import CommandError, call_command | ||
from django.test import TransactionTestCase | ||
|
||
|
||
class SaveDatabaseEquityCommand(TransactionTestCase): | ||
def test_command_without_country_batch(self): | ||
with self.assertRaises(CommandError): | ||
call_command("save_database_equity") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
|
||
class CountryViewTest(TestCase): | ||
def setUp(self): | ||
self.buyer_list_api_url = "BuyerView-list" | ||
self.country_list_api_url = "country-list" | ||
self.language_list_api_url = "language-list" | ||
self.supplier_list_api_url = "SupplierView-list" | ||
self.tender_list_api_url = "TenderView-list" | ||
self.overview_summary_list_api_url = "OverallStatSummaryView-list" | ||
self.country_choices_api_url = "country-choices" | ||
self.data_edit_url = "data_edits" | ||
self.data_imports_url = "data_imports" | ||
self.data_validate_url = "data_validate" | ||
self.data_delete_url = "data_delete" | ||
|
||
def test_buyer_list_GET(self): | ||
url = "%s?country=KE&buyer_name=buyer2&product=1" % reverse(self.buyer_list_api_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_country_list_GET(self): | ||
url = reverse(self.country_list_api_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_country_choice_list_GET(self): | ||
url = reverse(self.country_choices_api_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_language_list_GET(self): | ||
url = reverse(self.country_list_api_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_supplier_list_GET(self): | ||
url = "%s?country=KE&supplier_name=supplier&product=1" % reverse(self.supplier_list_api_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_tender_list_GET(self): | ||
url_string = "%s?&country=1&buyer=1&supplier=1&product=1&status=open&procurement_procedure=direct&title=title" | ||
url_string += ( | ||
"&date_from=2020-01-01&date_to=2021-01-01&contract_value_usd=112&value_comparison=true&equity_id=1" | ||
) | ||
url = url_string % reverse(self.tender_list_api_url) | ||
|
||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_overview_summary_list_GET(self): | ||
url = reverse(self.overview_summary_list_api_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_data_edit_GET(self): | ||
url = "%s?data_import_id=1" % reverse(self.data_edit_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_302_FOUND) | ||
|
||
def test_data_imports_GET(self): | ||
url = "%s?country=1&data_import_id=1&validated=true" % reverse(self.data_imports_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_302_FOUND) | ||
|
||
def test_data_imports_without_validate_GET(self): | ||
url = "%s?country=1&data_import_id=1" % reverse(self.data_imports_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_302_FOUND) | ||
|
||
def test_data_validate_GET(self): | ||
url = "%s?data_import_id=1" % reverse(self.data_validate_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_302_FOUND) | ||
|
||
def test_data_validate_without_import_id_GET(self): | ||
url = reverse(self.data_validate_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_302_FOUND) | ||
|
||
def test_data_delete_GET(self): | ||
url = "%s?data_import_id=1" % reverse(self.data_delete_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_302_FOUND) | ||
|
||
def test_data_delete_without_id_GET(self): | ||
url = reverse(self.data_delete_url) | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_302_FOUND) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import json | ||
|
||
from django.conf import settings | ||
from django.http import HttpResponse | ||
from django.utils.deprecation import MiddlewareMixin | ||
|
||
|
||
class NonHtmlDebugToolbarMiddleware(MiddlewareMixin): | ||
def process_response(self, request, response): | ||
debug = request.GET.get("debug", "UNSET") | ||
|
||
if debug != "UNSET" and settings.DEBUG: | ||
if response["Content-Type"] == "application/octet-stream": | ||
new_content = "<html><body>Binary Data, " "Length: {}</body></html>".format(len(response.content)) | ||
response = HttpResponse(new_content) | ||
elif response["Content-Type"] != "text/html": | ||
content = response.content | ||
try: | ||
json_ = json.loads(content) | ||
content = json.dumps(json_, sort_keys=True, indent=2) | ||
except ValueError: | ||
pass | ||
response = HttpResponse("<html><body><pre>{}" "</pre></body></html>".format(content)) | ||
|
||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.test import TestCase | ||
from rest_framework import status | ||
|
||
|
||
class CovidAdminViewTest(TestCase): | ||
def setUp(self): | ||
self.not_found_url = "404" | ||
|
||
def test_not_found_GET(self): | ||
url = "/api/v1/404" | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, status.HTTP_404_NOT_FOUND) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ sentry_sdk | |
xlsxwriter | ||
wagtail | ||
djangorestframework-serializer-extensions | ||
django-debug-toolbar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ pip-tools | |
pre-commit | ||
psycopg2-binary | ||
transifex-client | ||
django-debug-toolbar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters