mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-12 23:56:13 +01:00
core.Request - implement ordering compatible with py3
This commit is contained in:
parent
9073b1a1d2
commit
783ed2b6e0
12
osc/core.py
12
osc/core.py
@ -28,7 +28,7 @@ import sys
|
|||||||
import tempfile
|
import tempfile
|
||||||
import textwrap
|
import textwrap
|
||||||
import time
|
import time
|
||||||
from functools import cmp_to_key
|
from functools import cmp_to_key, total_ordering
|
||||||
from http.client import IncompleteRead
|
from http.client import IncompleteRead
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from urllib.parse import urlsplit, urlunsplit, urlparse, quote_plus, urlencode, unquote
|
from urllib.parse import urlsplit, urlunsplit, urlparse, quote_plus, urlencode, unquote
|
||||||
@ -2812,6 +2812,7 @@ class Action:
|
|||||||
return Action(action_node.get('type'), **kwargs)
|
return Action(action_node.get('type'), **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@total_ordering
|
||||||
class Request:
|
class Request:
|
||||||
"""Represents a request (``<request />``)"""
|
"""Represents a request (``<request />``)"""
|
||||||
|
|
||||||
@ -2831,6 +2832,12 @@ class Request:
|
|||||||
self.statehistory = []
|
self.statehistory = []
|
||||||
self.reviews = []
|
self.reviews = []
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return int(self.reqid) == int(other.reqid)
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return int(self.reqid) < int(other.reqid)
|
||||||
|
|
||||||
def read(self, root):
|
def read(self, root):
|
||||||
"""read in a request"""
|
"""read in a request"""
|
||||||
self._init_attributes()
|
self._init_attributes()
|
||||||
@ -3097,9 +3104,6 @@ class Request:
|
|||||||
|
|
||||||
return '\n'.join(lines)
|
return '\n'.join(lines)
|
||||||
|
|
||||||
def __cmp__(self, other):
|
|
||||||
return cmp(int(self.reqid), int(other.reqid))
|
|
||||||
|
|
||||||
def create(self, apiurl, addrevision=False, enforce_branching=False):
|
def create(self, apiurl, addrevision=False, enforce_branching=False):
|
||||||
"""create a new request"""
|
"""create a new request"""
|
||||||
query = {'cmd': 'create'}
|
query = {'cmd': 'create'}
|
||||||
|
40
tests/test_core_request.py
Normal file
40
tests/test_core_request.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
from osc.core import Request
|
||||||
|
|
||||||
|
|
||||||
|
class TestRequest(unittest.TestCase):
|
||||||
|
def test_eq(self):
|
||||||
|
req1 = Request()
|
||||||
|
req1.reqid = 1
|
||||||
|
req2 = Request()
|
||||||
|
req2.reqid = 1
|
||||||
|
self.assertEqual(req1, req2)
|
||||||
|
|
||||||
|
def test_lt(self):
|
||||||
|
req1 = Request()
|
||||||
|
req1.reqid = 1
|
||||||
|
req2 = Request()
|
||||||
|
req2.reqid = 2
|
||||||
|
self.assertTrue(req1 < req2)
|
||||||
|
|
||||||
|
def test_gt(self):
|
||||||
|
req1 = Request()
|
||||||
|
req1.reqid = 2
|
||||||
|
req2 = Request()
|
||||||
|
req2.reqid = 1
|
||||||
|
self.assertTrue(req1 > req2)
|
||||||
|
|
||||||
|
def test_sort(self):
|
||||||
|
req1 = Request()
|
||||||
|
req1.reqid = 2
|
||||||
|
req2 = Request()
|
||||||
|
req2.reqid = 1
|
||||||
|
requests = [req1, req2]
|
||||||
|
requests.sort()
|
||||||
|
self.assertEqual(requests[0].reqid, 1)
|
||||||
|
self.assertEqual(requests[1].reqid, 2)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user