def test_licences_rows_only_assigned(self): self.licence1.assets.add(self.asset) self.licence1.users.add(self.user) self.licence1.users.add(self.owner) rows = [item for item in get_licences_rows(only_assigned=True)] self.assertEqual( rows, [ [ 'niw', 'software_category', 'number_bought', 'price', 'invoice_date', 'invoice_no', 'id', 'barcode', 'niw', 'user__username', 'user__first_name', 'user__last_name', 'owner__username', 'owner__first_name', 'owner__last_name', 'username', 'first_name', 'last_name', 'single_cost', ], [ 'niw-666', 'soft-cat1', '10', '1000', '2014-04-28', '666-999-666', '1', 'br-666', 'niw=666', 'user', 'Elmer', 'Stevens', 'owner', 'Eric', 'Brown', '', '', '', '', '', '', '', '', '', '', '', '', ], [ 'niw-666', 'soft-cat1', '10', '1000', '2014-04-28', '666-999-666', '', '', '', '', '', '', '', '', '', 'user', 'Elmer', 'Stevens', '100', ], [ 'niw-666', 'soft-cat1', '10', '1000', '2014-04-28', '666-999-666', '', '', '', '', '', '', '', '', '', 'owner', 'Eric', 'Brown', '100', ], ] )
def handle(self, *args, **options): only_licences = options['only_licences'] only_assets = options['only_assets'] filter_type = options['filter_type'] only_assigned_licences = options['only_assigned_licences'] if not any((only_licences, only_assets)): self.stdout.write( 'Arguments required, type --help for more informations\n', ) output = cStringIO.StringIO() writer = csv.writer(output) if only_assets and not only_licences: for row in get_assets_rows(filter_type): writer.writerow([smart_str(item) for item in row]) self.stdout.write(output.getvalue()) elif only_licences and not only_assets: for row in get_licences_rows(filter_type, only_assigned_licences): writer.writerow([smart_str(item) for item in row]) self.stdout.write(output.getvalue())
def test_licences_rows(self): self.licence1.assign(self.asset) self.licence1.assign(self.user) self.licence1.assign(self.owner) rows = [item for item in get_licences_rows()] self.assertListEqual( rows, [ [ 'niw', 'software_category', 'number_bought', 'price', 'invoice_date', 'invoice_no', 'id', 'barcode', 'niw', 'user__username', 'user__first_name', 'user__last_name', 'owner__username', 'owner__first_name', 'owner__last_name', 'region__name', 'username', 'first_name', 'last_name', 'single_cost', ], [ 'niw-666', 'soft-cat1', '10', '1000.00', '2014-04-28', '666-999-666', '', '', '', '', '', '', '', '', '', '', '', '', '', ], [ 'niw-666', 'soft-cat1', '10', '1000.00', '2014-04-28', '666-999-666', str(self.asset.id), 'br-666', 'niw=666', 'user', 'Elmer', 'Stevens', 'owner', 'Eric', 'Brown', 'Default region', '', '', '', '', '', '', '', '', '', '', '', '', '', ], [ 'niw-666', 'soft-cat1', '10', '1000.00', '2014-04-28', '666-999-666', '', '', '', '', '', '', '', '', '', '', 'user', 'Elmer', 'Stevens', '100.00', ], [ 'niw-666', 'soft-cat1', '10', '1000.00', '2014-04-28', '666-999-666', '', '', '', '', '', '', '', '', '', '', 'owner', 'Eric', 'Brown', '100.00', ], ] )
def get_result(self, *args, **kwargs): filter_type = kwargs.get('mode') data = [] for row in get_licences_rows(filter_type, True): data.append([item.decode('utf-8') for item in row]) return data
def test_licences_rows_only_assigned(self): self.licence1.assets.add(self.asset) self.licence1.users.add(self.user) self.licence1.users.add(self.owner) rows = [item for item in get_licences_rows(only_assigned=True)] self.assertEqual(rows, [ [ 'niw', 'software_category', 'number_bought', 'price', 'invoice_date', 'invoice_no', 'id', 'barcode', 'niw', 'user__username', 'user__first_name', 'user__last_name', 'owner__username', 'owner__first_name', 'owner__last_name', 'username', 'first_name', 'last_name', 'single_cost', ], [ 'niw-666', 'soft-cat1', '10', '1000', '2014-04-28', '666-999-666', '1', 'br-666', 'niw=666', 'user', 'Elmer', 'Stevens', 'owner', 'Eric', 'Brown', '', '', '', '', '', '', '', '', '', '', '', '', ], [ 'niw-666', 'soft-cat1', '10', '1000', '2014-04-28', '666-999-666', '', '', '', '', '', '', '', '', '', 'user', 'Elmer', 'Stevens', '100', ], [ 'niw-666', 'soft-cat1', '10', '1000', '2014-04-28', '666-999-666', '', '', '', '', '', '', '', '', '', 'owner', 'Eric', 'Brown', '100', ], ])