-
Notifications
You must be signed in to change notification settings - Fork 74
[#120] method to list tickets #800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fec88de
b5c2033
5b0873a
3323b9d
5626233
b133459
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,25 @@ | ||
| #! /usr/bin/env python | ||
|
|
||
| import calendar | ||
| import datetime | ||
| import logging | ||
| import os | ||
| import sys | ||
| import unittest | ||
| import time | ||
| import calendar | ||
| import unittest | ||
|
|
||
| import irods.test.helpers as helpers | ||
| import tempfile | ||
| from irods.session import iRODSSession | ||
| import irods.exception as ex | ||
| import irods.keywords as kw | ||
| from irods.ticket import Ticket | ||
| from irods.ticket import list_tickets, Ticket | ||
| from irods.models import TicketQuery, DataObject, Collection | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| # As with most of the modules in this test suite, session objects created via | ||
| # make_session() are implicitly agents of a rodsadmin unless otherwise indicated. | ||
| # Counterexamples within this module shall be obvious as they are instantiated by | ||
|
|
@@ -29,6 +34,17 @@ | |
| ) | ||
|
|
||
|
|
||
| def delete_tickets(session, dry_run = False): | ||
| for res in session.query(TicketQuery.Ticket): | ||
| t = Ticket(session, result=res) | ||
| if dry_run in (False, None): | ||
| t.delete(**{kw.ADMIN_KW: ""}) | ||
| elif isinstance(dry_run, list): | ||
| dry_run.append(t) | ||
| else: | ||
| logger.info('Found ticket: %s',t.string) | ||
|
|
||
|
|
||
| def delete_my_tickets(session): | ||
| my_userid = session.users.get(session.username).id | ||
| my_tickets = session.query(TicketQuery.Ticket).filter( | ||
|
|
@@ -358,6 +374,30 @@ | |
| os.unlink(file_.name) | ||
| alice.cleanup() | ||
|
|
||
| def test_new_attributes_in_tickets__issue_801(self): | ||
|
|
||
| admin_ticket_for_bob = None | ||
|
|
||
| if (admin:=helpers.make_session()).server_version < (4, 3, 0): | ||
| self.skipTest('"create_time" and "modify_time" not supported for Ticket') | ||
|
Comment on lines
+381
to
+382
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check isn't necessary since we no longer support anything earlier than 4.3.0. |
||
|
|
||
| try: | ||
| with self.login(self.bob) as bob: | ||
| bobs_ticket = Ticket(bob) | ||
| bobs_ticket.issue('write', helpers.home_collection(bob)) | ||
| time.sleep(2) | ||
| bobs_ticket.modify('add', 'user', admin.username) | ||
| bobs_ticket = Ticket(bob, result=[], ticket=bobs_ticket.string) | ||
| self.assertGreaterEqual( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be |
||
| bobs_ticket.modify_time, | ||
| bobs_ticket.create_time + datetime.timedelta(seconds=1) | ||
korydraughn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| admin_ticket_for_bob = Ticket(admin, result=[], ticket=bobs_ticket.string) | ||
| self.assertEqual(admin_ticket_for_bob.id, bobs_ticket.id) | ||
| finally: | ||
| if admin_ticket_for_bob: | ||
| admin_ticket_for_bob.delete(**{kw.ADMIN_KW:''}) | ||
|
|
||
| class TestTicketOps(unittest.TestCase): | ||
|
|
||
|
|
@@ -455,7 +495,21 @@ | |
| def test_coll_ticket_write(self): | ||
| self._ticket_write_helper(obj_type="coll") | ||
|
|
||
|
|
||
| def test_list_tickets__issue_120(self): | ||
|
|
||
| ses = self.sess | ||
|
|
||
| # t first assigned as a "utility" Ticket object | ||
| t = Ticket(ses).issue('read', helpers.home_collection(ses)) | ||
|
|
||
| # This time, t receives attributes from an internal GenQuery result. | ||
| t = Ticket(ses, result=[], ticket=t.string) | ||
|
|
||
| # Check an id attribute is present and listed in the results from list_tickets | ||
| self.assertIn(t.id, (_.id for _ in list_tickets(ses))) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| # let the tests find the parent irods lib | ||
| sys.path.insert(0, os.path.abspath("../..")) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| from irods.api_number import api_number | ||
| from irods.message import iRODSMessage, TicketAdminRequest | ||
| from irods.models import TicketQuery | ||
| from irods.column import Like | ||
| from collections.abc import Mapping, Sequence | ||
|
|
||
| import random | ||
| import string | ||
| import logging | ||
| import datetime | ||
| import calendar | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
@@ -28,15 +30,71 @@ | |
| raise # final try at conversion, so a failure is an error | ||
|
|
||
|
|
||
| def list_tickets(session, *, raw=False, all=True): | ||
| """ | ||
| Enumerates (via GenQuery1) all tickets visible by, or owned by, the current user. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GenQuery1 is an implementation detail. It's unlikely that anyone needs to know how the information is gathered.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted. Will change if desired. However, not mentioning it could confuse beginners, unless some work is done on the README. (Note for the "future me"? Should I explain what specific queries are incompatible with general queries? Or that Genquery2 will not suffice for this purpose until/unless the entire library is basically recast to be based on GenQuery2.)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Please say more. |
||
|
|
||
| Args: | ||
| session: An iRODSSession object for use in the query. | ||
| raw: True if only the queried rows are to be returned; False to construct Ticket objects for each row. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is If a user wants the GenQuery results, they can use GenQuery directly.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not all the columns are translated, so I'd prefer to leave the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you provide an example of using the |
||
| all: True if a comprehensive list is desired; otherwise only those | ||
| tickets owned by the calling user. | ||
|
Comment on lines
+40
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should update the implementation to always return the full listing of tickets and remove the Reading the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll defer to the experts on this. |
||
|
|
||
| Returns: | ||
| An iterator over a range of ticket objects. | ||
| """ | ||
|
Check failure on line 45 in irods/ticket.py
|
||
| query = session.query(TicketQuery.Ticket) | ||
| if not all: | ||
| query = query.filter( | ||
| TicketQuery.Ticket.user_id == session.users.get(session.username).id | ||
| ) | ||
| if raw: | ||
| yield from query | ||
| else: | ||
| yield from (Ticket(session, result=_) for _ in query) | ||
|
|
||
|
|
||
| class Ticket: | ||
| def __init__(self, session, ticket="", result=None, allow_punctuation=False): | ||
| self._session = session | ||
| try: | ||
| if result is not None: | ||
| if isinstance(result, Mapping): | ||
| if (single_string:=result.get(TicketQuery.Ticket.string, '')): | ||
| if ticket and (ticket != single_string): | ||
|
Check failure on line 63 in irods/ticket.py
|
||
| raise RuntimeError( | ||
| f"The specified result contained a ticket string mismatched to the provided identifier ({ticket = })" | ||
| ) | ||
|
|
||
| # Allow limited query for the purpose of populating id and other attributes | ||
| if result == [] and ticket: | ||
| result[:] = list(session.query(TicketQuery.Ticket).filter(TicketQuery.Ticket.string == ticket)) | ||
|
|
||
| if isinstance(result, Sequence): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have tests for all these different types of |
||
| if ticket: | ||
| result = [_ for _ in result if _[TicketQuery.Ticket.string] == ticket][:1] | ||
korydraughn marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I'm normally fine with this, in this case, I find that it makes this part hard to read: if _[TicketQuery.Ticket.string]I might recommend using a proper variable name instead here for readability. Up to you |
||
|
|
||
| if not result: | ||
| result = None | ||
| else: | ||
| result = result[0] | ||
|
|
||
| if result: | ||
| ticket = result[TicketQuery.Ticket.string] | ||
| for attr, value in TicketQuery.Ticket.__dict__.items(): | ||
| if value is TicketQuery.Ticket.string: continue | ||
| if not attr.startswith("_"): | ||
| try: | ||
| setattr(self, attr, result[value]) | ||
| except KeyError: | ||
| # backward compatibility with older schema versions | ||
| pass | ||
| except TypeError: | ||
| raise RuntimeError( | ||
| "If specified, 'result' parameter must be a TicketQuery.Ticket search result" | ||
| "If specified, 'result' parameter must be a TicketQuery.Ticket search result or iterable of same" | ||
korydraughn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| except IndexError: | ||
| raise RuntimeError( | ||
| "If both result and string are specified, at least one 'result' must match the ticket string" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the user be able to specify both? Does this lead to deterministic behavior?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a minor release I'd rather not change it, but I know it's confusing. It is admittedly confusing. Ticket objects exist in raw and cooked forms. The raw is for setup/creation, the cooked is to represent row results from a query. We can examine.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait... if
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. If result is the default of
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. if it's a list of DB entries, ticket is used to filter. If there's only a single result passed in, that's used to produce a cooked object.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you get a "cooked" object after filtering a list containing multiple items/rows too?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, both are true. If the ticket string is given and there is a matching row, we get an object with the attributes filled in, ie the cooked object.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if no row in I tried reading the implementation, but it wasn't clear to me if an error is raised or not. It appears you get an object containing the ticket string and that's it? |
||
| ) | ||
| self._ticket = ( | ||
| ticket if ticket else self._generate(allow_punctuation=allow_punctuation) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's explicitly mention the attributes being tested here (i.e.
create_timeandmodify_time). These will not be "new" for very long.