Example #1
0
    def test_vessel_action_error(self):
        response = response_factory(
            os.path.join(FIXTURE_PATH, 'imo-not-found.xml'),
            meta={
                'vessel': self.vessel,
                'action': 'add'
            },
        )
        with patch(
                'kp_scrapers.spiders.ais.marinetraffic.MarineTrafficSpider.logger'
        ):
            spider = MarineTrafficSpider(fleet='True')

            spider.check_vessel_action_status(response)

            spider.logger.error.assert_called_once_with(
                "Could not add vessel {name} (IMO: {imo}, MMSI: {mmsi}): "
                "{message}".format(message="VESSEL IMO NOT FOUND IN DATABASE",
                                   **self.vessel))
Example #2
0
    def test_vessel_action_successful(self):
        response = response_factory(
            os.path.join(FIXTURE_PATH, 'vessel-added.xml'),
            meta={
                'vessel': self.vessel,
                'action': 'add'
            },
        )
        with patch(
                'kp_scrapers.spiders.ais.marinetraffic.MarineTrafficSpider.logger'
        ) as logger:
            spider = MarineTrafficSpider(fleet='True')

            spider.check_vessel_action_status(response)

        self.assertEqual(logger.info.call_count, 1)
        self.assertEqual(
            logger.info.call_args_list[-1][0][0],
            "Vessel {name} (IMO: {imo}, MMSI: {mmsi}) added to MT fleet.".
            format(message="FLEET ITEM UPDATED", **self.vessel),
        )