def test_cloud_notifier_job_update_existing_file(self, job): # pylint:disable=unused-argument,redefined-outer-name """Tests the job update for CloudNotifier when the image exists and is valid""" posted_payload = {} def fake_post(payload): nonlocal posted_payload posted_payload = payload def fake_upload(image_path, download_link): assert image_path == __file__, "Expecting given mock `image_path` to match '{}'".format( __file__) return "no_upload" cloud_notifier = CloudNotifier(fake_post, fake_upload) cloud_notifier.notify(job, __file__, n_iterations=-1) expected_payload = { 'query': 'mutation NotifyJobEvent($in: JobScalarChangesWithImageInput!)' ' {notifyJobScalarChangesWithImage(input: $in)}' } # Verify query structure assert 'query' in posted_payload, "Payload is expected to contain the key 'query'" assert posted_payload['query'] == expected_payload[ 'query'], "GraphQL queries should be identical" assert 'variables' in posted_payload, "Payload is expected to contain the key 'variables'" assert 'in' in posted_payload[ 'variables'], "'variables' dictionary is expected to contain a key called 'in'" # Verify empty imageUrl variables = posted_payload['variables']['in'] assert 'imageUrl' in variables, "'in' dictionary is expected to contain a key called 'imageUrl'" assert variables['imageUrl'] == "no_upload", "`imageUrl` value is expected to " \ "contain hard-coded value `no_upload`"
def test_cloud_notifier_job_update_no_image(self): # pylint:disable=unused-argument,redefined-outer-name """Tests the job update for CloudNotifier when no image is available or image does not exist""" posted_payload = {} def fake_post(payload): nonlocal posted_payload posted_payload = payload cloud_notifier = CloudNotifier(fake_post, _empty_upload) for path in ["fake_path", None]: cloud_notifier.notify(_get_job(), path, n_iterations=-1) expected_payload = { 'query': 'mutation NotifyJobEvent($in: JobScalarChangesWithImageInput!)' ' {notifyJobScalarChangesWithImage(input: $in)}' } # Verify query structure assert 'query' in posted_payload, "Payload is expected to contain the key 'query'" assert posted_payload['query'] == expected_payload[ 'query'], "GraphQL queries should be identical" assert 'variables' in posted_payload, "Payload is expected to contain the key 'variables'" assert 'in' in posted_payload['variables'], "'variables' dictionary is expected " \ "to contain a key called 'in'" # Verify empty imageUrl variables = posted_payload['variables']['in'] assert 'imageUrl' in variables, "'in' dictionary is expected to contain a key called 'imageUrl'" assert variables[ 'imageUrl'] == '', "`imageUrl` value is expected to be empty"