Ejemplo n.º 1
0
 def test_collect_event(self):
     config = {
         Configuration.POLICIES: {
             Configuration.ANALYTICS_POLICY: ["mock_analytics_provider"]
         },
         "option": "value"
     }
     with temp_config(config) as config:
         work = self._work(title="title", with_license_pool=True)
         [lp] = work.license_pools
         Analytics.collect_event(self._db, lp, CirculationEvent.CHECKIN, None)
         mock = Analytics.instance().providers[0]
         eq_(1, mock.count)
Ejemplo n.º 2
0
    def test_collect_event(self):
        sitewide_integration, ignore = create(
            self._db, ExternalIntegration,
            goal=ExternalIntegration.ANALYTICS_GOAL,
            protocol="mock_analytics_provider"
        )

        library, ignore = create(self._db, Library, short_name="library")
        library_integration, ignore = create(
            self._db, ExternalIntegration,
            goal=ExternalIntegration.ANALYTICS_GOAL,
            protocol="mock_analytics_provider",
        )
        library_integration.libraries += [library]

        work = self._work(title="title", with_license_pool=True)
        [lp] = work.license_pools
        analytics = Analytics(self._db)
        sitewide_provider = analytics.sitewide_providers[0]
        library_provider = analytics.library_providers[library.id][0]

        analytics.collect_event(self._default_library, lp, CirculationEvent.DISTRIBUTOR_CHECKIN, None)

        # The sitewide provider was called.
        eq_(1, sitewide_provider.count)
        eq_(CirculationEvent.DISTRIBUTOR_CHECKIN, sitewide_provider.event_type)

        # The library provider wasn't called, since the event was for a different library.
        eq_(0, library_provider.count)

        analytics.collect_event(library, lp, CirculationEvent.DISTRIBUTOR_CHECKIN, None)

        # Now both providers were called, since the event was for the library provider's library.
        eq_(2, sitewide_provider.count)
        eq_(1, library_provider.count)
        eq_(CirculationEvent.DISTRIBUTOR_CHECKIN, library_provider.event_type)