Python mock.PropertyMock() Examples

The following are 30 code examples of mock.PropertyMock(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mock , or try the search function .
Example #1
Source File: cli_test.py    From zap-cli with MIT License 7 votes vote down vote up
def test_load_script_engine_error(self, isfile_mock, script_mock):
        """Testing that an error is raised when an invalid engine is provided."""
        isfile_mock.return_value = True

        valid_engines = ['ECMAScript : Oracle Nashorn']
        class_mock = MagicMock()
        class_mock.load.return_value = 'OK'
        engines = PropertyMock(return_value=valid_engines)
        type(class_mock).list_engines = engines
        script_mock.return_value = class_mock

        result = self.runner.invoke(cli.cli, ['--boring', '--api-key', '', 'scripts', 'load',
                                              '--name', 'Foo.js', '--script-type', 'proxy',
                                              '--engine', 'Invalid Engine', '--file-path', 'Foo.js'])
        self.assertEqual(result.exit_code, 2)
        self.assertFalse(class_mock.load.called) 
Example #2
Source File: test_interest.py    From biweeklybudget with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_find_payments_total_too_low(self):
        cls = LowestBalanceFirstMethod(Decimal('3.00'))
        s1 = Mock(spec_set=CCStatement)
        type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s1).principal = PropertyMock(return_value=Decimal('10.00'))
        s2 = Mock(spec_set=CCStatement)
        type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00'))
        type(s2).principal = PropertyMock(return_value=Decimal('25.00'))
        s3 = Mock(spec_set=CCStatement)
        type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s3).principal = PropertyMock(return_value=Decimal('1234.56'))
        s4 = Mock(spec_set=CCStatement)
        type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00'))
        type(s4).principal = PropertyMock(return_value=Decimal('3.00'))
        with pytest.raises(TypeError):
            cls.find_payments([s1, s2, s3, s4]) 
Example #3
Source File: test_requirements.py    From pyup with MIT License 6 votes vote down vote up
def test_update_with_hashes_and_comment_and_env_markers_all_in_one_line(self, get_hashes_mock, _):
        get_hashes_mock.return_value = [{"hash": "123"}, {"hash": "456"}]
        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="1.4.2"):
            content = "alembic==0.8.9; sys_platform != 'win32' --hash=sha256:abcde # yay"
            req_file = RequirementFile("req.txt", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("alembic==0.8.9; sys_platform != 'win32'", 1),
                req
            )

            new_content = req.update_content(content)
            self.assertEqual(new_content, "alembic==1.4.2; sys_platform != 'win32' \\\n"
                                          "    --hash=sha256:123 \\\n"
                                          "    --hash=sha256:456 # yay") 
Example #4
Source File: test_requirements.py    From pyup with MIT License 6 votes vote down vote up
def test_taskcluster_215(self, get_hashes_mock, _):
        get_hashes_mock.return_value = [{"hash": "123"}, {"hash": "456"}]
        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="1.4.2"):
            content = "taskcluster==0.3.4 --hash sha256:d4fe5e2a44fe27e195b92830ece0a6eb9eb7ad9dc556a0cb16f6f2a6429f1b65"
            req_file = RequirementFile("req.txt", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("taskcluster==0.3.4", 1),
                req
            )

            new_content = req.update_content(content)
            self.assertEqual(new_content, "taskcluster==1.4.2 \\\n"
                                          "    --hash=sha256:123 \\\n"
                                          "    --hash=sha256:456") 
Example #5
Source File: test_requirements.py    From pyup with MIT License 6 votes vote down vote up
def test_update_with_hashes_and_comment_and_env_markers(self, get_hashes_mock, _):
        get_hashes_mock.return_value = [{"hash": "123"}, {"hash": "456"}]
        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="1.4.2"):
            content = "alembic==0.8.9; sys_platform != 'win32' \\\n" \
                      "        --hash=sha256:abcde # yay"
            req_file = RequirementFile("req.txt", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("alembic==0.8.9; sys_platform != 'win32'", 1),
                req
            )

            new_content = req.update_content(content)
            self.assertEqual(new_content, "alembic==1.4.2; sys_platform != 'win32' \\\n"
                                                          "    --hash=sha256:123 \\\n"
                                                          "    --hash=sha256:456 # yay") 
