def test_process_upload(self, pg_db_conn, monkeypatch, caplog): """Test to see that upload only sends eval-msgs on new systems and ones with new vmaas_json""" same_json = "{'diff': False}" diff_json = "{'diff': True}" upld_data = {'id': 'A-SYSTEM-ID', 'rh_account': 'AN-ACCOUNT', 'url': 'A-URL', 'satellite_managed': False} monkeypatch.setattr(MQWriter, 'send', lambda self, msg, loop: LOGGER.info('SENT')) monkeypatch.setattr(listener.upload_listener, 'parse_archive', lambda upld_dta: same_json) # first-upload - should send caplog.clear() with caplog.at_level(logging.INFO): process_upload(upld_data, pg_db_conn, None) assert caplog.records[0].msg == 'SENT' # re-upload - should not send caplog.clear() with caplog.at_level(logging.INFO): process_upload(upld_data, pg_db_conn, None) assert not caplog.records # same-id, diff-vmaas upload - should send monkeypatch.setattr(listener.upload_listener, 'parse_archive', lambda upld_dta: diff_json) caplog.clear() with caplog.at_level(logging.INFO): process_upload(upld_data, pg_db_conn, None) assert caplog.records[0].msg == 'SENT'
def test_process_upload(self, pg_db_conn, monkeypatch, caplog): # pylint: disable=unused-argument """Test to see that upload only sends eval-msgs on new systems and ones with new vmaas_json""" same_json = "{'diff': False}" diff_json = "{'diff': True}" upld_data = { 'host': { 'id': 'A-SYSTEM-ID', 'account': 'AN-ACCOUNT' }, 'platform_metadata': { 'url': 'A-URL', 'request_id': 'some-request-id' }, 'timestamp': 'some-time-stamp' } monkeypatch.setattr(MQWriter, 'send', lambda self, msg, loop: LOGGER.info('SENT')) monkeypatch.setattr(listener.upload_listener, 'parse_archive', lambda upld_dta: (same_json, [])) monkeypatch.setattr(listener.upload_listener, 'DIRECT_INVENTORY_FETCH', False) with DatabasePool(1): # first-upload - should send caplog.clear() with caplog.at_level(logging.INFO): sent = process_upload(upld_data, None) assert caplog.records[0].msg == 'SENT' assert sent is True self._mark_evaluated(upld_data['host']['id']) # re-upload - should not send caplog.clear() with caplog.at_level(logging.INFO): sent = process_upload(upld_data, None) assert sent is False # same-id, diff-vmaas upload - should send monkeypatch.setattr(listener.upload_listener, 'parse_archive', lambda upld_dta: (diff_json, [])) caplog.clear() with caplog.at_level(logging.INFO): sent = process_upload(upld_data, None) assert caplog.records[0].msg == 'SENT' assert sent is True
def test_process_upload(self, pg_db_conn, monkeypatch, caplog): # pylint: disable=unused-argument """Test to see that upload only sends eval-msgs on new systems and ones with new vmaas_json""" upld_data = { 'host': { 'id': 'A-SYSTEM-ID', 'account': 'AN-ACCOUNT', 'system_profile': { 'installed_packages': ['kernel'] } }, 'platform_metadata': { 'url': 'A-URL', 'request_id': 'some-request-id' }, 'timestamp': 'some-time-stamp' } monkeypatch.setattr(MQWriter, 'send', lambda self, msg, loop: LOGGER.info('SENT')) with DatabasePool(1): # first-upload - should send caplog.clear() with caplog.at_level(logging.INFO): sent = process_upload(upld_data, None) assert caplog.records[0].msg == 'SENT' assert sent is True self._mark_evaluated(upld_data['host']['id']) # re-upload - should not send caplog.clear() with caplog.at_level(logging.INFO): sent = process_upload(upld_data, None) assert sent is False # same-id, diff pkg profile - should send upld_data['host']['system_profile']['installed_packages'].append( 'glibc') caplog.clear() with caplog.at_level(logging.INFO): sent = process_upload(upld_data, None) assert caplog.records[0].msg == 'SENT' assert sent is True