def _notify_due_actions(self, verbosity=0): """call notify_due_actions and check what is printed on the console""" buf = StringIO() sysout = sys.stdout sys.stdout = buf management.call_command('notify_due_actions', verbosity=verbosity, stdout=buf) buf.seek(0, 0) sys.stdout = sysout return buf.readlines()
def test_find_same_as(self): contact1 = mommy.make(models.Contact, firstname="John", lastname="Lennon") contact2 = mommy.make(models.Contact, firstname="Paul", lastname="McCartney") contact3 = mommy.make(models.Contact, firstname="Paul", lastname="McCartney") buf = StringIO() sysout = sys.stdout sys.stdout = buf management.call_command('find_same_as', verbosity=0, interactive=False, stdout=buf) buf.seek(0, 0) sys.stdout = sysout self.assertEqual(2, len(buf.readlines()))
def test_find_same_as_with_group(self): contact1 = mommy.make(models.Contact, firstname="John", lastname="Lennon") contact2 = mommy.make(models.Contact, firstname="Paul", lastname="McCartney") contact3 = mommy.make(models.Contact, firstname="Paul", lastname="McCartney") buf = StringIO() sysout = sys.stdout sys.stdout = buf management.call_command('find_same_as', "SameAs", verbosity=0, interactive=False, stdout=buf) buf.seek(0, 0) sys.stdout = sysout self.assertEqual(2, len(buf.readlines())) qs = models.Group.objects.filter(name="SameAs") self.assertEqual(1, qs.count()) self.assertEqual(qs[0].contacts.count(), 2) self.assertFalse(contact1 in qs[0].contacts.all()) self.assertTrue(contact2 in qs[0].contacts.all()) self.assertTrue(contact3 in qs[0].contacts.all())
def unicode_csv_reader(the_file, encoding, dialect=csv.excel, **kwargs): """read csv file properly""" the_file.seek(0) content = the_file.read() decoded = content.decode(encoding) text_file = StringIO(decoded) if 'delimiter' in kwargs: kwargs['delimiter'] = str(kwargs['delimiter']) csv_reader = csv.reader(text_file, dialect=dialect, **kwargs) for row in csv_reader: yield [cell for cell in row]