Example #6
Source File: test_requirements.py    From pyup with MIT License 6 votes vote down vote up
def test_update_with_hashes_and_comment(self, get_hashes_mock, _):
        get_hashes_mock.return_value = [{"hash": "123"}, {"hash": "456"}]
        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="1.4.2"):
            content = "alembic==0.8.9 \\\n" \
                      "        --hash=sha256:abcde # yay"
            req_file = RequirementFile("req.txt", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("alembic==0.8.9", 1),
                req
            )

            new_content = req.update_content(content)
            self.assertEqual(new_content, "alembic==1.4.2 \\\n"
                                                          "    --hash=sha256:123 \\\n"
                                                          "    --hash=sha256:456 # yay") 
Example #7
Source File: test_requirements.py    From pyup with MIT License 6 votes vote down vote up
def test_conda_file(self, _):

        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="2.9.5"):
            content = "name: my_env\n" \
                      "dependencies:\n" \
                      "  - gevent=1.2.1\n" \
                      "  - pip:\n" \
                      "    - beautifulsoup4==1.2.3\n"
            req_file = RequirementFile("req.yml", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("beautifulsoup4==1.2.3", 1),
                req
            )
            updated = req.update_content(content)
            new_content = "name: my_env\n" \
                      "dependencies:\n" \
                      "  - gevent=1.2.1\n" \
                      "  - pip:\n" \
                      "    - beautifulsoup4==2.9.5\n"
            self.assertEqual(updated, new_content) 
Example #8
Source File: test_requirements.py    From pyup with MIT License 6 votes vote down vote up
def test_update_with_hashes_in_one_line(self, get_hashes_mock, _):
        get_hashes_mock.return_value = [{"hash": "123"}, {"hash": "456"}]
        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="1.4.2"):
            content = "alembic==0.8.9 --hash=sha256:abcde"
            req_file = RequirementFile("req.txt", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("alembic==0.8.9", 1),
                req
            )

            new_content = req.update_content(content)
            self.assertEqual(new_content, "alembic==1.4.2 \\\n"
                                          "    --hash=sha256:123 \\\n"
                                          "    --hash=sha256:456") 
Example #9
Source File: test_requirements.py    From pyup with MIT License 6 votes vote down vote up
def test_update_with_hashes_sorted(self, get_hashes_mock, _):
        get_hashes_mock.return_value = [{"hash": "abc"}, {"hash": "456"},
                                        {"hash": "789"}, {"hash": "123"}]
        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="1.4.2"):
            content = "alembic==0.8.9 \\\n" \
                      "        --hash=sha256:abcde"
            req_file = RequirementFile("req.txt", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("alembic==0.8.9", 1),
                req
            )

            self.assertEqual(req.update_content(content), "alembic==1.4.2 \\\n"
                                                          "    --hash=sha256:123 \\\n"
                                                          "    --hash=sha256:456 \\\n"
                                                          "    --hash=sha256:789 \\\n"
                                                          "    --hash=sha256:abc") 
Example #10
Source File: test_requirements.py    From pyup with MIT License 6 votes vote down vote up
def test_update_with_hashes(self, get_hashes_mock, _):
        get_hashes_mock.return_value = [{"hash": "123"}, {"hash": "456"}]
        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="1.4.2"):
            content = "alembic==0.8.9 \\\n" \
                      "        --hash=sha256:abcde"
            req_file = RequirementFile("req.txt", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("alembic==0.8.9", 1),
                req
            )

            self.assertEqual(req.update_content(content), "alembic==1.4.2 \\\n"
                                                          "    --hash=sha256:123 \\\n"
                                                          "    --hash=sha256:456") 
