Example #1
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(
            username=self.username)
        self.user.set_password(self.password)
        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()
Example #2
0
    def save(self, request):
        "Process form and create DB objects as required"

        if self.instance:
            item = self.instance
        else:
            item = Item()
            item.item_type = self.item_type

        item.name = unicode(self.cleaned_data['name'])
        item.parent = self.cleaned_data['parent']
        item.status = self.cleaned_data['status']
        item.manufacturer = self.cleaned_data['manufacturer']
        item.supplier = self.cleaned_data['supplier']
        item.owner = self.cleaned_data['owner']
        item.location = self.cleaned_data['location']
        item.asset = self.cleaned_data['asset']

        if not item.id:
            item.set_user_from_request(request)
        item.save()
        if self.instance:
            item.itemvalue_set.all().delete()
        for field in item.item_type.fields.all():
            for form_name in self.cleaned_data:
                if re.match(str("^" + field.name + "___\d+$"), form_name):
                    value = None
                    if isinstance(self.fields[form_name], forms.FileField):
                        value = ItemValue(
                            field=field,
                            item=item,
                            value=self._handle_uploaded_file(form_name))
                        if isinstance(self.fields[form_name],
                                      forms.ImageField):
                            self._image_resize(value.value)
                    else:
                        if field.field_type == 'picture' and isinstance(self.fields[form_name], forms.ChoiceField) and\
                                        self.cleaned_data[form_name] != 'delete':
                            value = ItemValue(
                                field=field,
                                item=item,
                                value=self.cleaned_data[form_name])
                        else:
                            value = ItemValue(
                                field=field,
                                item=item,
                                value=self.cleaned_data[form_name])
                    if value:
                        if not value.value:
                            value.value = ''
                        value.save()

        return item
Example #3
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        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()
Example #4
0
    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()
Example #5
0
    def save(self, request):
        "Process form and create DB objects as required"

        if self.instance:
            item = self.instance
        else:
            item = Item()
            item.item_type = self.item_type

        item.name = unicode(self.cleaned_data['name'])
        item.parent = self.cleaned_data['parent']
        item.status = self.cleaned_data['status']
        item.manufacturer = self.cleaned_data['manufacturer']
        item.supplier = self.cleaned_data['supplier']
        item.owner = self.cleaned_data['owner']
        item.location = self.cleaned_data['location']
        item.asset = self.cleaned_data['asset']

        if not item.id:
            item.set_user_from_request(request)
        item.save()
        if self.instance:
            item.itemvalue_set.all().delete()
        for field in item.item_type.fields.all():
            for form_name in self.cleaned_data:
                if re.match(str("^" + field.name + "___\d+$"), form_name):
                    value = None
                    if isinstance(self.fields[form_name], forms.FileField):
                        value = ItemValue(field=field, item=item,
                                          value=self._handle_uploaded_file(form_name))
                        if isinstance(self.fields[form_name], forms.ImageField):
                            self._image_resize(value.value)
                    else:
                        if field.field_type == 'picture' and isinstance(self.fields[form_name], forms.ChoiceField) and\
                                        self.cleaned_data[form_name] != 'delete':
                            value = ItemValue(field=field, item=item, value=self.cleaned_data[form_name])
                        else:
                            value = ItemValue(field=field, item=item, value=self.cleaned_data[form_name])
                    if value:
                        if not value.value:
                            value.value = ''
                        value.save()

        return item
Example #6
0
    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()
