def setUp(self): value = randint(1000, 5000) self.data_valid = {'name': get_random_name(), 'sku': get_random_sku(), 'cost': get_random_cost()} self.data_long = {'name': 'Exceedingly Long {}'.format(value), 'sku': get_random_sku(), 'cost': get_random_cost()} self.data_empty = {'name': None, 'sku': get_random_sku(), 'cost': get_random_cost()} self.data_blank = {'name': '', 'sku': get_random_sku(), 'cost': get_random_cost()}
def test_06_filter(self): names = ['Moon', 'Sun', 'Star'] for idx in range(len(names)): self.data.update({'name': names[idx], 'sku': get_random_sku()}) Widget.objects.create(**self.data) actual = Widget.objects.filter(deleted=False) self.assertEqual(len(names), len(actual))
def populate_widgets(n): from django.contrib.auth.models import User from simple.models import Widget from simple.tests.utils import get_random_cost, get_random_sku try: user = User.objects.get(username='******') except User.DoesNotExist as e: exit('ERROR: create missing username: qa') if hasattr(user, 'id'): widgets = [] for i in range(n): while True: ref = randint(10000, 50000) kwargs = { 'name': 'Random Widget {}'.format(ref), 'sku': get_random_sku(), 'cost': get_random_cost(), 'created_by': user, 'deleted': False } try: w = Widget.objects.create(**kwargs) widgets.append(w) break except IntegrityError as e: if str(e).endswith('name'): w = Widget.objects.filter(name=kwargs['name']) elif str(e).endswith('sku'): w = Widget.objects.filter(sku=kwargs['sku']) widgets.append(w[0]) break return widgets else: error = 'script assumes User: qa exists as first user created!' exit('ERROR: {}'.format(error))
def setUp(self): user = User.objects.get(username='******') self.data = { 'name': 'Moon', 'sku': get_random_sku(), 'cost': get_random_cost(), 'created_by': user, 'deleted': False }
def setUp(self): user = User.objects.get(username='******') self.locations = get_locations() self.i_data = {'quantity': 1, 'created_by': user, 'deleted': False} self.s_data = { 'name': 'Moon', 'location': self.locations[0], 'created_by': user, 'deleted': False } self.w_data = { 'name': 'Moon', 'sku': get_random_sku(), 'cost': get_random_cost(), 'created_by': user, 'deleted': False }
def setUp(self): value = randint(1000, 5000) self.user = User.objects.get(username='******') self.s_data = {'name': get_random_name(), 'location': get_random_location(), 'created_by': self.user} self.w_data = {'name': get_random_name(), 'sku': get_random_sku(), 'cost': get_random_cost(), 'created_by': self.user} self.data_valid = {'quantity': value, 'created_by': self.user.id} self.data_large = {'quantity': value * value, 'created_by': self.user.id} self.data_empty = {'quantity': None, 'created_by': self.user.id} self.data_blank = {'quantity': '', 'created_by': self.user.id}