Coverage for api/examples/image_requests.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 06:14 +0000

1from api.examples.environment import ORIGIN, TOKEN 

2 

3 

4auth = f'-H "Authorization: Bearer {TOKEN}"' if TOKEN else "" 

5identifier = "4bc43a04-ef46-4544-a0c1-63c63f56e276" 

6 

7syntax_examples = { 

8 "using single query parameter": "test", 

9 "using multiple query parameters": "test&license=pdm,by&categories=illustration&page_size=1&page=1", # noqa: E501 

10 "that are an exact match of Claude Monet": "%22Claude%20Monet%22", 

11 "related to both dog and cat": "dog+cat", 

12 "related to dog or cat, but not necessarily both": "dog|cat", 

13 "related to dog but won't include results related to 'pug'": "dog -pug", 

14 "matching anything with the prefix ‘net’": "net*", 

15 "matching dogs that are either corgis or labrador": "dogs + (corgis | labrador)", 

16 "matching strings close to the term theater" 

17 "with a difference of one character": "theatre~1", 

18} 

19 

20image_search_list_curl = "\n".join( 

21 f""" 

22# Example {index}: Search for images {purpose} 

23curl \\ 

24 {auth} \\ 

25 "{ORIGIN}/v1/images/?q={syntax}" 

26""" 

27 for (index, (purpose, syntax)) in enumerate(syntax_examples.items()) 

28) 

29 

30image_search_curl = f""" 

31# Search for images titled "Bark" by Sullivan 

32curl \\ 

33 {auth} \\ 

34 "{ORIGIN}/v1/images/?title=Bark&creator=Sullivan" 

35""" 

36 

37image_stats_curl = f""" 

38# Get the statistics for image sources 

39curl \\ 

40 {auth} \\ 

41 "{ORIGIN}/v1/images/stats/" 

42""" 

43 

44image_detail_curl = f""" 

45# Get the details of image ID {identifier} 

46curl \\ 

47 {auth} \\ 

48 "{ORIGIN}/v1/images/{identifier}/" 

49""" 

50 

51image_related_curl = f""" 

52# Get related images for image ID {identifier} 

53curl \\ 

54 {auth} \\ 

55 "{ORIGIN}/v1/images/{identifier}/related/" 

56""" 

57 

58image_complain_curl = f""" 

59# Report an issue about image ID {identifier} 

60curl \\ 

61 -X POST \\ 

62 -H "Content-Type: application/json" \\ 

63 {auth} \\ 

64 -d '{{"reason": "mature", "description": "Image contains sensitive content"}}' \\ 

65 "{ORIGIN}/v1/images/{identifier}/report/" 

66""" 

67 

68image_oembed_curl = f""" 

69# Retrieve embedded content from an image's URL 

70curl \\ 

71 {auth} \\ 

72 "{ORIGIN}/v1/images/oembed/?url=https://wordpress.org/openverse/photos/{identifier}" 

73"""