def test_svc_supported_activity_types(self): ''' check that only activities are only sent to services which support them ''' svcA, svcB = TestTools.create_mock_services() recA = TestTools.create_mock_svc_record(svcA) recB = TestTools.create_mock_svc_record(svcB) svcA.SupportedActivities = [ActivityType.CrossCountrySkiing] svcB.SupportedActivities = [ActivityType.Cycling] actA = Activity() actA.StartTime = datetime(1, 2, 3, 4, 5, 6, 7) actA.ServiceDataCollection = TestTools.create_mock_servicedatacollection( svcA, record=recA) actA.Type = svcA.SupportedActivities[0] actA.CalculateUID() actA.UIDs = set([actA.UID]) actA.Record = ActivityRecord.FromActivity(actA) actB = Activity() actB.StartTime = datetime(5, 6, 7, 8, 9, 10, 11) actB.ServiceDataCollection = TestTools.create_mock_servicedatacollection( svcB, record=recB) actB.Type = [x for x in svcB.SupportedActivities if x != actA.Type][0] actB.CalculateUID() actB.UIDs = set([actB.UID]) actB.Record = ActivityRecord.FromActivity(actB) s = SynchronizationTask(None) s._serviceConnections = [recA, recB] s._activities = [] s._accumulateActivities(recA, [actA]) s._accumulateActivities(recB, [actB]) syncToA = s._determineRecipientServices(actA) syncToB = s._determineRecipientServices(actB) self.assertEqual(len(syncToA), 0) self.assertEqual(len(syncToB), 0) svcB.SupportedActivities = svcA.SupportedActivities syncToA = s._determineRecipientServices(actA) syncToB = s._determineRecipientServices(actB) self.assertEqual(len(syncToA), 1) self.assertEqual(len(syncToB), 0) svcB.SupportedActivities = svcA.SupportedActivities = [ ActivityType.CrossCountrySkiing, ActivityType.Cycling ] syncToA = s._determineRecipientServices(actA) syncToB = s._determineRecipientServices(actB) self.assertEqual(len(syncToA), 1) self.assertEqual(len(syncToB), 1)
def test_svc_supported_activity_types(self): ''' check that only activities are only sent to services which support them ''' svcA, svcB = TestTools.create_mock_services() recA = TestTools.create_mock_svc_record(svcA) recB = TestTools.create_mock_svc_record(svcB) svcA.SupportedActivities = [ActivityType.CrossCountrySkiing] svcB.SupportedActivities = [ActivityType.Cycling] actA = Activity() actA.StartTime = datetime(1, 2, 3, 4, 5, 6, 7) actA.ServiceDataCollection = TestTools.create_mock_servicedatacollection(svcA, record=recA) actA.Type = svcA.SupportedActivities[0] actA.CalculateUID() actA.UIDs = set([actA.UID]) actA.Record = ActivityRecord.FromActivity(actA) actB = Activity() actB.StartTime = datetime(5, 6, 7, 8, 9, 10, 11) actB.ServiceDataCollection = TestTools.create_mock_servicedatacollection(svcB, record=recB) actB.Type = [x for x in svcB.SupportedActivities if x != actA.Type][0] actB.CalculateUID() actB.UIDs = set([actB.UID]) actB.Record = ActivityRecord.FromActivity(actB) s = SynchronizationTask(None) s._serviceConnections = [recA, recB] s._activities = [] s._accumulateActivities(recA, [actA]) s._accumulateActivities(recB, [actB]) syncToA = s._determineRecipientServices(actA) syncToB = s._determineRecipientServices(actB) self.assertEqual(len(syncToA), 0) self.assertEqual(len(syncToB), 0) svcB.SupportedActivities = svcA.SupportedActivities syncToA = s._determineRecipientServices(actA) syncToB = s._determineRecipientServices(actB) self.assertEqual(len(syncToA), 1) self.assertEqual(len(syncToB), 0) svcB.SupportedActivities = svcA.SupportedActivities = [ActivityType.CrossCountrySkiing, ActivityType.Cycling] syncToA = s._determineRecipientServices(actA) syncToB = s._determineRecipientServices(actB) self.assertEqual(len(syncToA), 1) self.assertEqual(len(syncToB), 1)
def test_svc_level_dupe_time_leeway(self): ''' check that service-level duplicate activities within the defined time leeway are caught ''' svcA, svcB = TestTools.create_mock_services() recA = TestTools.create_mock_svc_record(svcA) recB = TestTools.create_mock_svc_record(svcB) actA = Activity() actA.StartTime = datetime(1, 2, 3, 4, 5, 6, 7) actA.ServiceDataCollection = TestTools.create_mock_servicedatacollection( svcA, record=recA) actA.Type = set(svcA.SupportedActivities).intersection( set(svcB.SupportedActivities)).pop() actB = Activity() actB.StartTime = datetime(1, 2, 3, 4, 6, 6, 7) actB.ServiceDataCollection = TestTools.create_mock_servicedatacollection( svcB, record=recB) actB.Type = actA.Type actA.CalculateUID() actB.CalculateUID() s = SynchronizationTask(None) s._activities = [] s._accumulateActivities(recA, [actA]) s._accumulateActivities(recB, [actB]) self.assertIn(actA.UID, actA.UIDs) self.assertIn(actB.UID, actA.UIDs) self.assertIn(actA.UID, actB.UIDs) self.assertIn(actB.UID, actB.UIDs) # we need to fake up the service records to avoid having to call the actual sync method where these values are normally preset recA = TestTools.create_mock_svc_record(svcA) recB = TestTools.create_mock_svc_record(svcB) recA.SynchronizedActivities = [actA.UID] recB.SynchronizedActivities = [actB.UID] s._serviceConnections = [recA, recB] recipientServicesA = s._determineRecipientServices(actA) recipientServicesB = s._determineRecipientServices(actB) self.assertEqual(len(recipientServicesA), 0) self.assertEqual(len(recipientServicesB), 0) self.assertEqual(len(s._activities), 1)
def test_svc_level_dupe_time_leeway(self): ''' check that service-level duplicate activities within the defined time leeway are caught ''' svcA, svcB = TestTools.create_mock_services() recA = TestTools.create_mock_svc_record(svcA) recB = TestTools.create_mock_svc_record(svcB) actA = Activity() actA.StartTime = datetime(1, 2, 3, 4, 5, 6, 7) actA.ServiceDataCollection = TestTools.create_mock_servicedatacollection(svcA, record=recA) actA.Type = set(svcA.SupportedActivities).intersection(set(svcB.SupportedActivities)).pop() actB = Activity() actB.StartTime = datetime(1, 2, 3, 4, 6, 6, 7) actB.ServiceDataCollection = TestTools.create_mock_servicedatacollection(svcB, record=recB) actB.Type = actA.Type actA.CalculateUID() actB.CalculateUID() s = SynchronizationTask(None) s._activities = [] s._accumulateActivities(recA, [actA]) s._accumulateActivities(recB, [actB]) self.assertIn(actA.UID, actA.UIDs) self.assertIn(actB.UID, actA.UIDs) self.assertIn(actA.UID, actB.UIDs) self.assertIn(actB.UID, actB.UIDs) # we need to fake up the service records to avoid having to call the actual sync method where these values are normally preset recA = TestTools.create_mock_svc_record(svcA) recB = TestTools.create_mock_svc_record(svcB) recA.SynchronizedActivities = [actA.UID] recB.SynchronizedActivities = [actB.UID] s._serviceConnections = [recA, recB] recipientServicesA = s._determineRecipientServices(actA) recipientServicesB = s._determineRecipientServices(actB) self.assertEqual(len(recipientServicesA), 0) self.assertEqual(len(recipientServicesB), 0) self.assertEqual(len(s._activities), 1)