Example #11
Source File: test_analysis_model.py    From OasisPlatform with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_state_is_ready___run_is_started(self, status, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                analysis = fake_analysis(status=status, run_task_id=task_id, input_file=fake_related_file(), settings_file=fake_related_file())
                initiator = fake_user()

                sig_res = Mock()
                sig_res.delay.return_value = res_factory(task_id)

                with patch('src.server.oasisapi.analyses.models.Analysis.run_analysis_signature', PropertyMock(return_value=sig_res)):
                    analysis.run(initiator)

                    sig_res.link.assert_called_once_with(record_run_analysis_result.s(analysis.pk, initiator.pk))
                    sig_res.link_error.assert_called_once_with(
                        signature('on_error', args=('record_run_analysis_failure', analysis.pk, initiator.pk), queue=analysis.model.queue_name)
                    )
                    sig_res.delay.assert_called_once_with() 
Example #12
Source File: test_analysis_model.py    From OasisPlatform with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_portfolio_has_no_location_file___validation_error_is_raised_revoke_is_not_called(self, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                initiator = fake_user()

                sig_res = Mock()
                with patch('src.server.oasisapi.analyses.models.Analysis.generate_input_signature', PropertyMock(return_value=sig_res)):
                    analysis = fake_analysis(status=Analysis.status_choices.NEW, run_task_id=task_id)

                    with self.assertRaises(ValidationError) as ex:
                        analysis.generate_inputs(initiator)

                    self.assertEqual({'portfolio': ['"location_file" must not be null']}, ex.exception.detail)

                    self.assertEqual(Analysis.status_choices.NEW, analysis.status)
                    self.assertFalse(res_factory.revoke_called) 
Example #13
Source File: test_analysis_model.py    From OasisPlatform with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_state_is_running_or_generating_inputs___validation_error_is_raised_revoke_is_not_called(self, status, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                initiator = fake_user()

                sig_res = Mock()
                with patch('src.server.oasisapi.analyses.models.Analysis.generate_input_signature', PropertyMock(return_value=sig_res)):
                    analysis = fake_analysis(status=status, run_task_id=task_id, portfolio=fake_portfolio(location_file=fake_related_file()))

                    with self.assertRaises(ValidationError) as ex:
                        analysis.generate_inputs(initiator)

                    self.assertEqual({'status': [
                        'Analysis status must be one of [NEW, INPUTS_GENERATION_ERROR, INPUTS_GENERATION_CANCELLED, READY, RUN_COMPLETED, RUN_CANCELLED, RUN_ERROR]'
                    ]}, ex.exception.detail)
                    self.assertEqual(status, analysis.status)
                    self.assertFalse(res_factory.revoke_called) 
Example #14
Source File: test_analysis_model.py    From OasisPlatform with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_state_is_not_running___run_is_started(self, status, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                analysis = fake_analysis(status=status, run_task_id=task_id, portfolio=fake_portfolio(location_file=fake_related_file()))
                initiator = fake_user()

                sig_res = Mock()
                sig_res.delay.return_value = res_factory(task_id)

                with patch('src.server.oasisapi.analyses.models.Analysis.generate_input_signature', PropertyMock(return_value=sig_res)):
                    analysis.generate_inputs(initiator)

                    sig_res.link.assert_called_once_with(record_generate_input_result.s(analysis.pk, initiator.pk))
                    sig_res.link_error.assert_called_once_with(
                        signature('on_error', args=('record_generate_input_failure', analysis.pk, initiator.pk), queue=analysis.model.queue_name)
                    )
                    sig_res.delay.assert_called_once_with() 
Example #15
Source File: test_git.py    From waliki with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_whatchanged_pagination(self):
        self.page.raw = 'line\n'
        Git().commit(self.page, message=u'one')
        self.page.raw += 'line 2\n'
        Git().commit(self.page, message=u'two')
        self.page.raw += 'line 3\n'
        Git().commit(self.page, message=u'three')
        with patch('waliki.git.views.settings') as s_mock:
            type(s_mock).WALIKI_PAGINATE_BY = PropertyMock(return_value=2)
            response1 = self.client.get(reverse('waliki_whatchanged'))
            response2 = self.client.get(reverse('waliki_whatchanged', args=('2',)))

        # first page has no previous page
        self.assertIsNone(response1.context[0]['prev'])
        self.assertEqual(response1.context[0]['next'], 2)
        self.assertIsNone(response2.context[0]['next'])
        self.assertEqual(response2.context[0]['prev'], 1)

        changes1 = response1.context[0]['changes']
        changes2 = response2.context[0]['changes']
        self.assertEqual(len(changes1), 2)
        self.assertEqual(len(changes2), 1)
        self.assertEqual(changes1[0]['message'], 'three')
        self.assertEqual(changes1[1]['message'], 'two')
        self.assertEqual(changes2[0]['message'], 'one') 
Example #16
Source File: test_slot.py    From pg2kinesis with MIT License 6 votes vote down vote up
def test_delete_slot(slot):
    with patch.object(psycopg2.ProgrammingError, 'pgcode',
                      new_callable=PropertyMock,
                      return_value=psycopg2.errorcodes.UNDEFINED_OBJECT):
        pe = psycopg2.ProgrammingError()
        slot._repl_cursor.drop_replication_slot = Mock(side_effect=pe)
        slot.delete_slot()
    slot._repl_cursor.drop_replication_slot.assert_called_with('pg2kinesis')

    with patch.object(psycopg2.ProgrammingError, 'pgcode',
                      new_callable=PropertyMock,
                      return_value=-1):
        pe = psycopg2.ProgrammingError()
        slot._repl_cursor.create_replication_slot = Mock(side_effect=pe)
        with pytest.raises(psycopg2.ProgrammingError) as e_info:
            slot.delete_slot()
            slot._repl_cursor.drop_replication_slot.assert_called_with('pg2kinesis')

            assert e_info.value.pgcode == -1

    slot._repl_cursor.create_replication_slot = Mock(side_effect=Exception)
    with pytest.raises(Exception):
        slot.delete_slot()
        slot._repl_cursor.drop_replication_slot.assert_called_with('pg2kinesis') 
Example #17
Source File: test_interest.py    From biweeklybudget with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_pay(self):
        b = Mock(spec_set=_BillingPeriod)
        b_next = Mock(spec_set=_BillingPeriod)
        type(b_next).payment_date = PropertyMock(return_value=date(2017, 1, 15))
        type(b).next_period = PropertyMock(return_value=b_next)
        i = Mock(spec_set=_InterestCalculation)
        p = Mock(spec_set=_MinPaymentFormula)
        cls = CCStatement(
            i, Decimal('1.23'), p, b,
            end_balance=Decimal('1.50'), interest_amt=Decimal('0.27')
        )
        mock_stmt = Mock(spec_set=CCStatement)
        with patch(
            'biweeklybudget.interest.CCStatement.next_with_transactions',
            autospec=True
        ) as m:
            m.return_value = mock_stmt
            res = cls.pay(Decimal('98.76'))
        assert res == mock_stmt
        assert m.mock_calls == [
            call(cls, {date(2017, 1, 15): Decimal('98.76')})
        ] 
Example #18
Source File: test_interest.py    From biweeklybudget with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_next_with_transactions(self):
        b = Mock(spec_set=_BillingPeriod)
        b_next = Mock(spec_set=_BillingPeriod)
        type(b).next_period = PropertyMock(return_value=b_next)
        i = Mock(spec_set=_InterestCalculation)
        p = Mock(spec_set=_MinPaymentFormula)
        cls = CCStatement(
            i, Decimal('1.23'), p, b,
            end_balance=Decimal('1.50'), interest_amt=Decimal('0.27')
        )
        mock_stmt = Mock(spec_set=CCStatement)
        with patch('biweeklybudget.interest.CCStatement', autospec=True) as m:
            m.return_value = mock_stmt
            res = cls.next_with_transactions({'foo': 'bar'})
        assert res == mock_stmt
        assert m.mock_calls == [
            call(
                i, Decimal('1.50'), p, b_next, transactions={'foo': 'bar'}
            )
        ] 
Example #19
Source File: cli_test.py    From zap-cli with MIT License 6 votes vote down vote up
def test_load_script_unknown_error(self, isfile_mock, script_mock):
        """Testing that an error is raised when an erro response is received from the API."""
        script_name = 'Foo.js'
        script_type = 'proxy'
        engine = 'Oracle Nashorn'
        valid_engines = ['ECMAScript : Oracle Nashorn']

        isfile_mock.return_value = True

        class_mock = MagicMock()
        class_mock.load.return_value = 'Internal Error'
        engines = PropertyMock(return_value=valid_engines)
        type(class_mock).list_engines = engines
        script_mock.return_value = class_mock

        result = self.runner.invoke(cli.cli, ['--boring', '--api-key', '', 'scripts', 'load',
                                              '--name', script_name, '--script-type', script_type,
                                              '--engine', engine, '--file-path', script_name])
        self.assertEqual(result.exit_code, 2)
        class_mock.load.assert_called_with(script_name, script_type, engine, script_name, scriptdescription='') 
Example #20
Source File: test_interest.py    From biweeklybudget with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_find_payments(self):
        cls = LowestBalanceFirstMethod(Decimal('100.00'))
        s1 = Mock(spec_set=CCStatement)
        type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s1).principal = PropertyMock(return_value=Decimal('10.00'))
        s2 = Mock(spec_set=CCStatement)
        type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00'))
        type(s2).principal = PropertyMock(return_value=Decimal('25.00'))
        s3 = Mock(spec_set=CCStatement)
        type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s3).principal = PropertyMock(return_value=Decimal('1234.56'))
        s4 = Mock(spec_set=CCStatement)
        type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00'))
        type(s4).principal = PropertyMock(return_value=Decimal('3.00'))
        assert cls.find_payments([s1, s2, s3, s4]) == [
            Decimal('2.00'),
            Decimal('5.00'),
            Decimal('2.00'),
            Decimal('91.00')
        ] 
Example #21
Source File: test_interest.py    From biweeklybudget with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_find_payments_total_too_low(self):
        cls = LowestInterestRateFirstMethod(Decimal('3.00'))
        s1 = Mock(spec_set=CCStatement)
        type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s1).principal = PropertyMock(return_value=Decimal('10.00'))
        s2 = Mock(spec_set=CCStatement)
        type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00'))
        type(s2).principal = PropertyMock(return_value=Decimal('25.00'))
        s3 = Mock(spec_set=CCStatement)
        type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s3).principal = PropertyMock(return_value=Decimal('1234.56'))
        s4 = Mock(spec_set=CCStatement)
        type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00'))
        type(s4).principal = PropertyMock(return_value=Decimal('3.00'))
        with pytest.raises(TypeError):
            cls.find_payments([s1, s2, s3, s4]) 
