annotate roundup/test/mocknull.py @ 8180:d02ce1d14acd

feat: issue2551068 - Provide way to retrieve file/msg data via rest endpoint. Use Allow header to change format of /binary_content endpoint. If Allow header for endpoint is not application/json, it will be matched against the mime type for the file. */*, text/* are supported and will return the native mime type if present. Changes: move */* mime type from static dict of supported types. It was hardcoded to return json only. Now it can return a matching non-json mime type for the /binary_content endpoint. Edited some errors to explicitly add */* mime type. Cleanups to use ', ' separation in lists of valid mime types rather than just space separated. Remove ETag header when sending raw content. See issue 2551375 for background. Doc added to rest.txt. Small format fix up (add dash) in CHANGES.txt. Make passing an unset/None/False accept_mime_type to format_dispatch_output a 500 error. This used to be the fallback to produce a 406 error after all processing had happened. It should no longer be possible to take that code path as all 406 errors (with valid accept_mime_types) are generated before processing takes place. Make format_dispatch_output handle output other than json/xml so it can send back binary_content data. Removed a spurious client.response_code = 400 that seems to not be used. Tests added for all code paths. Database setup for tests msg and file entry. This required a file upload test to change so it doesn't look for file1 as the link returned by the upload. Download the link and verify the data rather than verifying the link. Multiple formatting changes to error messages to make all lists of valid mime types ', ' an not just space separated.
author John Rouillard <rouilj@ieee.org>
date Sun, 08 Dec 2024 17:22:33 -0500
parents f2c31f5ec50b
children 617d85ce4ac3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2532
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2 class MockNull:
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
3 def __init__(self, **kwargs):
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
4 for key, value in kwargs.items():
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
5 self.__dict__[key] = value
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
6
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
7 def __call__(self, *args, **kwargs): return MockNull()
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
8 def __getattr__(self, name):
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
9 # This allows assignments which assume all intermediate steps are Null
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
10 # objects if they don't exist yet.
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
11 #
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
12 # For example (with just 'client' defined):
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
13 #
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
14 # client.db.config.TRACKER_WEB = 'BASE/'
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
15 self.__dict__[name] = MockNull()
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
16 return getattr(self, name)
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
17
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
18 def __getitem__(self, key): return self
5457
a35d4cc8cd1a fix MissingValue / MockNull to return False on __bool__ and add a
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5404
diff changeset
19 def __bool__(self): return False
5404
3757449e00c4 Python 3 preparation: use __bool__ instead of __nonzero__.
Joseph Myers <jsm@polyomino.org.uk>
parents: 2686
diff changeset
20 # Python 2 compatibility:
3757449e00c4 Python 3 preparation: use __bool__ instead of __nonzero__.
Joseph Myers <jsm@polyomino.org.uk>
parents: 2686
diff changeset
21 __nonzero__ = __bool__
5457
a35d4cc8cd1a fix MissingValue / MockNull to return False on __bool__ and add a
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5404
diff changeset
22 def __contains__(self, key): return False
5461
ad8031290639 Python 3 compatibility for missing / mock value
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5457
diff changeset
23 def __eq__(self, rhs): return False
ad8031290639 Python 3 compatibility for missing / mock value
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5457
diff changeset
24 def __ne__(self, rhs): return False
2532
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
25 def __str__(self): return ''
24d3b25a9157 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
26 def __repr__(self): return '<MockNull 0x%x>'%id(self)
2686
79fd8537ae3b .gettext() facility is vital for many roundup objects.
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2532
diff changeset
27 def gettext(self, str): return str
79fd8537ae3b .gettext() facility is vital for many roundup objects.
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2532
diff changeset
28 _ = gettext
5699
b1ab8bd18e79 Adding tests for csrf protection for rest. Also test disabling of
John Rouillard <rouilj@ieee.org>
parents: 5461
diff changeset
29 def get(self, name, default=None):
b1ab8bd18e79 Adding tests for csrf protection for rest. Also test disabling of
John Rouillard <rouilj@ieee.org>
parents: 5461
diff changeset
30 try:
b1ab8bd18e79 Adding tests for csrf protection for rest. Also test disabling of
John Rouillard <rouilj@ieee.org>
parents: 5461
diff changeset
31 return self.__dict__[name.lower()]
b1ab8bd18e79 Adding tests for csrf protection for rest. Also test disabling of
John Rouillard <rouilj@ieee.org>
parents: 5461
diff changeset
32 except KeyError:
b1ab8bd18e79 Adding tests for csrf protection for rest. Also test disabling of
John Rouillard <rouilj@ieee.org>
parents: 5461
diff changeset
33 return default

Roundup Issue Tracker: http://roundup-tracker.org/