def test_tx(self, mock):
     response = self.node.tx('id')
     mock.assert_called()
     assert response.to_json() == {
         'type':
         4,
         'version':
         3,
         'sender':
         '3N5PoiMisnbNPseVXcCa5WDRLLHkj7dz4Du',
         'senderKeyType':
         'ed25519',
         'senderPublicKey':
         'AneNBwCMTG1YQ5ShPErzJZETTsHEWFnPWhdkKiHG6VTX',
         'fee':
         100000000,
         'timestamp':
         1631613596742,
         'amount':
         10000000,
         'recipient':
         '3N6MFpSbbzTozDcfkTUT5zZ2sNbJKFyRtRj',
         'attachment':
         '',
         'height':
         '',
         'id':
         '74MeWagvnJ2MZTV7wEUQVWG8mTVddS9pJuqvtyG8b5eP',
         'proofs': [
             'j2q6isq2atpXBADMZ2Vz7oRozfUKGuDkLnVMqtnXkwDhw6tyHmMMHTbaVknP4JmYiVWN5PuNp6i4f5TBhuc9QSm'
         ]
     }
Exemple #2
0
 def test_allow_tpay_action(self):
     request = self.rf.get(reverse("admin:payments_paymentuser_changelist"))
     request.user = self.user
     with patch("payments.models.PaymentUser.allow_tpay") as mock:
         request._messages = Mock()
         self.admin.allow_thalia_pay(request, PaymentUser.objects.all())
         mock.assert_called()
Exemple #3
0
def test_uninstall(mocker):
    mock = mocker.patch(mocks.make_target("shim", "remove"))

    # although not specifically mocked, this will not uninstall pytorch-pip-shim since
    # it is outside the environment we are currently running in
    pip_uninstall(Package("pytorch-pip-shim", pps.__version__))

    mock.assert_called()
    def test_trigger_on_custom_chord(self):
        mock = unittest.mock.Mock()
        chord = Chord.from_midi_list([20, 40, 60])
        self.assertFalse(self.MEL.handlers)  # Empty check
        self.MEL.add_handler(mock, chord)

        press_chord(self.loopback, chord)
        mock.assert_called()
    def test_trigger_on_sequence(self):
        mock = unittest.mock.Mock()
        seq1 = Sequence(Note(1), Note(2), Note(3))
        self.assertFalse(self.MEL.handlers)  # Empty check
        self.MEL.add_handler(mock, seq1)

        press_sequence(self.loopback, seq1)
        mock.assert_called()
Exemple #6
0
 def test_plot_show(self, mock):
     """Test to prove that plt.show is called in plot() method.
     Uses mocking
     """
     self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                     "CelestialObjects")
     animate = Animation(self.system_probe)
     animate.plot()
     mock.assert_called()
Exemple #7
0
    def test_not_adaptive(self):
        with unittest.mock.patch.object(SimilarTriangles,
                                        '_check_relaxation',
                                        return_value=None) as mock:
            self.optimizer = SimilarTriangles(self.model.parameters(),
                                              is_adaptive=False)
            self.closure()
            self.optimizer.step(self.closure)

        with self.assertRaises(AssertionError):
            mock.assert_called()
Exemple #8
0
    def test_plot_animate(self, mock, mock2):
        """Test used to check that a FunCAnimator is used in plot()
        Uses mocking

        """
        mock.return_value = None
        self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                        "CelestialObjects")
        animate = Animation(self.system_probe)
        animate.plot()
        mock.assert_called()
Exemple #9
0
 def test_animate_update(self, mock, mock2):
     """Test used to prove that update beeman is calld in the animate method
     Uses mocking.
     """
     self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                     "CelestialObjects")
     animate = Animation(self.system_probe)
     animate.plot()
     animate.init()
     animate.animate(0)
     mock.assert_called()
Exemple #10
0
 def test_scatterplot_update(self, mock, mock2):
     """Test used to prove that update_beeman() is called 100 times in scatter_plot method
     if the parameter passed to scatter_plot is 100.
     uses mocking
     """
     self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                     "CelestialObjects")
     animate = Animation(self.system_probe)
     animate.scatter_plot(100)
     mock.assert_called()
     self.assertEqual(mock.call_count, 100)
    def test_decorator_string(self):
        mock = unittest.mock.Mock()
        self.assertFalse(self.MEL.handlers)  # Empty

        @self.MEL.on_notes("C4 Major")
        def sub():  # pragma: no cover
            mock()

        self.assertTrue(self.MEL.handlers)  # Not empty
        press_chord(self.loopback, Chord.from_ident("C4 Major"))
        mock.assert_called()