Example #22
Source File: test_interest.py    From biweeklybudget with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_find_payments(self):
        cls = LowestInterestRateFirstMethod(Decimal('100.00'))
        s1 = Mock(spec_set=CCStatement)
        type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s1).apr = PropertyMock(return_value=Decimal('0.0100'))
        type(s1).principal = PropertyMock(return_value=Decimal('10.00'))
        s2 = Mock(spec_set=CCStatement)
        type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00'))
        type(s2).apr = PropertyMock(return_value=Decimal('0.0200'))
        type(s2).principal = PropertyMock(return_value=Decimal('25.00'))
        s3 = Mock(spec_set=CCStatement)
        type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s3).apr = PropertyMock(return_value=Decimal('0.0800'))
        type(s3).principal = PropertyMock(return_value=Decimal('1234.56'))
        s4 = Mock(spec_set=CCStatement)
        type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00'))
        type(s4).apr = PropertyMock(return_value=Decimal('0.0300'))
        type(s4).principal = PropertyMock(return_value=Decimal('3.00'))
        assert cls.find_payments([s1, s2, s3, s4]) == [
            Decimal('86.00'),
            Decimal('5.00'),
            Decimal('2.00'),
            Decimal('7.00')
        ] 
Example #23
Source File: test_interest.py    From biweeklybudget with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_find_payments_total_too_low(self):
        cls = HighestInterestRateFirstMethod(Decimal('3.00'))
        s1 = Mock(spec_set=CCStatement)
        type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s1).principal = PropertyMock(return_value=Decimal('10.00'))
        s2 = Mock(spec_set=CCStatement)
        type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00'))
        type(s2).principal = PropertyMock(return_value=Decimal('25.00'))
        s3 = Mock(spec_set=CCStatement)
        type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s3).principal = PropertyMock(return_value=Decimal('1234.56'))
        s4 = Mock(spec_set=CCStatement)
        type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00'))
        type(s4).principal = PropertyMock(return_value=Decimal('3.00'))
        with pytest.raises(TypeError):
            cls.find_payments([s1, s2, s3, s4]) 
