def test_pillow(self): from corehq.apps.change_feed.topics import get_topic_offset from corehq.pillows.synclog import get_user_sync_history_pillow consumer = get_test_kafka_consumer(topics.SYNCLOG_SQL) # get the seq id before the change is published kafka_seq = get_topic_offset(topics.SYNCLOG_SQL) # make sure user has empty reporting-metadata before a sync self.assertEqual(self.ccuser.reporting_metadata.last_syncs, []) # do a sync synclog = SyncLog(domain=self.domain.name, user_id=self.ccuser._id, date=datetime.datetime(2015, 7, 1, 0, 0)) synclog.save() # make sure kafka change updates the user with latest sync info message = next(consumer) change_meta = change_meta_from_kafka_message(message.value) synclog = self._get_latest_synclog() self.assertEqual(change_meta.document_id, synclog._id) self.assertEqual(change_meta.domain, self.domain.name) # make sure processor updates the user correctly pillow = get_user_sync_history_pillow() pillow.process_changes(since=kafka_seq, forever=False) ccuser = CommCareUser.get(self.ccuser._id) self.assertEqual(len(ccuser.reporting_metadata.last_syncs), 1) self.assertEqual(ccuser.reporting_metadata.last_syncs[0].sync_date, synclog.date) self.assertEqual(ccuser.reporting_metadata.last_sync_for_user.sync_date, synclog.date)
def test_login_as(self): self.web_user.is_superuser = True self.web_user.save() restore_uri = reverse('ota_restore', args=[self.domain]) auth_header = _get_auth_header(self.web_user_username, self.web_user_password) client = Client(HTTP_AUTHORIZATION=auth_header) device_id = "foo" # get the seq id before the change is published kafka_seq = get_topic_offset(topics.SYNCLOG_SQL) resp = client.get(restore_uri, data={ 'as': self.username, "device_id": device_id }, follow=True) self.assertEqual(resp.status_code, 200) pillow = get_user_sync_history_pillow() pillow.process_changes(since=kafka_seq, forever=False) restored_as_user = CommCareUser.get_by_username(self.username) self.assertEqual(len(restored_as_user.devices), 1) self.assertEqual(restored_as_user.devices[0].device_id, device_id)
def test_pillow(self): from corehq.apps.change_feed.topics import get_topic_offset from corehq.pillows.synclog import get_user_sync_history_pillow consumer = get_test_kafka_consumer(topics.SYNCLOG_SQL) # get the seq id before the change is published kafka_seq = get_topic_offset(topics.SYNCLOG_SQL) # make sure user has empty reporting-metadata before a sync self.assertEqual(self.ccuser.reporting_metadata.last_syncs, []) # do a sync synclog = SyncLog(domain=self.domain.name, user_id=self.ccuser._id, date=datetime.datetime(2015, 7, 1, 0, 0)) synclog.save() # make sure kafka change updates the user with latest sync info message = next(consumer) change_meta = change_meta_from_kafka_message(message.value) synclog = self._get_latest_synclog() self.assertEqual(change_meta.document_id, synclog._id) self.assertEqual(change_meta.domain, self.domain.name) # make sure processor updates the user correctly pillow = get_user_sync_history_pillow() pillow.process_changes(since=kafka_seq, forever=False) ccuser = CommCareUser.get(self.ccuser._id) self.assertEqual(len(ccuser.reporting_metadata.last_syncs), 1) self.assertEqual(ccuser.reporting_metadata.last_syncs[0].sync_date, synclog.date) self.assertEqual(ccuser.reporting_metadata.last_sync_for_user.sync_date, synclog.date)
def test_pillow_form_processed(self): from corehq.apps.change_feed.topics import get_topic_offset from corehq.pillows.synclog import get_user_sync_history_pillow self.assertEqual(UserReportingMetadataStaging.objects.count(), 0) UserReportingMetadataStaging.add_submission( self.domain.name, self.ccuser._id, '123', None, None, {}, datetime.datetime.utcnow() ) self.assertEqual(UserReportingMetadataStaging.objects.count(), 1) consumer = get_test_kafka_consumer(topics.SYNCLOG_SQL) # get the seq id before the change is published kafka_seq = get_topic_offset(topics.SYNCLOG_SQL) # make sure user has empty reporting-metadata before a sync ccuser = CommCareUser.get(self.ccuser._id) self.assertEqual(ccuser.reporting_metadata.last_syncs, []) # do a sync synclog = SimplifiedSyncLog(domain=self.domain.name, user_id=self.ccuser._id, date=datetime.datetime(2015, 7, 1, 0, 0), app_id='123') synclog.save() # make sure kafka change updates the user with latest sync info message = next(consumer) change_meta = change_meta_from_kafka_message(message.value) synclog = self._get_latest_synclog() self.assertEqual(change_meta.document_id, synclog._id) self.assertEqual(change_meta.domain, self.domain.name) self.assertEqual(UserReportingMetadataStaging.objects.count(), 1) # make sure processor updates the user correctly pillow = get_user_sync_history_pillow() pillow.process_changes(since=kafka_seq) process_reporting_metadata_staging() ccuser = CommCareUser.get(self.ccuser._id) self.assertEqual(len(ccuser.reporting_metadata.last_syncs), 1) self.assertEqual(ccuser.reporting_metadata.last_syncs[0].sync_date, synclog.date) self.assertEqual(ccuser.reporting_metadata.last_sync_for_user.sync_date, synclog.date)