def revoke_line(self, line): """ Revokes the purchase of a 'Journal'. This will attempt to revoke the access that was granted when this order was fulfilled. Args: line (Line): A line has data about the purchase. Access will be revoked for the 'journalaccess' record associated with this line order. Returns: Returns True if journal access was successfully revoked. """ try: logger.info('Attempting to revoke fulfillment of Line [%d]...', line.id) journal_uuid = line.product.attr.UUID # TODO: WL-1680: All calls from ecommerce to other services should be async revoke_journal_access( site_configuration=line.order.site.siteconfiguration, order_number=line.order.number) audit_log('line_revoked', order_line_id=line.id, order_number=line.order.number, product_class=line.product.get_product_class().name, user_id=line.order.user.id, journal_uuid=journal_uuid) return True except Exception: # pylint: disable=broad-except logger.exception('Failed to revoke fulfillment of Line [%d].', line.id) return False
def test_revoke_journal_access(self): """ Test 'revoke_journal_access' """ self.mock_access_token_response() data = { 'order_number': 'ORDER-64242', 'revoke_access': 'true' } responses.add( responses.POST, self.journal_access_url, status=200, body='{}', content_type='application/json' ) revoke_journal_access( site_configuration=self.site_configuration, order_number=data['order_number'] ) # The first call (response.calls[0]) is to get post the access token # The second call (response.calls[1]) is the 'post_journal_access' call self.assertEqual(len(responses.calls), 2, "Incorrect number of API calls") request = responses.calls[1].request self.assertEqual(json.loads(request.body), data) self.assertEqual(request.method, responses.POST) response = responses.calls[1].response self.assertEqual(response.status_code, 200)