Exemple #12
0
    def test_ingest_oral_arguments(self, mock) -> None:
        """Can we successfully ingest oral arguments at a high level?"""
        site = test_oral_arg_scraper.Site()
        site.method = "LOCAL"
        parsed_site = site.parse()
        cl_scrape_oral_arguments.Command().scrape_court(parsed_site,
                                                        full_crawl=True)

        # There should now be two items in the database.
        audio_files = Audio.objects.all()
        self.assertEqual(2, audio_files.count())
        mock.assert_called()
 def test_chord_progression_callback(self):
     c1 = Chord.from_ident("A1 Major")
     c2 = Chord.from_ident("A2 Major")
     c3 = Chord.from_ident("A3 Major")
     cs1 = ChordProgression(c1, c2, c3)
     mock = unittest.mock.Mock()
     self.MEL.add_handler(mock, cs1)
     press_chord(self.loopback, c1)
     press_chord(self.loopback, c2)
     press_chord(self.loopback, c3)
     time.sleep(TEST_CHORD_DELAY)
     mock.assert_called()
Exemple #14
0
    def test_transforms(self, config):
        mock = unittest.mock.Mock(wraps=lambda *args: args[0] if len(args) == 1 else args)
        for kwarg in self._TRANSFORM_KWARGS:
            if kwarg not in self._HAS_SPECIAL_KWARG:
                continue

            mock.reset_mock()

            with self.subTest(kwarg=kwarg):
                with self.create_dataset(config, **{kwarg: mock}) as (dataset, _):
                    dataset[0]

                mock.assert_called()
    def test_decorator_sequence(self):
        mock = unittest.mock.Mock()
        self.assertFalse(self.MEL.handlers)  # Empty

        seq1 = Sequence(Note(5), Note(10), Note(15))

        @self.MEL.on_notes(seq1)
        def sub():
            mock()

        press_sequence(self.loopback, seq1)
        self.assertTrue(self.MEL.handlers)  # Not empty
        mock.assert_called()
    def test_decorator_chord(self):
        mock = unittest.mock.Mock()
        self.assertFalse(self.MEL.handlers)  # Empty

        c1 = Chord(Note(5), Note(10), Note(15))

        @self.MEL.on_notes(c1)
        def sub():
            mock()

        self.assertTrue(self.MEL.handlers)  # Not empty
        press_chord(self.loopback, c1)
        mock.assert_called()
Exemple #17
0
    def test_send_mail_with_keeper(self):
        with unittest.mock.patch(
                'prog_code.util.mail_util.get_mail_keeper') as mock:
            mock.return_value = TEST_MAIL_KEEPER

            mail_util.send_msg('test address', 'test subject', 'test message')

            last_message = TEST_MAIL_INSTANCE.last_message
            self.assertEqual(last_message.subject, 'test subject')
            self.assertEqual(last_message.sender, 'from addr')
            self.assertEqual(last_message.body, 'test message')
            self.assertEqual(last_message.recipients, ['testaddress'])

            mock.assert_called()
Exemple #18
0
    def test_ingest_opinions_from_scraper(self, mock) -> None:
        """Can we successfully ingest opinions at a high level?"""
        site = test_opinion_scraper.Site()
        site.method = "LOCAL"
        parsed_site = site.parse()
        cl_scrape_opinions.Command().scrape_court(parsed_site,
                                                  full_crawl=True,
                                                  ocr_available=False)

        opinions = Opinion.objects.all()
        count = opinions.count()
        self.assertTrue(
            opinions.count() == 6,
            f"Should have 6 test opinions, not {count}",
        )
        mock.assert_called()
    def test_delete_search_query_restore(self):
        with unittest.mock.patch('prog_code.util.db_util.get_db_connection') as mock:
            fake_cursor = TestDBCursor()
            fake_connection = TestDBConnection(fake_cursor)
            mock.return_value = fake_connection

            filters = [
                models.Filter('study', 'eq', 'study1,study2')
            ]
            filter_util.run_delete_query(filters, 'test', True)

            query = fake_cursor.queries[1]
            query_str ='UPDATE test SET deleted=0 WHERE (study == ? OR study == ?)'
            self.assertEqual(query, query_str)

            operands = fake_cursor.operands[0]
            self.assertEqual(len(operands), 2)
            self.assertEqual(operands[0], 'study1')
            self.assertEqual(operands[1], 'study2')

            mock.assert_called()
