def test_model_item_status(self): "Test item status model" obj = ItemStatus(name='test') obj.save() self.assertEquals('test', obj.name) self.assertNotEquals(obj.id, None) obj.delete()
def status_add(request, response_format='html'): "ItemStatus edit" if not request.user.get_profile().is_admin('treeio.infrastructure'): return user_denied( request, message="You are not an Administrator of the Infrastructure module", response_format=response_format) if request.POST: if not 'cancel' in request.POST: item_status = ItemStatus() form = ItemStatusForm(request.POST, instance=item_status) if form.is_valid(): item_status = form.save(request) item_status.set_user_from_request(request) return HttpResponseRedirect( reverse('infrastructure_status_view', args=[item_status.id])) else: return HttpResponseRedirect( reverse('infrastructure_settings_view')) else: form = ItemStatusForm() context = _get_default_context(request) context.update({'form': form}) return render_to_response('infrastructure/item_status_add', context, context_instance=RequestContext(request), response_format=response_format)
def test_model_item(self): "Test item model" type = ItemType(name='test') type.save() status = ItemStatus(name='test') status.save() obj = Item(name='test', item_type=type, status=status) obj.save() self.assertEquals('test', obj.name) self.assertNotEquals(obj.id, None) obj.delete()
def setUp(self): "Initial Setup" if not self.prepared: self.group, created = Group.objects.get_or_create(name='test') duser, created = DjangoUser.objects.get_or_create( username=self.username) duser.set_password(self.password) duser.save() self.user, created = User.objects.get_or_create(user=duser) self.user.save() perspective, created = Perspective.objects.get_or_create( name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.type = ItemType(name='test') self.type.set_default_user() self.type.save() self.status = ItemStatus(name='test') self.status.set_default_user() self.status.save() self.field = ItemField(name='test', label='test', field_type='text') self.field.set_default_user() self.field.save() self.item = Item(name='test', item_type=self.type, status=self.status) self.item.set_default_user() self.item.save() self.value = ItemValue(field=self.field, item=self.item) self.value.save() self.servicing = ItemServicing(name='test') self.servicing.set_default_user() self.servicing.save() self.client = Client() self.prepared = True
def test_model_item_value(self): "Test item value model" status = ItemStatus(name='test') status.save() type = ItemType(name='test') type.save() item = Item(name='test', item_type=type, status=status) item.save() field = ItemField(name='test', label='test', field_type='text') field.save() obj = ItemValue(value='test', field=field, item=item) obj.save() self.assertEquals('test', obj.value) self.assertNotEquals(obj.id, None) obj.delete()
def setUp(self): "Initial Setup" if not self.prepared: # Clean up first Object.objects.all().delete() # Create objects try: self.group = Group.objects.get(name='test') except Group.DoesNotExist: Group.objects.all().delete() self.group = Group(name='test') self.group.save() try: self.user = DjangoUser.objects.get(username=self.username) self.user.set_password(self.password) try: self.profile = self.user.get_profile() except Exception: User.objects.all().delete() self.user = DjangoUser(username=self.username, password='') self.user.set_password(self.password) self.user.save() except DjangoUser.DoesNotExist: User.objects.all().delete() self.user = DjangoUser(username=self.username, password='') self.user.set_password(self.password) self.user.save() try: perspective = Perspective.objects.get(name='default') except Perspective.DoesNotExist: Perspective.objects.all().delete() perspective = Perspective(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.type = ItemType(name='test') self.type.set_default_user() self.type.save() self.status = ItemStatus(name='test') self.status.set_default_user() self.status.save() self.field = ItemField(name='test', label='test', field_type='text') self.field.set_default_user() self.field.save() self.item = Item(name='test', item_type=self.type, status=self.status) self.item.set_default_user() self.item.save() self.value = ItemValue(field=self.field, item=self.item) self.value.save() self.servicing = ItemServicing(name='test') self.servicing.set_default_user() self.servicing.save() self.client = Client() self.prepared = True