def test_model_item_type(self): "Test item type model" obj = ItemType(name='test') obj.save() self.assertEquals('test', obj.name) self.assertNotEquals(obj.id, None) obj.delete()
def type_add(request, response_format='html'): "ItemType add" if not request.user.profile.is_admin('anaf.infrastructure'): return user_denied(request, message="You don't have administrator access to the Infrastructure module", response_format=response_format) if request.POST: if 'cancel' not in request.POST: item_type = ItemType() form = ItemTypeForm( request.user.profile, request.POST, instance=item_type) if form.is_valid(): item = form.save(request) item_type.set_user_from_request(request) return HttpResponseRedirect(reverse('infrastructure_type_view', args=[item.id])) else: return HttpResponseRedirect(reverse('infrastructure_settings_view')) else: form = ItemTypeForm(request.user.profile) context = _get_default_context(request) context.update({'form': form}) return render_to_response('infrastructure/item_type_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 post_item_type(): if not request.is_json: abort(400, "The request payload is not in JSON format") else: try: data = request.get_json() if data["name"] is None: abort(422) else: item_type = ItemType(name=data["name"]) db.session.add(item_type) db.session.commit() return jsonify(item_type.serialize()) except Exception as e: return abort(e.code, e)
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()
def itemFromXML(item_idmap, itemel): if itemel.tag != 'item': raise ValueError(f"Got element '{itemel.tag}', expecting 'item'.") itemid = itemel.attrib['id'] if not _checkXMLHasNoText(itemel): raise ValueError(f"Invalid item {itemid}") if itemid in item_idmap: raise ValueError(f"Item {itemid} defined twice.") name = itemel.attrib.get('name', itemid) time = itemel.attrib.get('time', None) produced = itemel.attrib.get('produced', None) if (produced is None) != (time is None): raise ValueError(f"Invalid item '{itemid}'.") if time is not None: time = _F(time) produced = int(produced) ingredients = [] for ingredientel in itemel.getchildren(): if ingredientel.tag != 'ingredient': raise ValueError(f"Item {itemid} has {ingredientel.tag}") ingid = ingredientel.attrib['idref'] if not _checkXMLHasNoText(ingredientel): raise ValueError(f"Invalid ingredient '{ingid}' in '{itemid}'") ingcount = int(ingredientel.attrib['count']) if ingid not in item_idmap: raise ValueError(f"Item '{itemid}' mentions ingredient " f"'{ingid}' before it's defined.") ingredients.append((ingcount, item_idmap[ingid])) if (len(ingredients) > 0) and (time is None): raise ValueError(f"Item '{itemid}' has ingredients but " "no production time.") return (itemid, ItemType(name, time, tuple(ingredients), produced))
def item_type_save(): try: new_item_type = ItemType(**request.form) db.session.add(new_item_type) db.session.commit() except BaseException as error: return str(error), 400 return "success", 200
def create_item_type(): request_json = request.json name = request_json.get('name') try: item_type = ItemType(name=name) except: return '', HTTPStatus.CONFLICT db.session.add(item_type) db.session.commit() return jsonify(item_type), HTTPStatus.CREATED
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()
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'))
print(" </tr>") print(" <tbody>") for item in items: print(" <tr>") print(" <td>%s</td>" % item.item_id) print(" <td>%s</td>" % item.name) print(" <td>%s</td>" % item.description) print(" <td>%s</td>" % item.type_name) print(" <td>%s</td>" % item.cost) print(" </tr>") print(" </tbody>") print("</table>") print("<h2>Item Creation</h2>") print("<hr />") itemTypes = ItemType.GetAll() print('<form action="/cgi-bin/items.py" method="post">') print(' <div class="form-group row">') print(' <label class="col-sm-2 col-form-label">Name</label>') print(' <div class="col-sm-3">') print( ' <input type="text" name="name" class="form-control" placeholder="item name" required>' ) print(' </div>') print(' </div>') print(' <div class="form-group row">') print(' <label class="col-sm-2 col-form-label">Description</label>') print(' <div class="col-sm-3">') print( ' <input type="text" name="description" class="form-control" placeholder="item description" required>' )
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'))