From 7806de5f05bbc153b8405f1e693e1ae202e2a54c Mon Sep 17 00:00:00 2001 From: Scott Bahling Date: Wed, 12 Feb 2020 18:38:33 +0100 Subject: Implement sub-api callbackso When an api object makes an API request to the OBS server, in addition to returning the results, it sends a reference to itself to the registered callback function (if set). We use this to track the last api object called so we can access the last raw request response. --- test/test_api.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/test_api.py b/test/test_api.py index 50afeca..09b2806 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -1,7 +1,9 @@ import re import pytest import os +import requests_mock as rmock from . import test_dir +from obsapi.null import Null from obsapi import ObsApi from lxml import etree try: @@ -202,6 +204,20 @@ def locked_package_meta(): """ +def test_callback(requests_mock): + """ + Test that api callback works and returns a reference to + the sub-api instance + """ + text = '' + requests_mock.get(rmock.ANY, text=text) + assert isinstance(api.lastapi, type(Null)) + api.build.get(prj=prj) + assert api.lastapi is api.build + api.source.get(prj=prj) + assert api.lastapi is api.source + + def test_get_project_meta(requests_mock): matcher = prj_meta_re text = '' -- cgit v1.2.3