Example #7
0
class InfrastructureViewsTest(TestCase):
    username = "******"
    password = "******"

    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(
            username=self.username)
        self.user.set_password(self.password)
        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()

    ######################################
    # Testing views when user is logged in
    ######################################
    def test_index_login(self):
        "Test index page with login at /infrastructure/"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure'))
        self.assertEquals(response.status_code, 200)

    def test_index_infrastructure_login(self):
        "Test index page with login at /infrastructure/index/"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure_index'))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_index_owned(self):
        "Test index page with login at /infrastructure/owned/"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure_index_owned'))
        self.assertEquals(response.status_code, 200)

    # Type
    def test_infrastructure_type_add(self):
        "Test index page with login at /infrastructure/type/add/"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure_type_add'))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_type_view(self):
        "Test index page with login at /infrastructure/type/view/<type_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_type_view', args=[self.type.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_type_edit(self):
        "Test index page with login at /infrastructure/type/edit/<type_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_type_edit', args=[self.type.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_type_delete(self):
        "Test index page with login at /infrastructure/type/delete/<type_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_type_delete', args=[self.type.id]))
        self.assertEquals(response.status_code, 200)

    # Field
    def test_infrastructure_field_add(self):
        "Test index page with login at /infrastructure/field/add/"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure_field_add'))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_field_view(self):
        "Test index page with login at /infrastructure/field/view/<field_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_field_view', args=[self.field.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_field_edit(self):
        "Test index page with login at /infrastructure/field/edit/<field_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_field_edit', args=[self.field.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_field_del(self):
        "Test index page with login at /infrastructure/field/delete/<field_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_field_delete', args=[self.field.id]))
        self.assertEquals(response.status_code, 200)

    # Status
    def test_infrastructure_status_add(self):
        "Test index page with login at /infrastructure/status/add/"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure_status_add'))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_status_view(self):
        "Test index page with login at /infrastructure/status/view/<status_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_status_view', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_status_edit(self):
        "Test index page with login at /infrastructure/status/edit/<status_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_status_edit', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_status_del(self):
        "Test index page with login at /infrastructure/status/delete/<status_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_status_delete', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    # Item
    def test_infrastructure_item_add(self):
        "Test index page with login at /infrastructure/item/add/"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure_item_add'))
        self.assertEquals(response.status_code, 200)

    def test_infr_item_add_typed(self):
        "Test index page with login at /infrastructure/item/add/<type_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_item_add_typed', args=[self.type.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_item_view(self):
        "Test index page with login at /infrastructure/item/view/<item_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_item_view', args=[self.item.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_item_edit(self):
        "Test index page with login at /infrastructure/item/edit/<item_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_item_edit', args=[self.item.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_item_del(self):
        "Test index page with login at /infrastructure/item/delete/<item_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_item_delete', args=[self.item.id]))
        self.assertEquals(response.status_code, 200)

    # Service Record
    def test_infr_service_record_index(self):
        "Test index page with login at /infrastructure/service_record/index/"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_service_record_index'))
        self.assertEquals(response.status_code, 200)

    def test_infr_service_record_add(self):
        "Test index page with login at /infrastructure/service_record/add/"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_service_record_add'))
        self.assertEquals(response.status_code, 200)

    def test_infr_service_record_view(self):
        "Test index page with login at /infrastructure/service_record/view/<service_record_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_service_record_view',
                    args=[self.servicing.id]))
        self.assertEquals(response.status_code, 200)

    def test_infr_service_record_edit(self):
        "Test index page with login at /infrastructure/service_record/edit/<service_record_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_service_record_edit',
                    args=[self.servicing.id]))
        self.assertEquals(response.status_code, 200)

    def test_infr_service_record_delete(self):
        "Test index page with login at /infrastructure/service_record/delete/<service_record_id>"
        response = self.client.post('/accounts/login', {
            'username': self.username,
            'password': self.password
        })
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_service_record_delete',
                    args=[self.servicing.id]))
        self.assertEquals(response.status_code, 200)

    ######################################
    # Testing views when user is not logged in
    ######################################
    def test_index(self):
        "Testing /infrastructure/"
        response = self.client.get('/infrastructure/')
        # Redirects as unauthenticated
        self.assertRedirects(response, reverse('user_login'))

    def test_index_infrastructure_out(self):
        "Testing /infrastructure/index/"
        response = self.client.get(reverse('infrastructure_index'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_index_owned_out(self):
        "Testing /infrastructure/owned/"
        response = self.client.get(reverse('infrastructure_index_owned'))
        self.assertRedirects(response, reverse('user_login'))

    # Type
    def test_infrastructure_type_add_out(self):
        "Testing /infrastructure/type/add/"
        response = self.client.get(reverse('infrastructure_type_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_type_view_out(self):
        "Testing /infrastructure/type/view/<type_id>"
        response = self.client.get(
            reverse('infrastructure_type_view', args=[self.type.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_type_edit_out(self):
        "Testing /infrastructure/type/edit/<type_id>"
        response = self.client.get(
            reverse('infrastructure_type_edit', args=[self.type.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_type_delete_out(self):
        "Testing /infrastructure/type/delete/<type_id>"
        response = self.client.get(
            reverse('infrastructure_type_delete', args=[self.type.id]))
        self.assertRedirects(response, reverse('user_login'))

    # Field
    def test_infrastructure_field_add_out(self):
        "Testing /infrastructure/field/add/"
        response = self.client.get(reverse('infrastructure_field_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_field_view_out(self):
        "Testing /infrastructure/field/view/<field_id>"
        response = self.client.get(
            reverse('infrastructure_field_view', args=[self.field.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_field_edit_out(self):
        "Testing /infrastructure/field/edit/<field_id>"
        response = self.client.get(
            reverse('infrastructure_field_edit', args=[self.field.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_field_del_out(self):
        "Testing /infrastructure/field/delete/<field_id>"
        response = self.client.get(
            reverse('infrastructure_field_delete', args=[self.field.id]))
        self.assertRedirects(response, reverse('user_login'))

    # Status
    def test_infrastructure_status_add_out(self):
        "Testing /infrastructure/status/add/"
        response = self.client.get(reverse('infrastructure_status_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_status_view_out(self):
        "Testing /infrastructure/status/view/<status_id>"
        response = self.client.get(
            reverse('infrastructure_status_view', args=[self.status.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_status_edit_out(self):
        "Testing /infrastructure/status/edit/<status_id>"
        response = self.client.get(
            reverse('infrastructure_status_edit', args=[self.status.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_status_del_out(self):
        "Testing /infrastructure/status/delete/<status_id>"
        response = self.client.get(
            reverse('infrastructure_status_delete', args=[self.status.id]))
        self.assertRedirects(response, reverse('user_login'))

    # Item
    def test_infrastructure_item_add_out(self):
        "Testing /infrastructure/item/add/"
        response = self.client.get(reverse('infrastructure_item_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infr_item_add_typed_out(self):
        "Testing /infrastructure/item/add/<type_id>"
        response = self.client.get(
            reverse('infrastructure_item_add_typed', args=[self.type.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_item_view_out(self):
        "Testing /infrastructure/item/view/<item_id>"
        response = self.client.get(
            reverse('infrastructure_item_view', args=[self.item.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_item_edit_out(self):
        "Testing /infrastructure/item/edit/<item_id>"
        response = self.client.get(
            reverse('infrastructure_item_edit', args=[self.item.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_item_del_out(self):
        "Testing /infrastructure/item/delete/<item_id>"
        response = self.client.get(
            reverse('infrastructure_item_delete', args=[self.item.id]))
        self.assertRedirects(response, reverse('user_login'))

    # Service Record
    def test_infr_service_record_index_out(self):
        "Testing /infrastructure/service_record/index/"
        response = self.client.get(
            reverse('infrastructure_service_record_index'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infr_service_record_add_out(self):
        "Testing /infrastructure/service_record/add/"
        response = self.client.get(
            reverse('infrastructure_service_record_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infr_service_record_view_out(self):
        "Testing /infrastructure/service_record/view/<service_record_id>"
        response = self.client.get(
            reverse('infrastructure_service_record_view',
                    args=[self.servicing.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infr_service_record_edit_out(self):
        "Testing /infrastructure/service_record/edit/<service_record_id>"
        response = self.client.get(
            reverse('infrastructure_service_record_edit',
                    args=[self.servicing.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infr_service_record_delete_out(self):
        "Testing /infrastructure/service_record/delete/<service_record_id>"
        response = self.client.get(
            reverse('infrastructure_service_record_delete',
                    args=[self.servicing.id]))
        self.assertRedirects(response, reverse('user_login'))
Example #8
0
class InfrastructureViewsTest(TestCase):
    username = "******"
    password = "******"

    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        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()

    ######################################
    # Testing views when user is logged in
    ######################################
    def test_index_login(self):
        "Test index page with login at /infrastructure/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure'))
        self.assertEquals(response.status_code, 200)

    def test_index_infrastructure_login(self):
        "Test index page with login at /infrastructure/index/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure_index'))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_index_owned(self):
        "Test index page with login at /infrastructure/owned/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure_index_owned'))
        self.assertEquals(response.status_code, 200)

    # Type
    def test_infrastructure_type_add(self):
        "Test index page with login at /infrastructure/type/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure_type_add'))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_type_view(self):
        "Test index page with login at /infrastructure/type/view/<type_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_type_view', args=[self.type.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_type_edit(self):
        "Test index page with login at /infrastructure/type/edit/<type_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_type_edit', args=[self.type.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_type_delete(self):
        "Test index page with login at /infrastructure/type/delete/<type_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_type_delete', args=[self.type.id]))
        self.assertEquals(response.status_code, 200)

    # Field
    def test_infrastructure_field_add(self):
        "Test index page with login at /infrastructure/field/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure_field_add'))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_field_view(self):
        "Test index page with login at /infrastructure/field/view/<field_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_field_view', args=[self.field.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_field_edit(self):
        "Test index page with login at /infrastructure/field/edit/<field_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_field_edit', args=[self.field.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_field_del(self):
        "Test index page with login at /infrastructure/field/delete/<field_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_field_delete', args=[self.field.id]))
        self.assertEquals(response.status_code, 200)

    # Status
    def test_infrastructure_status_add(self):
        "Test index page with login at /infrastructure/status/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure_status_add'))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_status_view(self):
        "Test index page with login at /infrastructure/status/view/<status_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_status_view', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_status_edit(self):
        "Test index page with login at /infrastructure/status/edit/<status_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_status_edit', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_status_del(self):
        "Test index page with login at /infrastructure/status/delete/<status_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_status_delete', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    # Item
    def test_infrastructure_item_add(self):
        "Test index page with login at /infrastructure/item/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('infrastructure_item_add'))
        self.assertEquals(response.status_code, 200)

    def test_infr_item_add_typed(self):
        "Test index page with login at /infrastructure/item/add/<type_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_item_add_typed', args=[self.type.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_item_view(self):
        "Test index page with login at /infrastructure/item/view/<item_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_item_view', args=[self.item.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_item_edit(self):
        "Test index page with login at /infrastructure/item/edit/<item_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_item_edit', args=[self.item.id]))
        self.assertEquals(response.status_code, 200)

    def test_infrastructure_item_del(self):
        "Test index page with login at /infrastructure/item/delete/<item_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_item_delete', args=[self.item.id]))
        self.assertEquals(response.status_code, 200)

    # Service Record
    def test_infr_service_record_index(self):
        "Test index page with login at /infrastructure/service_record/index/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_service_record_index'))
        self.assertEquals(response.status_code, 200)

    def test_infr_service_record_add(self):
        "Test index page with login at /infrastructure/service_record/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_service_record_add'))
        self.assertEquals(response.status_code, 200)

    def test_infr_service_record_view(self):
        "Test index page with login at /infrastructure/service_record/view/<service_record_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_service_record_view', args=[self.servicing.id]))
        self.assertEquals(response.status_code, 200)

    def test_infr_service_record_edit(self):
        "Test index page with login at /infrastructure/service_record/edit/<service_record_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_service_record_edit', args=[self.servicing.id]))
        self.assertEquals(response.status_code, 200)

    def test_infr_service_record_delete(self):
        "Test index page with login at /infrastructure/service_record/delete/<service_record_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('infrastructure_service_record_delete', args=[self.servicing.id]))
        self.assertEquals(response.status_code, 200)

    ######################################
    # Testing views when user is not logged in
    ######################################
    def test_index(self):
        "Testing /infrastructure/"
        response = self.client.get('/infrastructure/')
        # Redirects as unauthenticated
        self.assertRedirects(response, reverse('user_login'))

    def test_index_infrastructure_out(self):
        "Testing /infrastructure/index/"
        response = self.client.get(reverse('infrastructure_index'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_index_owned_out(self):
        "Testing /infrastructure/owned/"
        response = self.client.get(reverse('infrastructure_index_owned'))
        self.assertRedirects(response, reverse('user_login'))

    # Type
    def test_infrastructure_type_add_out(self):
        "Testing /infrastructure/type/add/"
        response = self.client.get(reverse('infrastructure_type_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_type_view_out(self):
        "Testing /infrastructure/type/view/<type_id>"
        response = self.client.get(
            reverse('infrastructure_type_view', args=[self.type.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_type_edit_out(self):
        "Testing /infrastructure/type/edit/<type_id>"
        response = self.client.get(
            reverse('infrastructure_type_edit', args=[self.type.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_type_delete_out(self):
        "Testing /infrastructure/type/delete/<type_id>"
        response = self.client.get(
            reverse('infrastructure_type_delete', args=[self.type.id]))
        self.assertRedirects(response, reverse('user_login'))

    # Field
    def test_infrastructure_field_add_out(self):
        "Testing /infrastructure/field/add/"
        response = self.client.get(reverse('infrastructure_field_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_field_view_out(self):
        "Testing /infrastructure/field/view/<field_id>"
        response = self.client.get(
            reverse('infrastructure_field_view', args=[self.field.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_field_edit_out(self):
        "Testing /infrastructure/field/edit/<field_id>"
        response = self.client.get(
            reverse('infrastructure_field_edit', args=[self.field.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_field_del_out(self):
        "Testing /infrastructure/field/delete/<field_id>"
        response = self.client.get(
            reverse('infrastructure_field_delete', args=[self.field.id]))
        self.assertRedirects(response, reverse('user_login'))

    # Status
    def test_infrastructure_status_add_out(self):
        "Testing /infrastructure/status/add/"
        response = self.client.get(reverse('infrastructure_status_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_status_view_out(self):
        "Testing /infrastructure/status/view/<status_id>"
        response = self.client.get(
            reverse('infrastructure_status_view', args=[self.status.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_status_edit_out(self):
        "Testing /infrastructure/status/edit/<status_id>"
        response = self.client.get(
            reverse('infrastructure_status_edit', args=[self.status.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_status_del_out(self):
        "Testing /infrastructure/status/delete/<status_id>"
        response = self.client.get(
            reverse('infrastructure_status_delete', args=[self.status.id]))
        self.assertRedirects(response, reverse('user_login'))

    # Item
    def test_infrastructure_item_add_out(self):
        "Testing /infrastructure/item/add/"
        response = self.client.get(reverse('infrastructure_item_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infr_item_add_typed_out(self):
        "Testing /infrastructure/item/add/<type_id>"
        response = self.client.get(
            reverse('infrastructure_item_add_typed', args=[self.type.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_item_view_out(self):
        "Testing /infrastructure/item/view/<item_id>"
        response = self.client.get(
            reverse('infrastructure_item_view', args=[self.item.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_item_edit_out(self):
        "Testing /infrastructure/item/edit/<item_id>"
        response = self.client.get(
            reverse('infrastructure_item_edit', args=[self.item.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infrastructure_item_del_out(self):
        "Testing /infrastructure/item/delete/<item_id>"
        response = self.client.get(
            reverse('infrastructure_item_delete', args=[self.item.id]))
        self.assertRedirects(response, reverse('user_login'))

    # Service Record
    def test_infr_service_record_index_out(self):
        "Testing /infrastructure/service_record/index/"
        response = self.client.get(
            reverse('infrastructure_service_record_index'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infr_service_record_add_out(self):
        "Testing /infrastructure/service_record/add/"
        response = self.client.get(
            reverse('infrastructure_service_record_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_infr_service_record_view_out(self):
        "Testing /infrastructure/service_record/view/<service_record_id>"
        response = self.client.get(
            reverse('infrastructure_service_record_view', args=[self.servicing.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infr_service_record_edit_out(self):
        "Testing /infrastructure/service_record/edit/<service_record_id>"
        response = self.client.get(
            reverse('infrastructure_service_record_edit', args=[self.servicing.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_infr_service_record_delete_out(self):
        "Testing /infrastructure/service_record/delete/<service_record_id>"
        response = self.client.get(
            reverse('infrastructure_service_record_delete', args=[self.servicing.id]))
        self.assertRedirects(response, reverse('user_login'))