From 8bcb58cbf6e645765981e16a941c176f48ede5f3 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Mon, 31 Jul 2017 12:53:18 -0300 Subject: [PATCH 01/32] Adds firt and second shared tests --- jarbas/core/tests/shared_tests.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 jarbas/core/tests/shared_tests.py diff --git a/jarbas/core/tests/shared_tests.py b/jarbas/core/tests/shared_tests.py new file mode 100644 index 0000000..2164677 --- /dev/null +++ b/jarbas/core/tests/shared_tests.py @@ -0,0 +1,18 @@ +from django.test import TestCase + +# Serializer methods: TestSerializer + + +def test_serializer(TestCase, obj, expected, input): + serialized = obj.serialize(input) + TestCase.assertEqual(serialized, expected) + + +# Cotum methods: TestCustomMethods + + +def test_main(TestCase, obj, update, schedule_update, costum_method): + costum_method.return_value = (range(21), range(21, 43)) + obj.main() + update.assert_has_calls([call()] * 2) + schedule_update.assert_has_calls(call(i) for i in range(42)) From 4cb1a8d883d40223af04bbc686a0259b88d4aed3 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Mon, 31 Jul 2017 13:35:33 -0300 Subject: [PATCH 02/32] Using shared_tests on Suspicions Command test suite --- jarbas/core/tests/test_suspicions_command.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index 77a6191..f5bdf2d 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -5,6 +5,7 @@ from jarbas.core.management.commands.suspicions import Command from jarbas.core.models import Reimbursement +from jarbas.core.tests import shared_tests class TestCommand(TestCase): @@ -32,7 +33,8 @@ def test_serializer(self): 'hypothesis_3': 'True', 'probability': '0.38' } - self.assertEqual(self.command.serialize(input), expected) + shared_tests.test_serializer(self, self.command, expected, input) + def test_serializer_without_probability(self): expected = { @@ -74,10 +76,8 @@ class TestCustomMethods(TestCommand): @patch('jarbas.core.management.commands.suspicions.Command.schedule_update') @patch('jarbas.core.management.commands.suspicions.Command.update') def test_main(self, update, schedule_update, suspicions): - suspicions.return_value = (range(21), range(21, 43)) - self.command.main() - update.assert_has_calls([call()] * 2) - schedule_update.assert_has_calls(call(i) for i in range(42)) + shared_tests.test_main(self, self.command, update, schedule_update, suspicions) + @patch.object(Reimbursement.objects, 'get') def test_schedule_update_existing_record(self, get): From 0fbff0b0a81aaa9f620f5b9661c5709fb99fe4c2 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Mon, 31 Jul 2017 15:05:36 -0300 Subject: [PATCH 03/32] Adds missing import --- jarbas/core/tests/shared_tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jarbas/core/tests/shared_tests.py b/jarbas/core/tests/shared_tests.py index 2164677..83cd13e 100644 --- a/jarbas/core/tests/shared_tests.py +++ b/jarbas/core/tests/shared_tests.py @@ -1,3 +1,5 @@ +from unittest.mock import call + from django.test import TestCase # Serializer methods: TestSerializer From 84ae334bf9e45d021431f5f86869eeb6d52af2d9 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Mon, 31 Jul 2017 15:37:12 -0300 Subject: [PATCH 04/32] uses content on assert --- jarbas/core/tests/test_suspicions_command.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index f5bdf2d..f3a1b6c 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -90,9 +90,9 @@ def test_schedule_update_existing_record(self, get): } self.command.queue = [] self.command.schedule_update(content) - get.assert_called_once_with(document_id=42) - self.assertEqual(0.618, reimbursement.probability) - self.assertEqual({'answer': 42}, reimbursement.suspicions) + get.assert_called_once_with(document_id=content['document_id']) + self.assertEqual(content['probability'], reimbursement.probability) + self.assertEqual(content['suspicions'], reimbursement.suspicions) self.assertEqual([reimbursement], self.command.queue) @patch.object(Reimbursement.objects, 'get') From 94b5716a3fb9d559a3c2c1c7cfa5e4833d79a4fa Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Tue, 1 Aug 2017 09:58:13 -0300 Subject: [PATCH 05/32] Using shared test: test_schedule_update_non_existing_record updates both suspicions_command and receipts_text_command tests suites --- jarbas/core/tests/shared_tests.py | 9 +++++++++ jarbas/core/tests/test_receipts_text_command.py | 7 ++----- jarbas/core/tests/test_suspicions_command.py | 6 +----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/jarbas/core/tests/shared_tests.py b/jarbas/core/tests/shared_tests.py index 83cd13e..0c77c4f 100644 --- a/jarbas/core/tests/shared_tests.py +++ b/jarbas/core/tests/shared_tests.py @@ -2,6 +2,8 @@ from django.test import TestCase +from jarbas.core.models import Reimbursement + # Serializer methods: TestSerializer @@ -18,3 +20,10 @@ def test_main(TestCase, obj, update, schedule_update, costum_method): obj.main() update.assert_has_calls([call()] * 2) schedule_update.assert_has_calls(call(i) for i in range(42)) + +def test_schedule_update_non_existing_record(TestCase, get, content, obj): + get.side_effect = Reimbursement.DoesNotExist + obj.queue = [] + obj.schedule_update(content) + get.assert_called_once_with(document_id=42) + TestCase.assertEqual([], obj.queue) diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index 56fc4a2..058f80b 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -5,6 +5,7 @@ from jarbas.core.management.commands.receipts_text import Command from jarbas.core.models import Reimbursement +from jarbas.core.tests import shared_tests class TestCommand(TestCase): @@ -65,12 +66,8 @@ def test_schedule_update_existing_record(self, get): @patch.object(Reimbursement.objects, 'get') def test_schedule_update_non_existing_record(self, get): - get.side_effect = Reimbursement.DoesNotExist content = {'document_id': 42} - self.command.queue = [] - self.command.schedule_update(content) - get.assert_called_once_with(document_id=42) - self.assertEqual([], self.command.queue) + shared_tests.test_schedule_update_non_existing_record(self, get, content, self.command) @patch('jarbas.core.management.commands.receipts_text.bulk_update') @patch('jarbas.core.management.commands.receipts_text.print') diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index f3a1b6c..c182960 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -97,12 +97,8 @@ def test_schedule_update_existing_record(self, get): @patch.object(Reimbursement.objects, 'get') def test_schedule_update_non_existing_record(self, get): - get.side_effect = Reimbursement.DoesNotExist content = {'document_id': 42} - self.command.queue = [] - self.command.schedule_update(content) - get.assert_called_once_with(document_id=42) - self.assertEqual([], self.command.queue) + shared_tests.test_schedule_update_non_existing_record(self, get, content, self.command) @patch('jarbas.core.management.commands.suspicions.bulk_update') @patch('jarbas.core.management.commands.suspicions.print') From 1f02caeb2ac0ed14026394ee3f0d9158eb60ff3d Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Tue, 1 Aug 2017 10:05:57 -0300 Subject: [PATCH 06/32] fix typo --- jarbas/core/tests/shared_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jarbas/core/tests/shared_tests.py b/jarbas/core/tests/shared_tests.py index 0c77c4f..6ac6715 100644 --- a/jarbas/core/tests/shared_tests.py +++ b/jarbas/core/tests/shared_tests.py @@ -12,7 +12,7 @@ def test_serializer(TestCase, obj, expected, input): TestCase.assertEqual(serialized, expected) -# Cotum methods: TestCustomMethods +# Custom methods: TestCustomMethods def test_main(TestCase, obj, update, schedule_update, costum_method): From 5242f99924971699072503b4f8458b2530997410 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Tue, 1 Aug 2017 10:35:32 -0300 Subject: [PATCH 07/32] Adds missing assert --- jarbas/core/tests/test_receipts_text_command.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index 058f80b..3d85308 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -63,6 +63,7 @@ def test_schedule_update_existing_record(self, get): self.command.schedule_update(content) get.assert_called_once_with(document_id=42) self.assertEqual(content['receipt_text'], reimbursement.receipt_text) + self.assertEqual([reimbursement], self.command.queue) @patch.object(Reimbursement.objects, 'get') def test_schedule_update_non_existing_record(self, get): From dea1f263865ddddcd190cf05e1a6565dd2da11a5 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Wed, 2 Aug 2017 11:43:32 -0300 Subject: [PATCH 08/32] Starting migrating shared testing methods to `__init__` - Moved serializer test method to `__init__` - Started using new serializer testing method on suspicions command test suite - Removed serializer test from `shared_tests` --- jarbas/core/tests/__init__.py | 8 ++++++++ jarbas/core/tests/shared_tests.py | 7 ------- jarbas/core/tests/test_suspicions_command.py | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index bb2d13a..87187f9 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -2,6 +2,7 @@ from random import randrange from django.utils import timezone +from django.test import TestCase as DjangoTestCase from jarbas.core.models import Tweet @@ -91,3 +92,10 @@ def random_tweet_status(): min_range = 9223372036854775807 # max big integer should be the minimum max_range = 10 ** status.max_digits # field limit return randrange(min_range, max_range) + + +class TestCase(DjangoTestCase): + + def serializer(self, obj, expected, input): + serialized = obj.serialize(input) + self.assertEqual(serialized, expected) diff --git a/jarbas/core/tests/shared_tests.py b/jarbas/core/tests/shared_tests.py index 6ac6715..c34f8ce 100644 --- a/jarbas/core/tests/shared_tests.py +++ b/jarbas/core/tests/shared_tests.py @@ -4,13 +4,6 @@ from jarbas.core.models import Reimbursement -# Serializer methods: TestSerializer - - -def test_serializer(TestCase, obj, expected, input): - serialized = obj.serialize(input) - TestCase.assertEqual(serialized, expected) - # Custom methods: TestCustomMethods diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index c182960..8ed5eee 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -1,7 +1,7 @@ from io import StringIO from unittest.mock import Mock, call, patch -from django.test import TestCase +from jarbas.core.tests import TestCase from jarbas.core.management.commands.suspicions import Command from jarbas.core.models import Reimbursement @@ -33,7 +33,7 @@ def test_serializer(self): 'hypothesis_3': 'True', 'probability': '0.38' } - shared_tests.test_serializer(self, self.command, expected, input) + self.serializer(self.command, expected, input) def test_serializer_without_probability(self): From 8abce0bcb5fa5860864b7bac4b7837b0eaefcf0a Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 3 Aug 2017 08:02:02 -0300 Subject: [PATCH 09/32] Moves TestCase class upwards --- jarbas/core/tests/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index 87187f9..f36fc42 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -7,6 +7,13 @@ from jarbas.core.models import Tweet +class TestCase(DjangoTestCase): + + def serializer(self, obj, expected, input): + serialized = obj.serialize(input) + self.assertEqual(serialized, expected) + + suspicions = { 'over_monthly_subquota': {'is_suspect': True, 'probability': 1.0} } @@ -92,10 +99,3 @@ def random_tweet_status(): min_range = 9223372036854775807 # max big integer should be the minimum max_range = 10 ** status.max_digits # field limit return randrange(min_range, max_range) - - -class TestCase(DjangoTestCase): - - def serializer(self, obj, expected, input): - serialized = obj.serialize(input) - self.assertEqual(serialized, expected) From 34fe8bc1f33d1f0d31abe0d7acb78ca46f5e8b76 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 3 Aug 2017 08:22:04 -0300 Subject: [PATCH 10/32] Moving remaining tests to `__init__` --- jarbas/core/tests/__init__.py | 17 ++++++++++++++- jarbas/core/tests/shared_tests.py | 22 -------------------- jarbas/core/tests/test_suspicions_command.py | 5 ++--- 3 files changed, 18 insertions(+), 26 deletions(-) delete mode 100644 jarbas/core/tests/shared_tests.py diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index f36fc42..168a278 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -1,10 +1,12 @@ from datetime import date from random import randrange +from unittest.mock import call + from django.utils import timezone from django.test import TestCase as DjangoTestCase -from jarbas.core.models import Tweet +from jarbas.core.models import Reimbursement, Tweet class TestCase(DjangoTestCase): @@ -13,6 +15,19 @@ def serializer(self, obj, expected, input): serialized = obj.serialize(input) self.assertEqual(serialized, expected) + def main(self, obj, update, schedule_update, costum_method): + costum_method.return_value = (range(21), range(21, 43)) + obj.main() + update.assert_has_calls([call()] * 2) + schedule_update.assert_has_calls(call(i) for i in range(42)) + + def schedule_update_non_existing_record(self, get, content, obj): + get.side_effect = Reimbursement.DoesNotExist + obj.queue = [] + obj.schedule_update(content) + get.assert_called_once_with(document_id=42) + self.assertEqual([], obj.queue) + suspicions = { 'over_monthly_subquota': {'is_suspect': True, 'probability': 1.0} diff --git a/jarbas/core/tests/shared_tests.py b/jarbas/core/tests/shared_tests.py deleted file mode 100644 index c34f8ce..0000000 --- a/jarbas/core/tests/shared_tests.py +++ /dev/null @@ -1,22 +0,0 @@ -from unittest.mock import call - -from django.test import TestCase - -from jarbas.core.models import Reimbursement - - -# Custom methods: TestCustomMethods - - -def test_main(TestCase, obj, update, schedule_update, costum_method): - costum_method.return_value = (range(21), range(21, 43)) - obj.main() - update.assert_has_calls([call()] * 2) - schedule_update.assert_has_calls(call(i) for i in range(42)) - -def test_schedule_update_non_existing_record(TestCase, get, content, obj): - get.side_effect = Reimbursement.DoesNotExist - obj.queue = [] - obj.schedule_update(content) - get.assert_called_once_with(document_id=42) - TestCase.assertEqual([], obj.queue) diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index 8ed5eee..2824313 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -5,7 +5,6 @@ from jarbas.core.management.commands.suspicions import Command from jarbas.core.models import Reimbursement -from jarbas.core.tests import shared_tests class TestCommand(TestCase): @@ -76,7 +75,7 @@ class TestCustomMethods(TestCommand): @patch('jarbas.core.management.commands.suspicions.Command.schedule_update') @patch('jarbas.core.management.commands.suspicions.Command.update') def test_main(self, update, schedule_update, suspicions): - shared_tests.test_main(self, self.command, update, schedule_update, suspicions) + self.main(self.command, update, schedule_update, suspicions) @patch.object(Reimbursement.objects, 'get') @@ -98,7 +97,7 @@ def test_schedule_update_existing_record(self, get): @patch.object(Reimbursement.objects, 'get') def test_schedule_update_non_existing_record(self, get): content = {'document_id': 42} - shared_tests.test_schedule_update_non_existing_record(self, get, content, self.command) + self.schedule_update_non_existing_record(get, content, self.command) @patch('jarbas.core.management.commands.suspicions.bulk_update') @patch('jarbas.core.management.commands.suspicions.print') From eff52b802be5b9ed6306eb2f7a1b7aab0b1e7cf1 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 3 Aug 2017 08:57:23 -0300 Subject: [PATCH 11/32] Updating receipts text command test suite --- jarbas/core/tests/test_receipts_text_command.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index 3d85308..257cc50 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -1,11 +1,10 @@ from io import StringIO from unittest.mock import Mock, call, patch -from django.test import TestCase +from jarbas.core.tests import TestCase from jarbas.core.management.commands.receipts_text import Command from jarbas.core.models import Reimbursement -from jarbas.core.tests import shared_tests class TestCommand(TestCase): @@ -68,7 +67,7 @@ def test_schedule_update_existing_record(self, get): @patch.object(Reimbursement.objects, 'get') def test_schedule_update_non_existing_record(self, get): content = {'document_id': 42} - shared_tests.test_schedule_update_non_existing_record(self, get, content, self.command) + self.schedule_update_non_existing_record(get, content, self.command) @patch('jarbas.core.management.commands.receipts_text.bulk_update') @patch('jarbas.core.management.commands.receipts_text.print') From 15b9411012fc04ac03b739c53085c868c0ae5b7a Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 3 Aug 2017 09:37:23 -0300 Subject: [PATCH 12/32] improve order of method arguments --- jarbas/core/tests/__init__.py | 2 +- jarbas/core/tests/test_suspicions_command.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index 168a278..34bf717 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -11,7 +11,7 @@ class TestCase(DjangoTestCase): - def serializer(self, obj, expected, input): + def serializer(self, obj, input, expected): serialized = obj.serialize(input) self.assertEqual(serialized, expected) diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index 2824313..f8a3bf2 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -32,7 +32,7 @@ def test_serializer(self): 'hypothesis_3': 'True', 'probability': '0.38' } - self.serializer(self.command, expected, input) + self.serializer(self.command, input, expected) def test_serializer_without_probability(self): @@ -51,7 +51,7 @@ def test_serializer_without_probability(self): 'hypothesis_2': 'False', 'hypothesis_3': 'True' } - self.assertEqual(self.command.serialize(input), expected) + self.serializer(self.command, input, expected) def test_serializer_without_suspicions(self): expected = { From 15f1b2f13556f50cedbd22fffc2cecc66a5f6261 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 3 Aug 2017 09:41:00 -0300 Subject: [PATCH 13/32] using serializer method for testing --- jarbas/core/tests/test_receipts_text_command.py | 4 ++-- jarbas/core/tests/test_suspicions_command.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index 257cc50..21d7866 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -25,7 +25,7 @@ def test_serializer(self): 'document_id': '42', 'text': 'lorem ipsum' } - self.assertEqual(self.command.serialize(input), expected) + self.serializer(self.command, input, expected) def test_serializer_without_text(self): expected = { @@ -36,7 +36,7 @@ def test_serializer_without_text(self): input = { 'document_id': '42', } - self.assertEqual(self.command.serialize(input), expected) + self.serializer(self.command, input, expected) class TestCustomMethods(TestCommand): diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index f8a3bf2..b7640d7 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -66,7 +66,7 @@ def test_serializer_without_suspicions(self): 'hypothesis_2': 'False', 'hypothesis_3': 'False' } - self.assertEqual(self.command.serialize(input), expected) + self.serializer(self.command, input, expected) class TestCustomMethods(TestCommand): From 2cc3c37543f157c6f0bee0d0b02d58971d1d2878 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 3 Aug 2017 09:43:46 -0300 Subject: [PATCH 14/32] Better naming for variables --- jarbas/core/tests/__init__.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index 34bf717..ab62a53 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -11,22 +11,22 @@ class TestCase(DjangoTestCase): - def serializer(self, obj, input, expected): - serialized = obj.serialize(input) + def serializer(self, command, input, expected): + serialized = command.serialize(input) self.assertEqual(serialized, expected) - def main(self, obj, update, schedule_update, costum_method): + def main(self, command, update, schedule_update, costum_method): costum_method.return_value = (range(21), range(21, 43)) - obj.main() + command.main() update.assert_has_calls([call()] * 2) schedule_update.assert_has_calls(call(i) for i in range(42)) - def schedule_update_non_existing_record(self, get, content, obj): + def schedule_update_non_existing_record(self, get, content, command): get.side_effect = Reimbursement.DoesNotExist - obj.queue = [] - obj.schedule_update(content) + command.queue = [] + command.schedule_update(content) get.assert_called_once_with(document_id=42) - self.assertEqual([], obj.queue) + self.assertEqual([], command.queue) suspicions = { From 2d8b854cecc5e2be62e155b093fc69725b98568c Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 3 Aug 2017 09:47:45 -0300 Subject: [PATCH 15/32] Improving posicional arguments ordering --- jarbas/core/tests/__init__.py | 2 +- jarbas/core/tests/test_receipts_text_command.py | 2 +- jarbas/core/tests/test_suspicions_command.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index ab62a53..edb666b 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -21,7 +21,7 @@ def main(self, command, update, schedule_update, costum_method): update.assert_has_calls([call()] * 2) schedule_update.assert_has_calls(call(i) for i in range(42)) - def schedule_update_non_existing_record(self, get, content, command): + def schedule_update_non_existing_record(self, command, content, get): get.side_effect = Reimbursement.DoesNotExist command.queue = [] command.schedule_update(content) diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index 21d7866..bf5664d 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -67,7 +67,7 @@ def test_schedule_update_existing_record(self, get): @patch.object(Reimbursement.objects, 'get') def test_schedule_update_non_existing_record(self, get): content = {'document_id': 42} - self.schedule_update_non_existing_record(get, content, self.command) + self.schedule_update_non_existing_record(self.command, content, get) @patch('jarbas.core.management.commands.receipts_text.bulk_update') @patch('jarbas.core.management.commands.receipts_text.print') diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index b7640d7..48534c7 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -97,7 +97,7 @@ def test_schedule_update_existing_record(self, get): @patch.object(Reimbursement.objects, 'get') def test_schedule_update_non_existing_record(self, get): content = {'document_id': 42} - self.schedule_update_non_existing_record(get, content, self.command) + self.schedule_update_non_existing_record(self.command, content, get) @patch('jarbas.core.management.commands.suspicions.bulk_update') @patch('jarbas.core.management.commands.suspicions.print') From f44132728dcf071b376137ff1b5286738c4d42f3 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 3 Aug 2017 10:05:31 -0300 Subject: [PATCH 16/32] updates main testign on receipts text command test suite --- jarbas/core/tests/test_receipts_text_command.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index bf5664d..af18960 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -45,10 +45,7 @@ class TestCustomMethods(TestCommand): @patch('jarbas.core.management.commands.receipts_text.Command.schedule_update') @patch('jarbas.core.management.commands.receipts_text.Command.update') def test_main(self, update, schedule_update, receipts): - receipts.return_value = (range(21), range(21, 43)) - self.command.main() - update.assert_has_calls([call()] * 2) - schedule_update.assert_has_calls(call(i) for i in range(42)) + self.main(self.command, update, schedule_update, receipts) @patch.object(Reimbursement.objects, 'get') def test_schedule_update_existing_record(self, get): From 8d451ae17283b053c652b40c9f888bf689d0f952 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 3 Aug 2017 10:14:14 -0300 Subject: [PATCH 17/32] update now in __init__ - Created update method on `__init__` - updated suspicions command test suite to use new update method - updated receipts text command test suite to use new update method --- jarbas/core/tests/__init__.py | 8 ++++++++ jarbas/core/tests/test_receipts_text_command.py | 7 +------ jarbas/core/tests/test_suspicions_command.py | 7 +------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index edb666b..f99bf42 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -28,6 +28,14 @@ def schedule_update_non_existing_record(self, command, content, get): get.assert_called_once_with(document_id=42) self.assertEqual([], command.queue) + def update(self, command, fields, print_, bulk_update): + command.count = 40 + command.queue = list(range(2)) + command.update() + bulk_update.assert_called_with([0, 1], update_fields=fields) + print_.assert_called_with('42 reimbursements updated.', end='\r') + self.assertEqual(42, command.count) + suspicions = { 'over_monthly_subquota': {'is_suspect': True, 'probability': 1.0} diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index af18960..da2892e 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -69,13 +69,8 @@ def test_schedule_update_non_existing_record(self, get): @patch('jarbas.core.management.commands.receipts_text.bulk_update') @patch('jarbas.core.management.commands.receipts_text.print') def test_update(self, print_, bulk_update): - self.command.count = 40 - self.command.queue = list(range(2)) - self.command.update() fields = ['receipt_text',] - bulk_update.assert_called_with([0, 1], update_fields=fields) - print_.assert_called_with('42 reimbursements updated.', end='\r') - self.assertEqual(42, self.command.count) + self.update(self.command, fields, print_, bulk_update) class TestConventionMethods(TestCommand): diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index 48534c7..df0cdb1 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -102,13 +102,8 @@ def test_schedule_update_non_existing_record(self, get): @patch('jarbas.core.management.commands.suspicions.bulk_update') @patch('jarbas.core.management.commands.suspicions.print') def test_update(self, print_, bulk_update): - self.command.count = 40 - self.command.queue = list(range(2)) - self.command.update() fields = ['probability', 'suspicions'] - bulk_update.assert_called_with([0, 1], update_fields=fields) - print_.assert_called_with('42 reimbursements updated.', end='\r') - self.assertEqual(42, self.command.count) + self.update(self.command, fields, print_, bulk_update) def test_bool(self): self.assertTrue(self.command.bool('True')) From bca0039fd79774ea27d716aae4d2c340c6569a0e Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 3 Aug 2017 11:30:53 -0300 Subject: [PATCH 18/32] handler_with_options() now in __init__ - Created handler_with_options method on `__init__` - updated suspicions command test suite to use new handler_with_options method - updated receipts text command test suite to use new handler_with_options method --- jarbas/core/tests/__init__.py | 7 +++++++ jarbas/core/tests/test_receipts_text_command.py | 7 ++----- jarbas/core/tests/test_suspicions_command.py | 7 ++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index f99bf42..06397b2 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -36,6 +36,13 @@ def update(self, command, fields, print_, bulk_update): print_.assert_called_with('42 reimbursements updated.', end='\r') self.assertEqual(42, command.count) + def handler_with_options(self, command, print_, exits, main, costum_command): + command.handle(dataset=self.file_name, batch_size=42) + main.assert_called_once_with() + print_.assert_called_once_with('0 reimbursements updated.') + self.assertEqual(command.path, self.file_name) + self.assertEqual(command.batch_size, 42) + suspicions = { 'over_monthly_subquota': {'is_suspect': True, 'probability': 1.0} diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index da2892e..7a1bfb4 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -11,6 +11,7 @@ class TestCommand(TestCase): def setUp(self): self.command = Command() + self.file_name = 'receipts-texts.xz' class TestSerializer(TestCommand): @@ -80,11 +81,7 @@ class TestConventionMethods(TestCommand): @patch('jarbas.core.management.commands.receipts_text.os.path.exists') @patch('jarbas.core.management.commands.receipts_text.print') def test_handler_with_options(self, print_, exists, main, receipts): - self.command.handle(dataset='receipts-texts.xz', batch_size=42) - main.assert_called_once_with() - print_.assert_called_once_with('0 reimbursements updated.') - self.assertEqual(self.command.path, 'receipts-texts.xz') - self.assertEqual(self.command.batch_size, 42) + self.handler_with_options(self.command, print_, exists, main, receipts) @patch('jarbas.core.management.commands.receipts_text.Command.receipts') @patch('jarbas.core.management.commands.receipts_text.Command.main') diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index df0cdb1..5c12db2 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -11,6 +11,7 @@ class TestCommand(TestCase): def setUp(self): self.command = Command() + self.file_name = 'suspicions.xz' class TestSerializer(TestCommand): @@ -128,11 +129,7 @@ class TestConventionMethods(TestCommand): @patch('jarbas.core.management.commands.suspicions.os.path.exists') @patch('jarbas.core.management.commands.suspicions.print') def test_handler_with_options(self, print_, exists, main, suspicions): - self.command.handle(dataset='suspicions.xz', batch_size=42) - main.assert_called_once_with() - print_.assert_called_once_with('0 reimbursements updated.') - self.assertEqual(self.command.path, 'suspicions.xz') - self.assertEqual(self.command.batch_size, 42) + self.handler_with_options(self.command, print_, exists, main, suspicions) @patch('jarbas.core.management.commands.suspicions.Command.suspicions') @patch('jarbas.core.management.commands.suspicions.Command.main') From b4836f85268f3d16105b953539bfeb59377b14b6 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 3 Aug 2017 11:37:40 -0300 Subject: [PATCH 19/32] handler_without_options() now in __init__ - Created handler_without_options method on `__init__` - updated suspicions command test suite to use new handler_without_options method - updated receipts text command test suite to use new handler_without_options method --- jarbas/core/tests/__init__.py | 7 +++++++ jarbas/core/tests/test_receipts_text_command.py | 6 +----- jarbas/core/tests/test_suspicions_command.py | 6 +----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index 06397b2..2660a2d 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -43,6 +43,13 @@ def handler_with_options(self, command, print_, exits, main, costum_command): self.assertEqual(command.path, self.file_name) self.assertEqual(command.batch_size, 42) + def handler_without_options(self, command, print_, exits, main, costum_command): + command.handle(dataset=self.file_name, batch_size=4096) + main.assert_called_once_with() + print_.assert_called_once_with('0 reimbursements updated.') + self.assertEqual(command.path, self.file_name) + self.assertEqual(command.batch_size, 4096) + suspicions = { 'over_monthly_subquota': {'is_suspect': True, 'probability': 1.0} diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index 7a1bfb4..a03e645 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -88,11 +88,7 @@ def test_handler_with_options(self, print_, exists, main, receipts): @patch('jarbas.core.management.commands.receipts_text.os.path.exists') @patch('jarbas.core.management.commands.receipts_text.print') def test_handler_without_options(self, print_, exists, main, receipts): - self.command.handle(dataset='receipts-texts.xz', batch_size=4096) - main.assert_called_once_with() - print_.assert_called_once_with('0 reimbursements updated.') - self.assertEqual(self.command.path, 'receipts-texts.xz') - self.assertEqual(self.command.batch_size, 4096) + self.handler_without_options(self.command, print_, exists, main, receipts) @patch('jarbas.core.management.commands.receipts_text.Command.receipts') @patch('jarbas.core.management.commands.receipts_text.Command.main') diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index 5c12db2..bb37d58 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -136,11 +136,7 @@ def test_handler_with_options(self, print_, exists, main, suspicions): @patch('jarbas.core.management.commands.suspicions.os.path.exists') @patch('jarbas.core.management.commands.suspicions.print') def test_handler_without_options(self, print_, exists, main, suspicions): - self.command.handle(dataset='suspicions.xz', batch_size=4096) - main.assert_called_once_with() - print_.assert_called_once_with('0 reimbursements updated.') - self.assertEqual(self.command.path, 'suspicions.xz') - self.assertEqual(self.command.batch_size, 4096) + self.handler_without_options(self.command, print_, exists, main, suspicions) @patch('jarbas.core.management.commands.suspicions.Command.suspicions') @patch('jarbas.core.management.commands.suspicions.Command.main') From 66a2dca2877a6c881645f3ee5a845116ca9172ec Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 3 Aug 2017 11:45:57 -0300 Subject: [PATCH 20/32] handler_with_non_existing_file() now in __init__ - Created handler_with_non_existing_file method on `__init__` - updated suspicions command test suite to use new handler_with_non_existing_file method - updated receipts text command test suite to use new handler_with_non_existing_file method --- jarbas/core/tests/__init__.py | 6 ++++++ jarbas/core/tests/test_receipts_text_command.py | 5 +---- jarbas/core/tests/test_suspicions_command.py | 5 +---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index 2660a2d..2f5a479 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -50,6 +50,12 @@ def handler_without_options(self, command, print_, exits, main, costum_command): self.assertEqual(command.path, self.file_name) self.assertEqual(command.batch_size, 4096) + def handler_with_non_existing_file(self, command, exists, update, costum_command): + exists.return_value = False + with self.assertRaises(FileNotFoundError): + command.handle(dataset='suspicions.xz', batch_size=4096) + update.assert_not_called() + suspicions = { 'over_monthly_subquota': {'is_suspect': True, 'probability': 1.0} diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index a03e645..e57517c 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -94,10 +94,7 @@ def test_handler_without_options(self, print_, exists, main, receipts): @patch('jarbas.core.management.commands.receipts_text.Command.main') @patch('jarbas.core.management.commands.receipts_text.os.path.exists') def test_handler_with_non_existing_file(self, exists, update, receipts): - exists.return_value = False - with self.assertRaises(FileNotFoundError): - self.command.handle(dataset='receipts-text.xz', batch_size=4096) - update.assert_not_called() + self.handler_with_non_existing_file(self.command, exists, update, receipts) class TestFileLoader(TestCommand): diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index bb37d58..e96450f 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -142,10 +142,7 @@ def test_handler_without_options(self, print_, exists, main, suspicions): @patch('jarbas.core.management.commands.suspicions.Command.main') @patch('jarbas.core.management.commands.suspicions.os.path.exists') def test_handler_with_non_existing_file(self, exists, update, suspicions): - exists.return_value = False - with self.assertRaises(FileNotFoundError): - self.command.handle(dataset='suspicions.xz', batch_size=4096) - update.assert_not_called() + self.handler_with_non_existing_file(self.command, exists, update, suspicions) class TestFileLoader(TestCommand): From 6d16652577e665458706d79d02c0a955036a4f20 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Fri, 4 Aug 2017 13:19:03 -0300 Subject: [PATCH 21/32] new_command() now in __init__ - Created new_command method on `__init__` - updated suspicions command test suite to use new_command method - updated receipts text command test suite to use new_command method --- jarbas/core/tests/__init__.py | 11 +++++++++++ jarbas/core/tests/test_receipts_text_command.py | 14 ++++---------- jarbas/core/tests/test_suspicions_command.py | 10 ++-------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index 2f5a479..a570b1e 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -1,3 +1,4 @@ +from io import StringIO from datetime import date from random import randrange @@ -56,6 +57,16 @@ def handler_with_non_existing_file(self, command, exists, update, costum_command command.handle(dataset='suspicions.xz', batch_size=4096) update.assert_not_called() + def new_command(self, command, costum_command, serialize, rows, lzma, print_): + serialize.return_value = '.' + lzma.return_value = StringIO() + rows.return_value = range(42) + command.batch_size = 10 + command.path = self.file_name + expected = [['.'] * 10, ['.'] * 10, ['.'] * 10, ['.'] * 10, ['.'] * 2] + self.assertEqual(expected, list(costum_command)) + self.assertEqual(42, serialize.call_count) + suspicions = { 'over_monthly_subquota': {'is_suspect': True, 'probability': 1.0} diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index e57517c..1a256bf 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -104,19 +104,13 @@ class TestFileLoader(TestCommand): @patch('jarbas.core.management.commands.receipts_text.csv.DictReader') @patch('jarbas.core.management.commands.receipts_text.Command.serialize') def test_receipts(self, serialize, rows, lzma, print_): - serialize.return_value = '.' - lzma.return_value = StringIO() - rows.return_value = range(42) - self.command.batch_size = 10 - self.command.path = 'receipts-text.xz' - expected = [['.'] * 10, ['.'] * 10, ['.'] * 10, ['.'] * 10, ['.'] * 2] - self.assertEqual(expected, list(self.command.receipts())) - self.assertEqual(42, serialize.call_count) + self.new_command(self.command, self.command.receipts(), + serialize, rows, lzma, print_) -class TestAddArguments(TestCase): +class TestAddArguments(TestCommand): def test_add_arguments(self): mock = Mock() - Command().add_arguments(mock) + self.command.add_arguments(mock) self.assertEqual(2, mock.add_argument.call_count) diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index e96450f..659182d 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -152,14 +152,8 @@ class TestFileLoader(TestCommand): @patch('jarbas.core.management.commands.suspicions.csv.DictReader') @patch('jarbas.core.management.commands.suspicions.Command.serialize') def test_suspicions(self, serialize, rows, lzma, print_): - serialize.return_value = '.' - lzma.return_value = StringIO() - rows.return_value = range(42) - self.command.batch_size = 10 - self.command.path = 'suspicions.xz' - expected = [['.'] * 10, ['.'] * 10, ['.'] * 10, ['.'] * 10, ['.'] * 2] - self.assertEqual(expected, list(self.command.suspicions())) - self.assertEqual(42, serialize.call_count) + self.new_command(self.command, self.command.suspicions(), + serialize, rows, lzma, print_) class TestAddArguments(TestCase): From 33da61f51b6f1d3ac98fa2ca58adb3a01aeea1de Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Fri, 4 Aug 2017 18:43:14 -0300 Subject: [PATCH 22/32] add_arguments now in __init__ - Created add_arguments method on __init__ - updated suspicions command test suite to use new add_arguments method - updated receipts text command test suite to use new add_arguments method --- jarbas/core/tests/__init__.py | 7 ++++++- jarbas/core/tests/test_receipts_text_command.py | 8 +++----- jarbas/core/tests/test_suspicions_command.py | 9 +++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index a570b1e..2aab6a9 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -2,7 +2,7 @@ from datetime import date from random import randrange -from unittest.mock import call +from unittest.mock import Mock, call from django.utils import timezone from django.test import TestCase as DjangoTestCase @@ -67,6 +67,11 @@ def new_command(self, command, costum_command, serialize, rows, lzma, print_): self.assertEqual(expected, list(costum_command)) self.assertEqual(42, serialize.call_count) + def add_arguments(self, command): + mock = Mock() + command.add_arguments(mock) + self.assertEqual(2, mock.add_argument.call_count) + suspicions = { 'over_monthly_subquota': {'is_suspect': True, 'probability': 1.0} diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index 1a256bf..858c705 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -1,5 +1,4 @@ -from io import StringIO -from unittest.mock import Mock, call, patch +from unittest.mock import patch from jarbas.core.tests import TestCase @@ -111,6 +110,5 @@ def test_receipts(self, serialize, rows, lzma, print_): class TestAddArguments(TestCommand): def test_add_arguments(self): - mock = Mock() - self.command.add_arguments(mock) - self.assertEqual(2, mock.add_argument.call_count) + self.add_arguments(self.command) + self.add_arguments(self.command) diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index 659182d..60de08a 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -1,5 +1,4 @@ -from io import StringIO -from unittest.mock import Mock, call, patch +from unittest.mock import patch from jarbas.core.tests import TestCase @@ -156,9 +155,7 @@ def test_suspicions(self, serialize, rows, lzma, print_): serialize, rows, lzma, print_) -class TestAddArguments(TestCase): +class TestAddArguments(TestCommand): def test_add_arguments(self): - mock = Mock() - Command().add_arguments(mock) - self.assertEqual(2, mock.add_argument.call_count) + self.add_arguments(self.command) From 18701a98ca6305c7c39033cc1673697aa718bfb1 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Sat, 5 Aug 2017 09:03:31 -0300 Subject: [PATCH 23/32] removing repeated line --- jarbas/core/tests/test_receipts_text_command.py | 1 - 1 file changed, 1 deletion(-) diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index 858c705..67104f8 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -111,4 +111,3 @@ class TestAddArguments(TestCommand): def test_add_arguments(self): self.add_arguments(self.command) - self.add_arguments(self.command) From 19d4d9e65af3091a5b4e0afb5a93e71a2908fc9d Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Sat, 5 Aug 2017 12:05:57 -0300 Subject: [PATCH 24/32] Using command defined on setup --- jarbas/core/tests/test_receipts_command.py | 89 ++++++++++------------ 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/jarbas/core/tests/test_receipts_command.py b/jarbas/core/tests/test_receipts_command.py index f1ed490..e336b96 100644 --- a/jarbas/core/tests/test_receipts_command.py +++ b/jarbas/core/tests/test_receipts_command.py @@ -1,13 +1,19 @@ from unittest.mock import Mock, call, patch -from django.test import TestCase +from jarbas.core.tests import TestCase from django.db.models import QuerySet from requests.exceptions import ConnectionError from jarbas.core.management.commands.receipts import Command -class TestCommandHandler(TestCase): +class TestCommand(TestCase): + + def setUp(self): + self.command = Command() + + +class TestCommandHandler(TestCommand): @patch('jarbas.core.management.commands.receipts.Command.get_queryset') @patch('jarbas.core.management.commands.receipts.Command.fetch') @@ -17,33 +23,31 @@ class TestCommandHandler(TestCase): @patch('jarbas.core.management.commands.receipts.print') def test_handler_with_queryset(self, print_, sleep, print_pause, print_count, fetch, get_queryset): get_queryset.side_effect = (True, True, True, False) - command = Command() - command.handle(batch_size=3, pause=42) + self.command.handle(batch_size=3, pause=42) print_.assert_has_calls((call('Loading…'), call('Done!'))) print_pause.assert_has_calls((call(), call())) print_count.assert_called_once_with(permanent=True) sleep.assert_has_calls([call(42)] * 2) self.assertEqual(3, fetch.call_count) - self.assertEqual(3, command.batch) - self.assertEqual(42, command.pause) - self.assertEqual(0, command.count) + self.assertEqual(3, self.command.batch) + self.assertEqual(42, self.command.pause) + self.assertEqual(0, self.command.count) @patch('jarbas.core.management.commands.receipts.Command.get_queryset') @patch('jarbas.core.management.commands.receipts.Command.fetch') @patch('jarbas.core.management.commands.receipts.print') def test_handler_without_queryset(self, print_, fetch, get_queryset): get_queryset.return_value = False - command = Command() - command.handle(batch_size=42, pause=1) + self.command.handle(batch_size=42, pause=1) print_.assert_has_calls([ call('Loading…'), call('Nothing to fetch.') ]) get_queryset.assert_called_once_with() fetch.assert_not_called() - self.assertEqual(42, command.batch) - self.assertEqual(1, command.pause) - self.assertEqual(0, command.count) + self.assertEqual(42, self.command.batch) + self.assertEqual(1, self.command.pause) + self.assertEqual(0, self.command.count) def test_add_arguments(self): parser = Mock() @@ -52,70 +56,64 @@ def test_add_arguments(self): self.assertEqual(2, parser.add_argument.call_count) -class TestCommandMethods(TestCase): +class TestCommandMethods(TestCommand): @patch('jarbas.core.management.commands.receipts.Command.update') @patch('jarbas.core.management.commands.receipts.Command.bulk_update') @patch('jarbas.core.management.commands.receipts.Command.print_count') def test_fetch(self, print_count, bulk_update, update): - command = Command() - command.count = 0 - command.queryset = (1, 2, 3) - command.queue = [] - command.fetch() + self.command.count = 0 + self.command.queryset = (1, 2, 3) + self.command.queue = [] + self.command.fetch() print_count.assert_has_calls((call(), call(), call())) update.assert_has_calls(call(i) for i in range(1, 4)) - self.assertEqual(3, command.count) + self.assertEqual(3, self.command.count) bulk_update.assert_called_once_with() @patch.object(QuerySet, '__getitem__') @patch.object(QuerySet, 'filter', return_value=QuerySet()) def test_get_queryset(self, filter_, getitem): - command = Command() - command.batch = 42 - command.get_queryset() + self.command.batch = 42 + self.command.get_queryset() filter_.assert_called_once_with(receipt_fetched=False) getitem.assert_called_once_with(slice(None, 42)) def test_update(self): reimbursement = Mock() - command = Command() - command.queue = [] - command.update(reimbursement) + self.command.queue = [] + self.command.update(reimbursement) reimbursement.get_receipt_url.assert_called_once_with(bulk=True) - self.assertEqual(1, len(command.queue)) + self.assertEqual(1, len(self.command.queue)) def test_update_with_error(self): reimbursement = Mock() reimbursement.get_receipt_url.side_effect = ConnectionError() - command = Command() - command.queue = [] - command.update(reimbursement) + self.command.queue = [] + self.command.update(reimbursement) reimbursement.get_receipt_url.assert_called_once_with(bulk=True) - self.assertEqual(0, len(command.queue)) + self.assertEqual(0, len(self.command.queue)) @patch('jarbas.core.management.commands.receipts.bulk_update') @patch('jarbas.core.management.commands.receipts.Command.print_saving') def test_bulk_update(self, print_saving, bulk_update): - command = Command() - command.queue = [1, 2, 3] - command.bulk_update() + self.command.queue = [1, 2, 3] + self.command.bulk_update() fields = ['receipt_url', 'receipt_fetched'] bulk_update.assert_called_once_with([1, 2, 3], update_fields=fields) - self.assertEqual([], command.queue) + self.assertEqual([], self.command.queue) print_saving.assert_called_once_with() -class TestCommandPrintMethods(TestCase): +class TestCommandPrintMethods(TestCommand): def test_count_msg(self): - command = Command() - command.count = 42 - self.assertEqual('42 receipt URLs fetched', command.count_msg()) + self.command.count = 42 + self.assertEqual('42 receipt URLs fetched', self.command.count_msg()) @patch('jarbas.core.management.commands.receipts.print') def test_print_msg(self, print_): - Command.print_msg('42') + self.command.print_msg('42') print_.assert_has_calls(( call('\x1b[1A\x1b[2K\x1b[1A'), call('42') @@ -123,30 +121,27 @@ def test_print_msg(self, print_): @patch('jarbas.core.management.commands.receipts.print') def test_print_permanent_msg(self, print_): - Command.print_msg('42', permanent=True) + self.command.print_msg('42', permanent=True) print_.assert_called_once_with('42') @patch('jarbas.core.management.commands.receipts.Command.count_msg') @patch('jarbas.core.management.commands.receipts.Command.print_msg') def test_print_count(self, print_msg, count_msg): count_msg.return_value = '42' - command = Command() - command.print_count() - command.print_count(permanent=True) + self.command.print_count() + self.command.print_count(permanent=True) print_msg.assert_has_calls((call('42'), call('42', permanent=True))) @patch('jarbas.core.management.commands.receipts.Command.count_msg') @patch('jarbas.core.management.commands.receipts.Command.print_msg') def test_print_pause(self, print_msg, count_msg): count_msg.return_value = '42' - command = Command() - command.print_pause() + self.command.print_pause() print_msg.assert_called_once_with('42 (Taking a break to avoid being blocked…)') @patch('jarbas.core.management.commands.receipts.Command.count_msg') @patch('jarbas.core.management.commands.receipts.Command.print_msg') def test_print_saving(self, print_msg, count_msg): count_msg.return_value = '42' - command = Command() - command.print_saving() + self.command.print_saving() print_msg.assert_called_once_with('42 (Saving the URLs to the database…)') From 132545c69cd55644e6850eba96860a63f0593d14 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Sat, 5 Aug 2017 12:07:02 -0300 Subject: [PATCH 25/32] Using command defined on __init__ --- jarbas/core/tests/test_receipts_command.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/jarbas/core/tests/test_receipts_command.py b/jarbas/core/tests/test_receipts_command.py index e336b96..d205ab9 100644 --- a/jarbas/core/tests/test_receipts_command.py +++ b/jarbas/core/tests/test_receipts_command.py @@ -50,10 +50,7 @@ def test_handler_without_queryset(self, print_, fetch, get_queryset): self.assertEqual(0, self.command.count) def test_add_arguments(self): - parser = Mock() - command = Command() - command.add_arguments(parser) - self.assertEqual(2, parser.add_argument.call_count) + self.add_arguments(self.command) class TestCommandMethods(TestCommand): From 2bf67802c8d3f628ae3fe4f77022685835cadcde Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Sat, 5 Aug 2017 12:15:11 -0300 Subject: [PATCH 26/32] using serializer defined on __init__ --- jarbas/core/tests/test_companies_command.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jarbas/core/tests/test_companies_command.py b/jarbas/core/tests/test_companies_command.py index f9995d6..06935a0 100644 --- a/jarbas/core/tests/test_companies_command.py +++ b/jarbas/core/tests/test_companies_command.py @@ -2,7 +2,7 @@ from io import StringIO from unittest.mock import patch -from django.test import TestCase +from jarbas.core.tests import TestCase from jarbas.core.management.commands.companies import Command from jarbas.core.models import Activity, Company @@ -23,7 +23,7 @@ def test_to_email(self): self.assertEqual(self.command.to_email('jane@example.com'), expected) def test_serializer(self): - company = { + input = { 'email': 'ahoy', 'opening': '31/12/1969', 'situation_date': '31/12/1969', @@ -39,7 +39,7 @@ def test_serializer(self): 'latitude': 3.1415, 'longitude': -42.0 } - self.assertEqual(self.command.serialize(company), expected) + self.serializer(self.command, input, expected) class TestCreate(TestCommand): From 77ac4f91dfb74ea720bb1bfa952869885ea67990 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Sat, 5 Aug 2017 12:18:01 -0300 Subject: [PATCH 27/32] Reordering tests on companies command test suite --- jarbas/core/tests/test_companies_command.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/jarbas/core/tests/test_companies_command.py b/jarbas/core/tests/test_companies_command.py index 06935a0..c57c4d0 100644 --- a/jarbas/core/tests/test_companies_command.py +++ b/jarbas/core/tests/test_companies_command.py @@ -83,25 +83,25 @@ def test_save_companies(self, create, print_count, serialize, save_activities, r class TestConventionMethods(TestCommand): @patch('jarbas.core.management.commands.companies.print') - @patch('jarbas.core.management.commands.companies.LoadCommand.drop_all') + @patch('jarbas.core.management.commands.companies.Command.drop_all') @patch('jarbas.core.management.commands.companies.Command.save_companies') @patch('jarbas.core.management.commands.companies.Command.print_count') - def test_handler_without_options(self, print_count, save_companies, drop_all, print_): + def test_handler_with_options(self, print_count, save_companies, drop_all, print_): print_count.return_value = 0 - self.command.handle(dataset='companies.xz') + self.command.handle(dataset='companies.xz', drop=True) print_.assert_called_with('Starting with 0 companies') + self.assertEqual(2, drop_all.call_count) self.assertEqual(1, save_companies.call_count) - self.assertEqual(1, print_count.call_count) - self.assertEqual('companies.xz', self.command.path) - drop_all.assert_not_called() @patch('jarbas.core.management.commands.companies.print') - @patch('jarbas.core.management.commands.companies.Command.drop_all') + @patch('jarbas.core.management.commands.companies.LoadCommand.drop_all') @patch('jarbas.core.management.commands.companies.Command.save_companies') @patch('jarbas.core.management.commands.companies.Command.print_count') - def test_handler_with_options(self, print_count, save_companies, drop_all, print_): + def test_handler_without_options(self, print_count, save_companies, drop_all, print_): print_count.return_value = 0 - self.command.handle(dataset='companies.xz', drop=True) + self.command.handle(dataset='companies.xz') print_.assert_called_with('Starting with 0 companies') - self.assertEqual(2, drop_all.call_count) self.assertEqual(1, save_companies.call_count) + self.assertEqual(1, print_count.call_count) + self.assertEqual('companies.xz', self.command.path) + drop_all.assert_not_called() From de09fb107fa6087c8043a117a9bc23c2f717e023 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Sat, 5 Aug 2017 12:22:57 -0300 Subject: [PATCH 28/32] Adds file_name to setUp() --- jarbas/core/tests/test_companies_command.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jarbas/core/tests/test_companies_command.py b/jarbas/core/tests/test_companies_command.py index c57c4d0..c8817af 100644 --- a/jarbas/core/tests/test_companies_command.py +++ b/jarbas/core/tests/test_companies_command.py @@ -13,6 +13,7 @@ class TestCommand(TestCase): def setUp(self): self.command = Command() + self.file_name = 'companies.xz' class TestSerializer(TestCommand): @@ -88,7 +89,7 @@ class TestConventionMethods(TestCommand): @patch('jarbas.core.management.commands.companies.Command.print_count') def test_handler_with_options(self, print_count, save_companies, drop_all, print_): print_count.return_value = 0 - self.command.handle(dataset='companies.xz', drop=True) + self.command.handle(dataset=self.file_name, drop=True) print_.assert_called_with('Starting with 0 companies') self.assertEqual(2, drop_all.call_count) self.assertEqual(1, save_companies.call_count) @@ -99,9 +100,9 @@ def test_handler_with_options(self, print_count, save_companies, drop_all, print @patch('jarbas.core.management.commands.companies.Command.print_count') def test_handler_without_options(self, print_count, save_companies, drop_all, print_): print_count.return_value = 0 - self.command.handle(dataset='companies.xz') + self.command.handle(dataset=self.file_name) print_.assert_called_with('Starting with 0 companies') self.assertEqual(1, save_companies.call_count) self.assertEqual(1, print_count.call_count) - self.assertEqual('companies.xz', self.command.path) + self.assertEqual(self.file_name, self.command.path) drop_all.assert_not_called() From ff1bed4b6affbc58aa8870c19a1a99431408f2de Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Sat, 5 Aug 2017 12:41:42 -0300 Subject: [PATCH 29/32] Using add_arguments() and moved setup and naming cmd was the same as command in other test suite and is now on a super setUp --- jarbas/core/tests/test_load_command.py | 53 ++++++++++++-------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/jarbas/core/tests/test_load_command.py b/jarbas/core/tests/test_load_command.py index 01445d8..7dcf80b 100644 --- a/jarbas/core/tests/test_load_command.py +++ b/jarbas/core/tests/test_load_command.py @@ -1,47 +1,46 @@ from datetime import date from unittest.mock import Mock, patch -from django.test import TestCase +from jarbas.core.tests import TestCase from jarbas.core.management.commands import LoadCommand from jarbas.core.models import Activity from jarbas.core.tests import sample_activity_data -class TestStaticMethods(TestCase): +class TestCommand(TestCase): def setUp(self): - self.cmd = LoadCommand() + self.command = LoadCommand() + +class TestStaticMethods(TestCommand): def test_get_model_name(self): - self.assertEqual('Activity', self.cmd.get_model_name(Activity)) + self.assertEqual('Activity', self.command.get_model_name(Activity)) def test_to_date(self): expected = date(1991, 7, 22) - self.assertEqual(self.cmd.to_date('22/7/91'), expected) - self.assertEqual(self.cmd.to_date('1991-07-22 03:15:00+0300'), expected) - self.assertEqual(self.cmd.to_date('22/13/91'), None) - self.assertEqual(self.cmd.to_date('aa/7/91'), None) - self.assertEqual(self.cmd.to_date('22/07/16'), date(2016, 7, 22)) + self.assertEqual(self.command.to_date('22/7/91'), expected) + self.assertEqual(self.command.to_date('1991-07-22 03:15:00+0300'), expected) + self.assertEqual(self.command.to_date('22/13/91'), None) + self.assertEqual(self.command.to_date('aa/7/91'), None) + self.assertEqual(self.command.to_date('22/07/16'), date(2016, 7, 22)) def test_to_number(self): - self.assertIsNone(self.cmd.to_number('')) - self.assertIsNone(self.cmd.to_number('NaN')) - self.assertIsNone(self.cmd.to_number('nan')) - self.assertEqual(1.0, self.cmd.to_number('1')) - self.assertEqual(1.2, self.cmd.to_number('1.2')) - self.assertEqual(1, self.cmd.to_number('1', int)) - self.assertEqual(1, self.cmd.to_number('1.0', int)) - + self.assertIsNone(self.command.to_number('')) + self.assertIsNone(self.command.to_number('NaN')) + self.assertIsNone(self.command.to_number('nan')) + self.assertEqual(1.0, self.command.to_number('1')) + self.assertEqual(1.2, self.command.to_number('1.2')) + self.assertEqual(1, self.command.to_number('1', int)) + self.assertEqual(1, self.command.to_number('1.0', int)) -class TestPrintCount(TestCase): - def setUp(self): - self.cmd = LoadCommand() +class TestPrintCount(TestCommand): @patch('jarbas.core.management.commands.print') def test_print_no_records(self, mock_print): - self.cmd.print_count(Activity) + self.command.print_count(Activity) arg = 'Current count: 0 Activitys ' kwargs = {'end': '\r'} mock_print.assert_called_with(arg, **kwargs) @@ -49,20 +48,20 @@ def test_print_no_records(self, mock_print): @patch('jarbas.core.management.commands.print') def test_print_with_records(self, mock_print): Activity.objects.create(**sample_activity_data) - self.cmd.print_count(Activity) + self.command.print_count(Activity) arg = 'Current count: 1 Activitys ' kwargs = {'end': '\r'} mock_print.assert_called_with(arg, **kwargs) @patch('jarbas.core.management.commands.print') def test_print_with_permanent_keyword_arg(self, mock_print): - self.cmd.print_count(Activity, permanent=True) + self.command.print_count(Activity, permanent=True) arg = 'Current count: 0 Activitys ' kwargs = {'end': '\n'} mock_print.assert_called_with(arg, **kwargs) -class TestDropAll(TestCase): +class TestDropAll(TestCommand): @patch('jarbas.core.management.commands.print') def test_drop_all(self, mock_print): @@ -73,12 +72,10 @@ def test_drop_all(self, mock_print): self.assertEqual(0, Activity.objects.count()) -class TestAddArguments(TestCase): +class TestAddArguments(TestCommand): def test_add_arguments(self): - mock = Mock() - LoadCommand().add_arguments(mock) - self.assertEqual(2, mock.add_argument.call_count) + self.add_arguments(self.command) def test_add_arguments_without_drop_all(self): mock = Mock() From 0f5e3bcf214853f451de3152de20fcc47e6ff83d Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Sat, 5 Aug 2017 12:53:21 -0300 Subject: [PATCH 30/32] using serializer --- jarbas/core/tests/test_reimbursements_command.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/jarbas/core/tests/test_reimbursements_command.py b/jarbas/core/tests/test_reimbursements_command.py index 998bf90..3f4fe78 100644 --- a/jarbas/core/tests/test_reimbursements_command.py +++ b/jarbas/core/tests/test_reimbursements_command.py @@ -2,7 +2,7 @@ from io import StringIO from unittest.mock import MagicMock, call, patch -from django.test import TestCase +from jarbas.core.tests import TestCase from jarbas.core.management.commands.reimbursements import Command from jarbas.core.models import Reimbursement @@ -85,8 +85,7 @@ def test_serializer(self): 'reimbursement_value_total': 'NaN', 'year': '1970' } - self.maxDiff = 2 ** 10 - self.assertEqual(self.command.serialize(input), expected) + self.serializer(self.command, input, expected) class TestCreate(TestCommand): From fa0553a5c8dc7218d938eac736ef4f16df661b23 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Sat, 5 Aug 2017 14:49:41 -0300 Subject: [PATCH 31/32] Fixing imports on tests --- jarbas/core/tests/test_companies_command.py | 4 +--- jarbas/core/tests/test_company_model.py | 1 + jarbas/core/tests/test_load_command.py | 4 +--- jarbas/core/tests/test_receipts_command.py | 2 +- jarbas/core/tests/test_receipts_text_command.py | 3 +-- jarbas/core/tests/test_reimbursements_command.py | 3 +-- jarbas/core/tests/test_suspicions_command.py | 3 +-- jarbas/core/tests/test_tweets_command.py | 3 +-- 8 files changed, 8 insertions(+), 15 deletions(-) diff --git a/jarbas/core/tests/test_companies_command.py b/jarbas/core/tests/test_companies_command.py index c8817af..1d2ebc1 100644 --- a/jarbas/core/tests/test_companies_command.py +++ b/jarbas/core/tests/test_companies_command.py @@ -2,11 +2,9 @@ from io import StringIO from unittest.mock import patch -from jarbas.core.tests import TestCase - from jarbas.core.management.commands.companies import Command from jarbas.core.models import Activity, Company -from jarbas.core.tests import sample_company_data +from jarbas.core.tests import TestCase, sample_company_data class TestCommand(TestCase): diff --git a/jarbas/core/tests/test_company_model.py b/jarbas/core/tests/test_company_model.py index 022c06c..9fe56a6 100644 --- a/jarbas/core/tests/test_company_model.py +++ b/jarbas/core/tests/test_company_model.py @@ -1,4 +1,5 @@ from django.test import TestCase + from jarbas.core.models import Activity, Company from jarbas.core.tests import sample_activity_data, sample_company_data diff --git a/jarbas/core/tests/test_load_command.py b/jarbas/core/tests/test_load_command.py index 7dcf80b..567b7fa 100644 --- a/jarbas/core/tests/test_load_command.py +++ b/jarbas/core/tests/test_load_command.py @@ -1,11 +1,9 @@ from datetime import date from unittest.mock import Mock, patch -from jarbas.core.tests import TestCase - from jarbas.core.management.commands import LoadCommand from jarbas.core.models import Activity -from jarbas.core.tests import sample_activity_data +from jarbas.core.tests import TestCase, sample_activity_data class TestCommand(TestCase): diff --git a/jarbas/core/tests/test_receipts_command.py b/jarbas/core/tests/test_receipts_command.py index d205ab9..8dd9786 100644 --- a/jarbas/core/tests/test_receipts_command.py +++ b/jarbas/core/tests/test_receipts_command.py @@ -1,10 +1,10 @@ from unittest.mock import Mock, call, patch -from jarbas.core.tests import TestCase from django.db.models import QuerySet from requests.exceptions import ConnectionError from jarbas.core.management.commands.receipts import Command +from jarbas.core.tests import TestCase class TestCommand(TestCase): diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index 67104f8..a0db77a 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -1,9 +1,8 @@ from unittest.mock import patch -from jarbas.core.tests import TestCase - from jarbas.core.management.commands.receipts_text import Command from jarbas.core.models import Reimbursement +from jarbas.core.tests import TestCase class TestCommand(TestCase): diff --git a/jarbas/core/tests/test_reimbursements_command.py b/jarbas/core/tests/test_reimbursements_command.py index 3f4fe78..620f73b 100644 --- a/jarbas/core/tests/test_reimbursements_command.py +++ b/jarbas/core/tests/test_reimbursements_command.py @@ -2,10 +2,9 @@ from io import StringIO from unittest.mock import MagicMock, call, patch -from jarbas.core.tests import TestCase - from jarbas.core.management.commands.reimbursements import Command from jarbas.core.models import Reimbursement +from jarbas.core.tests import TestCase class TestCommand(TestCase): diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index 60de08a..0d0fca7 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -1,9 +1,8 @@ from unittest.mock import patch -from jarbas.core.tests import TestCase - from jarbas.core.management.commands.suspicions import Command from jarbas.core.models import Reimbursement +from jarbas.core.tests import TestCase class TestCommand(TestCase): diff --git a/jarbas/core/tests/test_tweets_command.py b/jarbas/core/tests/test_tweets_command.py index 6c2130a..a9d3a76 100644 --- a/jarbas/core/tests/test_tweets_command.py +++ b/jarbas/core/tests/test_tweets_command.py @@ -2,12 +2,11 @@ from itertools import permutations from unittest.mock import MagicMock, PropertyMock, patch -from django.test import TestCase from mixer.backend.django import mixer from jarbas.core.models import Reimbursement, Tweet from jarbas.core.management.commands.tweets import Command -from jarbas.core.tests import random_tweet_status +from jarbas.core.tests import TestCase, random_tweet_status KEYS = ( From d4c4593ec0458ef9b6e62141c78e3b5c41e98f5b Mon Sep 17 00:00:00 2001 From: Eduardo Cuducos Date: Thu, 28 Sep 2017 00:34:46 -0300 Subject: [PATCH 32/32] Typo --- jarbas/core/tests/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index 2aab6a9..9ca0f51 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -16,8 +16,8 @@ def serializer(self, command, input, expected): serialized = command.serialize(input) self.assertEqual(serialized, expected) - def main(self, command, update, schedule_update, costum_method): - costum_method.return_value = (range(21), range(21, 43)) + def main(self, command, update, schedule_update, custom_method): + custom_method.return_value = (range(21), range(21, 43)) command.main() update.assert_has_calls([call()] * 2) schedule_update.assert_has_calls(call(i) for i in range(42)) @@ -37,34 +37,34 @@ def update(self, command, fields, print_, bulk_update): print_.assert_called_with('42 reimbursements updated.', end='\r') self.assertEqual(42, command.count) - def handler_with_options(self, command, print_, exits, main, costum_command): + def handler_with_options(self, command, print_, exits, main, custom_command): command.handle(dataset=self.file_name, batch_size=42) main.assert_called_once_with() print_.assert_called_once_with('0 reimbursements updated.') self.assertEqual(command.path, self.file_name) self.assertEqual(command.batch_size, 42) - def handler_without_options(self, command, print_, exits, main, costum_command): + def handler_without_options(self, command, print_, exits, main, custom_command): command.handle(dataset=self.file_name, batch_size=4096) main.assert_called_once_with() print_.assert_called_once_with('0 reimbursements updated.') self.assertEqual(command.path, self.file_name) self.assertEqual(command.batch_size, 4096) - def handler_with_non_existing_file(self, command, exists, update, costum_command): + def handler_with_non_existing_file(self, command, exists, update, custom_command): exists.return_value = False with self.assertRaises(FileNotFoundError): command.handle(dataset='suspicions.xz', batch_size=4096) update.assert_not_called() - def new_command(self, command, costum_command, serialize, rows, lzma, print_): + def new_command(self, command, custom_command, serialize, rows, lzma, print_): serialize.return_value = '.' lzma.return_value = StringIO() rows.return_value = range(42) command.batch_size = 10 command.path = self.file_name expected = [['.'] * 10, ['.'] * 10, ['.'] * 10, ['.'] * 10, ['.'] * 2] - self.assertEqual(expected, list(costum_command)) + self.assertEqual(expected, list(custom_command)) self.assertEqual(42, serialize.call_count) def add_arguments(self, command):