Exemplo n.º 1
0
 def test_truncate_title(self):
     self.assertEqual(mint.truncate_title('Some great title [', 20),
                      'Some great title')
     self.assertEqual(mint.truncate_title(' Some great title abc', 5),
                      'Some')
     self.assertEqual(mint.truncate_title('S', 1), 'S')
     self.assertEqual(
         mint.truncate_title('Some great title [', 20, 'Amazon: '),
         'Amazon: Some great')
     self.assertEqual(mint.truncate_title('Some great title [', 20, '2x: '),
                      '2x: Some great title')
Exemplo n.º 2
0
def get_title(amzn_obj, target_length):
    # Also works for a Refund record.
    qty = amzn_obj.quantity
    base_str = None
    if qty > 1:
        base_str = str(qty) + 'x'
    # Remove non-ASCII characters from the title.
    clean_title = ''.join(filter(lambda x: x in PRINTABLE, amzn_obj.title))
    return truncate_title(clean_title, target_length, base_str)