Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def recursively_call_properties(self, zenpy_object):
""" Recursively test that a Zenpy object's properties, and each linked property can be called without error. """
for attr_name in dir(zenpy_object):
if isinstance(getattr(type(zenpy_object), attr_name, None), property):
prop_val = getattr(zenpy_object, attr_name)
if prop_val and issubclass(prop_val.__class__, BaseObject):
self.recursively_call_properties(prop_val)
elif issubclass(prop_val.__class__, BaseResultGenerator):
for obj in prop_val:
self.recursively_call_properties(obj)
def iter_classes(mod):
for cls in vars(mod).values():
if isinstance(cls, type) and cls not in (BaseObject, ProxyDict, ProxyList):
yield cls
def create_tickets(self):
""" Helper method for creating some tickets with the raw_subject set. """
with self.recorder.use_cassette("{}-create".format(self.generate_cassette_name()), serialize_with='prettyjson'):
tickets = list()
for i in range(5):
tickets.append(Ticket(subject=str(i), raw_subject=str(i), description="desc{}".format(i)))
job_status = self.zenpy_client.tickets.create(tickets)
self.wait_for_job_status(job_status)
return tickets, [t for t in self.zenpy_client.tickets()]
def check_slice_range(self, values, slice_range):
self.assertEqual(len(values), len(slice_range))
for i, n in enumerate(slice_range):
self.assertIsInstance(values[i], Ticket)
self.assertTrue(values[i].id == n,
msg="expected Ticket id: {}, found: {}, values: {}".format(n, values[i], values))
def populate_cache(self, num_objects):
for i in range(num_objects):
self.cache[i] = Ticket(id=i)
def generate_tickets(self, num_tickets):
tickets = [Ticket(subject=str(i), description=str(i)) for i in range(num_tickets)]
job_status = self.zenpy_client.tickets.create(tickets)
self.wait_for_job_status(job_status)
def verify(self, ticket_count):
returned_tickets = [t for t in self.zenpy_client.tickets()]
self.assertEqual(len(returned_tickets), ticket_count)
for ticket in returned_tickets:
self.assertIsInstance(ticket, Ticket)
self.assertInCache(ticket)
def setUp(self):
super(TestTicketAPIMethods, self).setUp()
cassette_name = "{}-create-test-ticket".format(self.generate_cassette_name())
with self.recorder.use_cassette(cassette_name=cassette_name, serialize_with='prettyjson'):
self.subject = "subject"
self.comment = Comment(body="I am comment")
ticket_audit = self.zenpy_client.tickets.create(Ticket(subject=self.subject, comment=self.comment))
self.test_ticket = ticket_audit.ticket
def test_cache_object(self):
cache_key = 1
ticket = self.cache_item(id=cache_key)
self.assertIs(self.cache.get(get_object_type(ticket), cache_key), ticket)
def test_list_access_wrapped(self):
self.proxy_list.append([])
item = self.proxy_list[-1]
self.assertIsInstance(item, ProxyList)