Example #24
Source File: test_interest.py    From biweeklybudget with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_find_payments(self):
        cls = HighestInterestRateFirstMethod(Decimal('100.00'))
        s1 = Mock(spec_set=CCStatement)
        type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s1).apr = PropertyMock(return_value=Decimal('0.0100'))
        type(s1).principal = PropertyMock(return_value=Decimal('10.00'))
        s2 = Mock(spec_set=CCStatement)
        type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00'))
        type(s2).apr = PropertyMock(return_value=Decimal('0.0200'))
        type(s2).principal = PropertyMock(return_value=Decimal('25.00'))
        s3 = Mock(spec_set=CCStatement)
        type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s3).apr = PropertyMock(return_value=Decimal('0.0800'))
        type(s3).principal = PropertyMock(return_value=Decimal('1234.56'))
        s4 = Mock(spec_set=CCStatement)
        type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00'))
        type(s4).apr = PropertyMock(return_value=Decimal('0.0300'))
        type(s4).principal = PropertyMock(return_value=Decimal('3.00'))
        assert cls.find_payments([s1, s2, s3, s4]) == [
            Decimal('2.00'),
            Decimal('5.00'),
            Decimal('86.00'),
            Decimal('7.00')
        ] 
Example #25
Source File: test_interest.py    From biweeklybudget with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_find_payments(self):
        cls = HighestBalanceFirstMethod(Decimal('100.00'))
        s1 = Mock(spec_set=CCStatement)
        type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s1).principal = PropertyMock(return_value=Decimal('10.00'))
        s2 = Mock(spec_set=CCStatement)
        type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00'))
        type(s2).principal = PropertyMock(return_value=Decimal('25.00'))
        s3 = Mock(spec_set=CCStatement)
        type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s3).principal = PropertyMock(return_value=Decimal('1234.56'))
        s4 = Mock(spec_set=CCStatement)
        type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00'))
        type(s4).principal = PropertyMock(return_value=Decimal('3.00'))
        assert cls.find_payments([s1, s2, s3, s4]) == [
            Decimal('2.00'),
            Decimal('5.00'),
            Decimal('86.00'),
            Decimal('7.00')
        ] 