def test_update_training_data_set_with_update(
        mock, data_set_manager, file_repository_stub, workspace_stub,
        interpolated_sample_stubs_fixture):
    workspace_stub.training_data_set.last_modified = 1617981582110
    data_set_manager.update_training_data_set()

    mock.assert_called()
    assert workspace_stub.training_data_set.last_modified == DataSourceStub.last_modified(
        workspace_stub.user_id, workspace_stub._id)
    assert not workspace_stub.training_data_set.feature_extraction_cache

    assert len(file_repository_stub.files) == 1
    files_in_repository = pickle.loads(
        file_repository_stub.get_file(
            workspace_stub.training_data_set.sample_list_file_ID))
    assert len(files_in_repository) == len(interpolated_sample_stubs_fixture)
    for i in range(len(files_in_repository)):
        assert files_in_repository[
            i].label == interpolated_sample_stubs_fixture[i].label
        assert files_in_repository[i].data_frame.equals(
            interpolated_sample_stubs_fixture[i].data_frame)
Exemple #21
0
def test_run_with_settings_dir(fake_manifest: FixtureType) -> None:
    base_dir = pathlib.Path("/foo")
    settings_dir = pathlib.Path("/settings")
    options = RunOptions()
    ref = [1.0]
    manifest = fake_manifest(base_dir, settings_dir, ref)
    runner = Runner(manifest)
    reporters = ReporterFactory()

    manifest_args = runner.parse_manifest_arguments([])
    with unittest.mock.patch("pathlib.Path.mkdir") as mock:
        runner.run(
            "op1",
            base_dir,
            manifest_args,
            reporters,
            options,
            settings_dir=settings_dir,
            files=None,
        )
        mock.assert_called()
    assert math.isclose(ref[0], 6.0)
    assert not reporters.has_error()
    def test_run_search_query(self):
        with unittest.mock.patch('prog_code.util.db_util.get_db_connection') as mock:
            fake_cursor = TestDBCursor()
            fake_connection = TestDBConnection(fake_cursor)
            mock.return_value = fake_connection

            filters = [
                models.Filter('study', 'eq', 'study1,study2')
            ]
            filter_util.run_search_query(filters, 'test')

            query = fake_cursor.queries[0]
            query_str ='SELECT * FROM test WHERE (study == ? OR study == ?) AND '\
                '(deleted == ?)'
            self.assertEqual(query, query_str)

            operands = fake_cursor.operands[0]
            self.assertEqual(len(operands), 3)
            self.assertEqual(operands[0], 'study1')
            self.assertEqual(operands[1], 'study2')
            self.assertEqual(operands[2], 0)

            mock.assert_called()
Exemple #23
0
    def test_process_audio_file(self, mock) -> None:
        af = Audio.objects.get(pk=1)
        af.duration = None
        af.save()

        expected_duration = 15.0
        self.assertNotEqual(
            af.duration,
            expected_duration,
            msg="Do we have no duration info at the outset?",
        )

        process_audio_file(pk=1)
        af.refresh_from_db()
        measured_duration: float = af.duration  # type: ignore
        # Use almost equal because measuring MP3's is wonky.
        self.assertAlmostEqual(
            measured_duration,
            expected_duration,
            delta=5,
            msg="We should end up with the proper duration of about %s. "
            "Instead we got %s." % (expected_duration, measured_duration),
        )
        mock.assert_called()
 def test_last_block(self, mock):
     self.node.last_block()
     mock.assert_called()
 def test_compile(self, mock):
     self.node.compile('sddsfdsf')
     mock.assert_called()
Exemple #26
0
 def test_existingemail_fail(self, mock: mock.Mock) -> None:
     self.submit_form('login',
                      'input_id_login',
                      send_form_keys={'id_email': '*****@*****.**'})
     mock.assert_called()
     self.assert_url_equal('token_sent')
Exemple #27
0
 def test_send_mail_no_keeper(self):
     with unittest.mock.patch(
             'prog_code.util.mail_util.get_mail_keeper') as mock:
         mock.return_value = None
         mail_util.send_msg('test address', 'test subject', 'test message')
         mock.assert_called()
 def test_height(self, mock):
     self.node.height()
     mock.assert_called()
 def test_block(self, mock):
     self.node.block(20)
     mock.assert_called()
def test_validate_config_and_parse_hyperparameters_with_valid_config(
        mock, valid_training_config, workspace_sensors):
    validate_config_and_parse_hyperparameters(valid_training_config,
                                              workspace_sensors)
    mock.assert_called()