Example #26
Source File: cli_test.py    From zap-cli with MIT License 6 votes vote down vote up
def test_load_script(self, isfile_mock, script_mock):
        """Test command to load a script."""
        script_name = 'Foo.js'
        script_type = 'proxy'
        engine = 'Oracle Nashorn'
        valid_engines = ['ECMAScript : Oracle Nashorn']

        isfile_mock.return_value = True

        class_mock = MagicMock()
        class_mock.load.return_value = 'OK'
        engines = PropertyMock(return_value=valid_engines)
        type(class_mock).list_engines = engines
        script_mock.return_value = class_mock

        result = self.runner.invoke(cli.cli, ['--boring', '--api-key', '', 'scripts', 'load',
                                              '--name', script_name, '--script-type', script_type,
                                              '--engine', engine, '--file-path', script_name])
        class_mock.load.assert_called_with(script_name, script_type, engine, script_name, scriptdescription='')
        self.assertEqual(result.exit_code, 0) 
Example #27
Source File: test_interest.py    From biweeklybudget with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_find_payments(self):
        cls = FixedPaymentMethod(Decimal('12.34'))
        s1 = Mock(spec_set=CCStatement)
        type(s1).minimum_payment = PropertyMock(return_value=Decimal('1.11'))
        s2 = Mock(spec_set=CCStatement)
        type(s2).minimum_payment = PropertyMock(return_value=Decimal('2.22'))
        s3 = Mock(spec_set=CCStatement)
        type(s3).minimum_payment = PropertyMock(return_value=Decimal('3.33'))
        assert cls.find_payments([s1, s2, s3]) == [
            Decimal('12.34'), Decimal('12.34'), Decimal('12.34')
        ] 
Example #28
Source File: test_interest.py    From biweeklybudget with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_find_payments(self):
        cls = MinPaymentMethod()
        s1 = Mock(spec_set=CCStatement)
        type(s1).minimum_payment = PropertyMock(return_value=Decimal('1.11'))
        s2 = Mock(spec_set=CCStatement)
        type(s2).minimum_payment = PropertyMock(return_value=Decimal('2.22'))
        s3 = Mock(spec_set=CCStatement)
        type(s3).minimum_payment = PropertyMock(return_value=Decimal('3.33'))
        assert cls.find_payments([s1, s2, s3]) == [
            Decimal('1.11'), Decimal('2.22'), Decimal('3.33')
        ] 
Example #29
Source File: zap_helper_test.py    From zap-cli with MIT License 5 votes vote down vote up
def test_run_ajax_spider(self):
        """Test running the AJAX Spider."""
        def status_result():
            """Return value of the status property."""
            if status.call_count > 2:
                return 'stopped'
            return 'running'

        class_mock = MagicMock()
        status = PropertyMock(side_effect=status_result)
        type(class_mock).status = status
        self.zap_helper.zap.ajaxSpider = class_mock

        self.zap_helper.run_ajax_spider('http://localhost') 
Example #30
Source File: test_interest.py    From biweeklybudget with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_end_date(self):
        b = Mock(spec_set=_BillingPeriod)
        type(b).start_date = PropertyMock(return_value=date(2017, 1, 1))
        type(b).end_date = PropertyMock(return_value=date(2017, 1, 29))
        i = Mock(spec_set=_InterestCalculation)
        p = Mock(spec_set=_MinPaymentFormula)
        cls = CCStatement(
            i, Decimal('1.23'), p, b,
            end_balance=Decimal('1.50'), interest_amt=Decimal('0.27')
        )
        assert cls.end_date == date(2017, 1, 29)