text:
"""All tests for views."""

import os
import json
import urllib2

from django.core.urlresolvers import reverse
from django.http import HttpRequest
from django.template.loader import render_to_string
from django.test import TestCase, RequestFactory
from django.contrib.messages import get_messages
from django.contrib.messages.storage.fallback import FallbackStorage
from django.contrib.auth.models import AnonymousUser
from django.contrib.sites.shortcuts import get_current_site

from rest_framework.test import APIRequestFactory, force_authenticate

from geokey import version
from geokey.core.tests.helpers import render_helpers, image_helpers
from geokey.users.tests.model_factories import UserFactory
from geokey.projects.tests.model_factories import ProjectFactory

from .url_mocks import (
    ValidURLHTTPHandler,
    NoCORSHTTPHandler,
    InvalidURLHTTPHandler
)
from .model_factories import WebResourceFactory
from ..helpers.context_helpers import does_not_exist_msg
from ..base import STATUS, FORMAT
from ..models import WebResource
from ..forms import WebResourceForm
from ..views import (
    IndexPage,
    AllWebResourcesPage,
    AddWebResourcePage,
    SingleWebResourcePage,
    RemoveWebResourcePage,
    ReorderWebResourcesAjax,
    UpdateWebResourceAjax,
    AllWebResourcesAPI,
    SingleWebResourceAPI
)

no_rights_to_access_msg = 'You are not member of the administrators group ' \
                          'of this project and therefore not allowed to ' \
                          'alter the settings of the project'

# ###########################
# TESTS FOR ADMIN PAGES
# ###########################

class IndexPageTest(TestCase):
    """Test index page."""

    def setUp(self):
        """Set up test."""
        self.request = HttpRequest()
        self.request.method = 'GET'
        self.view = IndexPage.as_view()
        self.filters = {
            'without-web-resources-only': 'Without web resources',
            'with-web-resources-only': 'With web resources'
        }

        self.user = UserFactory.create()

        self.project_1 = ProjectFactory.create(add_admins=[self.user])
        self.project_2 = ProjectFactory.create(add_admins=[self.user])
        self.project_3 = ProjectFactory.create(add_admins=[self.user])
        self.project_4 = ProjectFactory.create(add_contributors=[self.user])
        self.project_5 = ProjectFactory.create()
        WebResourceFactory.create(project=self.project_2)
        WebResourceFactory.create(project=self.project_4)

        wr_to_delete = WebResourceFactory.create(project=self.project_3)
        wr_to_delete.delete()

        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages)

    def test_get_with_anonymous(self):
        """
        Test GET with with anonymous.

        It should redirect to login page.
        """
        self.request.user = AnonymousUser()
        response = self.view(self.request)

        self.assertEqual(response.status_code, 302)
        self.assertIn('/admin/account/login/', response['location'])

    def test_get_with_user(self):
        """
        Test GET with with user.

        It should render the page with all projects, where user is an
        administrator.
        """
        projects = [self.project_1, self.project_2, self.project_3]

        self.request.user = self.user
        response = self.view(self.request).render()

        rendered = render_to_string(
            'wr_index.html',
            {
                'PLATFORM_NAME': get_current_site(self.request).name,
                'GEOKEY_VERSION': version.get_version(),
                'user': self.request.user,
                'messages': get_messages(self.request),
                'filters': self.filters,
                'projects': projects
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_get_with_user_only_without_web_resources(self):
        """
        Test GET with with user, but only projects without web resources.

        It should render the page with all projects, where user is an
        administrator. Those projects must also not have web resources.
        """
        projects = [self.project_1, self.project_3]

        self.request.user = self.user
        self.request.GET['filter'] = 'without-web-resources-only'
        response = self.view(self.request).render()

        rendered = render_to_string(
            'wr_index.html',
            {
                'PLATFORM_NAME': get_current_site(self.request).name,
                'GEOKEY_VERSION': version.get_version(),
                'user': self.request.user,
                'messages': get_messages(self.request),
                'filters': self.filters,
                'projects': projects,
                'request': {
                    'GET': {
                        'filter': self.request.GET.get('filter')
                    }
                }
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_get_with_user_only_with_web_resources(self):
        """
        Test GET with with user, but only projects with web resources.

        It should render the page with all projects, where user is an
        administrator. Those projects must also have web resources.
        """
        projects = [self.project_2]

        self.request.user = self.user
        self.request.GET['filter'] = 'with-web-resources-only'
        response = self.view(self.request).render()

        rendered = render_to_string(
            'wr_index.html',
            {
                'PLATFORM_NAME': get_current_site(self.request).name,
                'GEOKEY_VERSION': version.get_version(),
                'user': self.request.user,
                'messages': get_messages(self.request),
                'filters': self.filters,
                'projects': projects,
                'request': {
                    'GET': {
                        'filter': self.request.GET.get('filter')
                    }
                }
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

class AllWebResourcesPageTest(TestCase):
    """Test all web resources page."""

    def setUp(self):
        """Set up test."""
        self.request = HttpRequest()
        self.request.method = 'GET'
        self.view = AllWebResourcesPage.as_view()

        self.user = UserFactory.create()
        self.contributor = UserFactory.create()
        self.admin = UserFactory.create()

        self.project = ProjectFactory.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )

        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages)

    def test_get_with_anonymous(self):
        """
        Test GET with with anonymous.

        It should redirect to login page.
        """
        self.request.user = AnonymousUser()
        response = self.view(self.request, project_id=self.project.id)

        self.assertEqual(response.status_code, 302)
        self.assertIn('/admin/account/login/', response['location'])

    def test_get_with_user(self):
        """
        Test GET with with user.

        It should not allow to access the page, when user is not an
        administrator.
        """
        self.request.user = self.user
        response = self.view(self.request, project_id=self.project.id).render()

        rendered = render_to_string(
            'wr_all_webresources.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Project')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_get_with_contributor(self):
        """
        Test GET with with contributor.

        It should not allow to access the page, when user is not an
        administrator.
        """
        self.request.user = self.contributor
        response = self.view(self.request, project_id=self.project.id).render()

        rendered = render_to_string(
            'wr_all_webresources.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'error': 'Permission denied.',
                'error_description': no_rights_to_access_msg
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_get_with_admin(self):
        """
        Test GET with with admin.

        It should render the page with a project.
        """
        self.request.user = self.admin
        response = self.view(self.request, project_id=self.project.id).render()

        rendered = render_to_string(
            'wr_all_webresources.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'project': self.project
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_get_when_no_project(self):
        """
        Test GET with with admin, when project does not exist.

        It should inform user that project does not exist.
        """
        self.request.user = self.admin
        response = self.view(
            self.request,
            project_id=self.project.id + 123
        ).render()

        rendered = render_to_string(
            'wr_all_webresources.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Project')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

class AddWebResourcePageTest(TestCase):
    """Test add web resource page."""

    def setUp(self):
        """Set up test."""
        self.factory = RequestFactory()
        self.request = HttpRequest()
        self.view = AddWebResourcePage.as_view()

        self.user = UserFactory.create()
        self.contributor = UserFactory.create()
        self.admin = UserFactory.create()

        self.project = ProjectFactory.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )

        self.data = {
            'name': 'Test Web Resource',
            'description': '',
            'url': 'http://source.org.uk/test.json',
            'colour': '#000000',
            'symbol': image_helpers.get_image(file_name='test_symbol.png')
        }
        self.url = reverse('geokey_webresources:webresource_add', kwargs={
            'project_id': self.project.id
        })

        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages)

    def tearDown(self):
        """Tear down test."""
        for webresource in WebResource.objects.all():
            if webresource.symbol:
                webresource.symbol.delete()

    def test_get_with_anonymous(self):
        """
        Test GET with with anonymous.

        It should redirect to login page.
        """
        self.request.user = AnonymousUser()
        self.request.method = 'GET'
        response = self.view(self.request, project_id=self.project.id)

        self.assertEqual(response.status_code, 302)
        self.assertIn('/admin/account/login/', response['location'])

    def test_get_with_user(self):
        """
        Test GET with with user.

        It should not allow to access the page, when user is not an
        administrator.
        """
        self.request.user = self.user
        self.request.method = 'GET'
        response = self.view(self.request, project_id=self.project.id).render()

        form = WebResourceForm()
        rendered = render_to_string(
            'wr_add_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'form': form,
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Project')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_get_with_contributor(self):
        """
        Test GET with with contributor.

        It should not allow to access the page, when user is not an
        administrator.
        """
        self.request.user = self.contributor
        self.request.method = 'GET'
        response = self.view(self.request, project_id=self.project.id).render()

        form = WebResourceForm()
        rendered = render_to_string(
            'wr_add_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'form': form,
                'error': 'Permission denied.',
                'error_description': no_rights_to_access_msg
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_get_with_admin(self):
        """
        Test GET with with admin.

        It should render the page with a project.
        """
        self.request.user = self.admin
        self.request.method = 'GET'
        response = self.view(self.request, project_id=self.project.id).render()

        form = WebResourceForm()
        rendered = render_to_string(
            'wr_add_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'form': form,
                'project': self.project
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_get_when_no_project(self):
        """
        Test GET with with admin, when project does not exist.

        It should inform user that project does not exist.
        """
        self.request.user = self.admin
        self.request.method = 'GET'
        response = self.view(
            self.request,
            project_id=self.project.id + 123
        ).render()

        form = WebResourceForm()
        rendered = render_to_string(
            'wr_add_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'form': form,
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Project'),
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_post_with_anonymous(self):
        """
        Test POST with with anonymous.

        It should redirect to login page.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = AnonymousUser()

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(request, project_id=self.project.id)

        self.assertEqual(response.status_code, 302)
        self.assertIn('/admin/account/login/', response['location'])

    def test_post_with_user(self):
        """
        Test POST with with user.

        It should not allow to add new web resources, when user is not an
        administrator.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = self.user

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(request, project_id=self.project.id).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_add_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Project')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )
        self.assertEqual(WebResource.objects.count(), 0)

    def test_post_with_contributor(self):
        """
        Test POST with with contributor.

        It should not allow to add new web resources, when user is not an
        administrator.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = self.contributor

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(request, project_id=self.project.id).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_add_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'error': 'Permission denied.',
                'error_description': no_rights_to_access_msg
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )
        self.assertEqual(WebResource.objects.count(), 0)

    def test_post_with_admin_geojson(self):
        """
        Test POST with with admin (GeoJSON).

        It should add new web resource, when user is an administrator.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        self.data['url'] = 'http://source.org.uk/test.json'
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(request, project_id=self.project.id)

        self.assertEqual(response.status_code, 302)
        self.assertIn(
            reverse(
                'geokey_webresources:all_webresources',
                kwargs={
                    'project_id': self.project.id
                }
            ),
            response['location']
        )
        self.assertEqual(WebResource.objects.count(), 1)
        self.assertEqual(
            WebResource.objects.latest('id').dataformat,
            FORMAT.GeoJSON
        )

    def test_post_with_admin_kml(self):
        """
        Test POST with with admin (KML).

        It should add new web resource, when user is an administrator.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        self.data['url'] = 'http://source.org.uk/test.kml'
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(request, project_id=self.project.id)

        self.assertEqual(response.status_code, 302)
        self.assertIn(
            reverse(
                'geokey_webresources:all_webresources',
                kwargs={
                    'project_id': self.project.id
                }
            ),
            response['location']
        )
        self.assertEqual(WebResource.objects.count(), 1)
        self.assertEqual(
            WebResource.objects.latest('id').dataformat,
            FORMAT.KML
        )

    def test_post_when_invalid_format(self):
        """
        Test POST with with admin, when format is invalid.

        It should add new web resource, when user is an administrator.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        self.data['url'] = 'http://source.org.uk/test.png'
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(request, project_id=self.project.id).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_add_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'project': self.project
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )
        self.assertEqual(WebResource.objects.count(), 0)

    def test_post_when_wrong_data(self):
        """
        Test POST with with admin, when data is wrong.

        It should inform user that data is wrong.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        self.data['url'] = 'some web address'
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(request, project_id=self.project.id).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_add_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'project': self.project
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )
        self.assertEqual(WebResource.objects.count(), 0)

    def test_post_when_no_cors_support(self):
        """
        Test POST with with admin, when server has no CORS enabled.

        It should inform user that server has no CORS enabled.
        """
        urllib2.install_opener(urllib2.build_opener(NoCORSHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(request, project_id=self.project.id).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_add_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'project': self.project
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )
        self.assertEqual(WebResource.objects.count(), 0)

    def test_post_when_invalid_url(self):
        """
        Test POST with with admin, when URL is invalid.

        It should inform user that URL is invalid.
        """
        urllib2.install_opener(urllib2.build_opener(InvalidURLHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(request, project_id=self.project.id).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_add_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'project': self.project
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )
        self.assertEqual(WebResource.objects.count(), 0)

    def test_post_when_no_project(self):
        """
        Test POST with with admin, when project does not exist.

        It should inform user that project does not exist.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id + 123
        ).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_add_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Project')
            }
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )
        self.assertEqual(WebResource.objects.count(), 0)

    def test_post_when_project_is_locked(self):
        """
        Test POST with with admin, when project is locked.

        It should inform user that the project is locked.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        self.project.islocked = True
        self.project.save()

        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(request, project_id=self.project.id).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_add_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'project': self.project
            }
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )
        self.assertEqual(WebResource.objects.count(), 0)

class SingleWebResourcePageTest(TestCase):
    """Test single web resource page."""

    def setUp(self):
        """Set up test."""
        self.factory = RequestFactory()
        self.request = HttpRequest()
        self.view = SingleWebResourcePage.as_view()

        self.user = UserFactory.create()
        self.contributor = UserFactory.create()
        self.admin = UserFactory.create()

        self.project = ProjectFactory.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )
        self.webresource = WebResourceFactory.create(project=self.project)

        self.data = {
            'name': self.webresource.name,
            'description': self.webresource.description,
            'url': 'http://big-data.org.uk/test.kml',
            'colour': '#000000',
            'symbol': image_helpers.get_image(file_name='test_symbol.png'),
            'symbol_clear': 'false'
        }
        self.url = reverse(
            'geokey_webresources:single_webresource',
            kwargs={
                'project_id': self.project.id,
                'webresource_id': self.webresource.id
            }
        )

        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages)

    def tearDown(self):
        """Tear down test."""
        for webresource in WebResource.objects.all():
            if webresource.symbol:
                webresource.symbol.delete()

    def test_get_with_anonymous(self):
        """
        Test GET with with anonymous.

        It should redirect to login page.
        """
        self.request.user = AnonymousUser()
        self.request.method = 'GET'
        response = self.view(
            self.request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        )

        self.assertEqual(response.status_code, 302)
        self.assertIn('/admin/account/login/', response['location'])

    def test_get_with_user(self):
        """
        Test GET with with user.

        It should not allow to access the page, when user is not an
        administrator.
        """
        self.request.user = self.user
        self.request.method = 'GET'
        response = self.view(
            self.request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

        form = WebResourceForm()
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'form': form,
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Web resource')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_get_with_contributor(self):
        """
        Test GET with with contributor.

        It should not allow to access the page, when user is not an
        administrator.
        """
        self.request.user = self.contributor
        self.request.method = 'GET'
        response = self.view(
            self.request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

        form = WebResourceForm()
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'form': form,
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Web resource')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_get_with_admin(self):
        """
        Test GET with with admin.

        It should render the page with a project and web resource.
        """
        self.request.user = self.admin
        self.request.method = 'GET'
        response = self.view(
            self.request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

        form = WebResourceForm()
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'form': form,
                'status_types': STATUS,
                'project': self.project,
                'webresource': self.webresource
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_get_when_no_project(self):
        """
        Test GET with with admin, when project does not exist.

        It should inform user that web resource does not exist.
        """
        self.request.user = self.admin
        self.request.method = 'GET'
        response = self.view(
            self.request,
            project_id=self.project.id + 123,
            webresource_id=self.webresource.id
        ).render()

        form = WebResourceForm()
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'form': form,
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Web resource')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_get_when_no_webresource(self):
        """
        Test GET with with admin, when web resource does not exist.

        It should inform user that web resource does not exist.
        """
        self.request.user = self.admin
        self.request.method = 'GET'
        response = self.view(
            self.request,
            project_id=self.project.id,
            webresource_id=self.webresource.id + 123
        ).render()

        form = WebResourceForm()
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'form': form,
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Web resource')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

    def test_post_with_anonymous(self):
        """
        Test POST with with anonymous.

        It should redirect to login page.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = AnonymousUser()

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        )

        self.assertEqual(response.status_code, 302)
        self.assertIn('/admin/account/login/', response['location'])

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.webresource.name)
        self.assertEqual(reference.description, self.webresource.description)
        self.assertEqual(reference.dataformat, self.webresource.dataformat)
        self.assertEqual(reference.url, self.webresource.url)
        self.assertEqual(reference.colour, self.webresource.colour)
        self.assertFalse(bool(reference.symbol))

    def test_post_with_user(self):
        """
        Test POST with with user.

        It should not allow to update web resources, when user is not an
        administrator.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = self.user

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Web resource')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.webresource.name)
        self.assertEqual(reference.description, self.webresource.description)
        self.assertEqual(reference.dataformat, self.webresource.dataformat)
        self.assertEqual(reference.url, self.webresource.url)
        self.assertEqual(reference.colour, self.webresource.colour)
        self.assertFalse(bool(reference.symbol))

    def test_post_with_contributor(self):
        """
        Test POST with with contributor.

        It should not allow to update web resources, when user is not an
        administrator.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = self.contributor

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Web resource')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.webresource.name)
        self.assertEqual(reference.description, self.webresource.description)
        self.assertEqual(reference.dataformat, self.webresource.dataformat)
        self.assertEqual(reference.url, self.webresource.url)
        self.assertEqual(reference.colour, self.webresource.colour)
        self.assertFalse(bool(reference.symbol))

    def test_post_with_admin_geojson(self):
        """
        Test POST with with admin (GeoJSON).

        It should update web resource, when user is an administrator.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        self.data['url'] = 'http://source.org.uk/test.json'
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        )

        self.assertEqual(response.status_code, 302)
        self.assertIn(
            reverse(
                'geokey_webresources:all_webresources',
                kwargs={
                    'project_id': self.project.id
                }
            ),
            response['location']
        )

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.data.get('name'))
        self.assertEqual(reference.description, self.data.get('description'))
        self.assertEqual(reference.dataformat, FORMAT.GeoJSON)
        self.assertEqual(reference.url, self.data.get('url'))
        self.assertEqual(reference.colour, self.data.get('colour'))
        self.assertTrue(bool(reference.symbol))

    def test_post_with_admin_kml(self):
        """
        Test POST with with admin (KML).

        It should update web resource, when user is an administrator.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        self.data['url'] = 'http://source.org.uk/test.kml'
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        )

        self.assertEqual(response.status_code, 302)
        self.assertIn(
            reverse(
                'geokey_webresources:all_webresources',
                kwargs={
                    'project_id': self.project.id
                }
            ),
            response['location']
        )

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.data.get('name'))
        self.assertEqual(reference.description, self.data.get('description'))
        self.assertEqual(reference.dataformat, FORMAT.KML)
        self.assertEqual(reference.url, self.data.get('url'))
        self.assertEqual(reference.colour, self.data.get('colour'))
        self.assertTrue(bool(reference.symbol))

    def test_post_when_invalid_format(self):
        """
        Test POST with with admin, when format is invalid.

        It should inform user that URL is invalid.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        self.data['url'] = 'http://source.org.uk/test.png'
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'status_types': STATUS,
                'project': self.project,
                'webresource': self.webresource
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.webresource.name)
        self.assertEqual(reference.description, self.webresource.description)
        self.assertEqual(reference.dataformat, self.webresource.dataformat)
        self.assertEqual(reference.url, self.webresource.url)
        self.assertEqual(reference.colour, self.webresource.colour)
        self.assertFalse(bool(reference.symbol))

    def test_post_when_clearing_symbol(self):
        """
        Test POST with with admin, when clearing symbol.

        It should clear symbol from web resource.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        self.webresource.symbol = image_helpers.get_image(
            file_name='test_symbol.png'
        )
        self.webresource.save()

        symbol = self.webresource.symbol.path

        self.data['symbol_clear'] = 'true'
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        )

        self.assertEqual(response.status_code, 302)
        self.assertIn(
            reverse(
                'geokey_webresources:all_webresources',
                kwargs={
                    'project_id': self.project.id
                }
            ),
            response['location']
        )

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.data.get('name'))
        self.assertEqual(reference.description, self.data.get('description'))
        self.assertEqual(reference.url, self.data.get('url'))
        self.assertEqual(reference.colour, self.data.get('colour'))
        self.assertFalse(bool(reference.symbol))

        os.remove(symbol)

    def test_post_when_wrong_data(self):
        """
        Test POST with with admin, when data is wrong.

        It should inform user that data is wrong.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        self.data['name'] = ''
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'status_types': STATUS,
                'project': self.project,
                'webresource': self.webresource
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.webresource.name)
        self.assertEqual(reference.description, self.webresource.description)
        self.assertEqual(reference.dataformat, self.webresource.dataformat)
        self.assertEqual(reference.url, self.webresource.url)
        self.assertEqual(reference.colour, self.webresource.colour)
        self.assertFalse(bool(reference.symbol))

    def test_post_when_no_cors_support(self):
        """
        Test POST with with admin, when server has no CORS enabled.

        It should inform user that server has no CORS enabled.
        """
        urllib2.install_opener(urllib2.build_opener(NoCORSHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'status_types': STATUS,
                'project': self.project,
                'webresource': self.webresource
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.webresource.name)
        self.assertEqual(reference.description, self.webresource.description)
        self.assertEqual(reference.dataformat, self.webresource.dataformat)
        self.assertEqual(reference.url, self.webresource.url)
        self.assertEqual(reference.colour, self.webresource.colour)
        self.assertFalse(bool(reference.symbol))

    def test_post_when_invalid_url(self):
        """
        Test POST with with admin, when URL is invalid.

        It should inform user that URL is invalid.
        """
        urllib2.install_opener(urllib2.build_opener(InvalidURLHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'status_types': STATUS,
                'project': self.project,
                'webresource': self.webresource
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.webresource.name)
        self.assertEqual(reference.description, self.webresource.description)
        self.assertEqual(reference.dataformat, self.webresource.dataformat)
        self.assertEqual(reference.url, self.webresource.url)
        self.assertEqual(reference.colour, self.webresource.colour)
        self.assertFalse(bool(reference.symbol))

    def test_post_when_no_project(self):
        """
        Test POST with with admin, when project does not exist.

        It should inform user that web resource does not exist.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id + 123,
            webresource_id=self.webresource.id
        ).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Web resource')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.webresource.name)
        self.assertEqual(reference.description, self.webresource.description)
        self.assertEqual(reference.dataformat, self.webresource.dataformat)
        self.assertEqual(reference.url, self.webresource.url)
        self.assertEqual(reference.colour, self.webresource.colour)
        self.assertFalse(bool(reference.symbol))

    def test_post_when_no_webresource(self):
        """
        Test POST with with admin, when web resource does not exist.

        It should inform user that web resource does not exist.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id + 123
        ).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Web resource')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.webresource.name)
        self.assertEqual(reference.description, self.webresource.description)
        self.assertEqual(reference.dataformat, self.webresource.dataformat)
        self.assertEqual(reference.url, self.webresource.url)
        self.assertEqual(reference.colour, self.webresource.colour)
        self.assertFalse(bool(reference.symbol))

    def test_post_when_project_is_locked(self):
        """
        Test POST with with admin, when project is locked.

        It should inform user that the project is locked.
        """
        urllib2.install_opener(urllib2.build_opener(ValidURLHTTPHandler))
        self.project.islocked = True
        self.project.save()

        request = self.factory.post(self.url, self.data)
        request.user = self.admin

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

        form = WebResourceForm(data=self.data)
        rendered = render_to_string(
            'wr_single_webresource.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(request).name,
                'user': request.user,
                'messages': get_messages(request),
                'form': form,
                'status_types': STATUS,
                'project': self.project,
                'webresource': self.webresource
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )

        reference = WebResource.objects.get(pk=self.webresource.id)
        self.assertEqual(reference.name, self.webresource.name)
        self.assertEqual(reference.description, self.webresource.description)
        self.assertEqual(reference.dataformat, self.webresource.dataformat)
        self.assertEqual(reference.url, self.webresource.url)
        self.assertEqual(reference.colour, self.webresource.colour)
        self.assertFalse(bool(reference.symbol))

class RemoveWebResourcePageTest(TestCase):
    """Test remove web resource page."""

    def setUp(self):
        """Set up test."""
        self.request = HttpRequest()
        self.request.method = 'GET'
        self.view = RemoveWebResourcePage.as_view()

        self.user = UserFactory.create()
        self.contributor = UserFactory.create()
        self.admin = UserFactory.create()

        self.project = ProjectFactory.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )
        self.webresource = WebResourceFactory.create(project=self.project)

        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages)

    def test_get_with_anonymous(self):
        """
        Test GET with with anonymous.

        It should redirect to login page.
        """
        self.request.user = AnonymousUser()
        response = self.view(
            self.request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        )

        self.assertEqual(response.status_code, 302)
        self.assertIn('/admin/account/login/', response['location'])

    def test_get_with_user(self):
        """
        Test GET with with user.

        It should not allow to access the page, when user is not an
        administrator.
        """
        self.request.user = self.user
        response = self.view(
            self.request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

        rendered = render_to_string(
            'base.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Web resource')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )
        self.assertEqual(WebResource.objects.count(), 1)

    def test_get_with_contributor(self):
        """
        Test GET with with contributor.

        It should not allow to access the page, when user is not an
        administrator.
        """
        self.request.user = self.contributor
        response = self.view(
            self.request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

        rendered = render_to_string(
            'base.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Web resource')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )
        self.assertEqual(WebResource.objects.count(), 1)

    def test_get_with_admin(self):
        """
        Test GET with with admin.

        It should remove web resource and redirect to all web resources of a
        project.
        """
        self.request.user = self.admin
        response = self.view(
            self.request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        )

        self.assertEqual(response.status_code, 302)
        self.assertIn(
            reverse(
                'geokey_webresources:all_webresources',
                kwargs={'project_id': self.project.id}
            ),
            response['location']
        )
        self.assertEqual(WebResource.objects.count(), 0)

    def test_get_when_no_project(self):
        """
        Test GET with with admin, when project does not exist.

        It should inform user that web resource does not exist.
        """
        self.request.user = self.admin
        response = self.view(
            self.request,
            project_id=self.project.id + 123,
            webresource_id=self.webresource.id
        ).render()

        rendered = render_to_string(
            'base.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Web resource')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )
        self.assertEqual(WebResource.objects.count(), 1)

    def test_get_when_no_webresource(self):
        """
        Test GET with with admin, when web resource does not exist.

        It should inform user that web resource does not exist.
        """
        self.request.user = self.admin
        response = self.view(
            self.request,
            project_id=self.project.id,
            webresource_id=self.webresource.id + 123
        ).render()

        rendered = render_to_string(
            'base.html',
            {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.request.user,
                'messages': get_messages(self.request),
                'error': 'Not found.',
                'error_description': does_not_exist_msg('Web resource')
            }
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            render_helpers.remove_csrf(response.content.decode('utf-8')),
            rendered
        )
        self.assertEqual(WebResource.objects.count(), 1)

    def test_get_when_project_is_locked(self):
        """
        Test GET with with admin, when project is locked.

        It should inform user that the project is locked and redirect the to
        same web resource.
        """
        self.project.islocked = True
        self.project.save()

        self.request.user = self.admin
        response = self.view(
            self.request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        )

        self.assertEqual(response.status_code, 302)
        self.assertIn(
            reverse(
                'geokey_webresources:single_webresource',
                kwargs={
                    'project_id': self.project.id,
                    'webresource_id': self.webresource.id
                }
            ),
            response['location']
        )
        self.assertEqual(WebResource.objects.count(), 1)

# ###########################
# TESTS FOR ADMIN AJAX
# ###########################

class ReorderWebResourcesAjaxTest(TestCase):
    """Test reorder web resources via Ajax."""

    def setUp(self):
        """Set up test."""
        self.factory = APIRequestFactory()
        self.view = ReorderWebResourcesAjax.as_view()

        self.user = UserFactory.create()
        self.contributor = UserFactory.create()
        self.admin = UserFactory.create()

        self.project = ProjectFactory.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )
        self.webresource_1 = WebResourceFactory.create(project=self.project)
        self.webresource_2 = WebResourceFactory.create(project=self.project)

        self.url = reverse(
            'geokey_webresources:ajax_webresources_reorder',
            kwargs={
                'project_id': self.project.id
            }
        )

    def _post(self, data, user):
        """Make test POST method."""
        request = self.factory.post(
            self.url,
            data,
            content_type='application/json'
        )
        force_authenticate(request, user=user)

        return self.view(
            request,
            project_id=self.project.id
        ).render()

    def test_post_with_anonymous(self):
        """
        Test POST with with anonymous.

        It should return 404 response.
        """
        response = self._post(
            json.dumps({
                'order': [
                    self.webresource_2.id,
                    self.webresource_1.id
                ]
            }),
            AnonymousUser()
        )
        self.assertEqual(response.status_code, 404)

        reference = self.project.webresources.all()
        self.assertEqual(reference[0].order, 0)
        self.assertEqual(reference[1].order, 0)

    def test_post_with_user(self):
        """
        Test POST with with user.

        It should return 404 response.
        """
        response = self._post(
            json.dumps({
                'order': [
                    self.webresource_2.id,
                    self.webresource_1.id
                ]
            }),
            self.user
        )
        self.assertEqual(response.status_code, 404)

        reference = self.project.webresources.all()
        self.assertEqual(reference[0].order, 0)
        self.assertEqual(reference[1].order, 0)

    def test_post_with_contributor(self):
        """
        Test POST with with contributor.

        It should return 403 response.
        """
        response = self._post(
            json.dumps({
                'order': [
                    self.webresource_2.id,
                    self.webresource_1.id
                ]
            }),
            self.contributor
        )
        self.assertEqual(response.status_code, 403)

        reference = self.project.webresources.all()
        self.assertEqual(reference[0].order, 0)
        self.assertEqual(reference[1].order, 0)

    def test_post_with_admin(self):
        """
        Test POST with with admin.

        It should return 200 response.
        """
        response = self._post(
            json.dumps({
                'order': [
                    self.webresource_2.id,
                    self.webresource_1.id
                ]
            }),
            self.admin
        )
        self.assertEqual(response.status_code, 200)

        reference = self.project.webresources.all()
        self.assertEqual(reference[0], self.webresource_2)
        self.assertEqual(reference[1], self.webresource_1)

    def test_post_when_wrong_webresource_id(self):
        """
        Test POST with with admin, when web resource ID is wrong.

        It should return 400 response.
        """
        response = self._post(
            json.dumps({
                'order': [
                    self.webresource_2.id,
                    self.webresource_1.id + 123
                ]
            }),
            self.admin
        )
        self.assertEqual(response.status_code, 400)

        reference = self.project.webresources.all()
        self.assertEqual(reference[0].order, 0)
        self.assertEqual(reference[1].order, 0)

    def test_post_when_no_project(self):
        """
        Test POST with with admin, when project does not exist.

        It should return 404 response.
        """
        self.project.delete()

        response = self._post(
            json.dumps({
                'order': [
                    self.webresource_2.id,
                    self.webresource_1.id
                ]
            }),
            self.admin
        )
        self.assertEqual(response.status_code, 404)

    def test_post_when_no_webresources(self):
        """
        Test POST with with admin, when project has no web resources.

        It should return 404 response.
        """
        self.webresource_1.delete()
        self.webresource_2.delete()

        response = self._post(
            json.dumps({
                'order': [
                    self.webresource_2.id,
                    self.webresource_1.id
                ]
            }),
            self.admin
        )
        self.assertEqual(response.status_code, 404)

    def test_post_when_project_is_locked(self):
        """
        Test POST with with admin, when project is locked.

        It should return 403 response.
        """
        self.project.islocked = True
        self.project.save()

        response = self._post(
            json.dumps({
                'order': [
                    self.webresource_2.id,
                    self.webresource_1.id
                ]
            }),
            self.admin
        )
        self.assertEqual(response.status_code, 403)

        reference = self.project.webresources.all()
        self.assertEqual(reference[0].order, 0)
        self.assertEqual(reference[1].order, 0)

class UpdateWebResourceAjaxTest(TestCase):
    """Test update web resource via Ajax."""

    def setUp(self):
        """Set up test."""
        self.factory = APIRequestFactory()
        self.view = UpdateWebResourceAjax.as_view()

        self.user = UserFactory.create()
        self.contributor = UserFactory.create()
        self.admin = UserFactory.create()

        self.project = ProjectFactory.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )
        self.webresource = WebResourceFactory.create(
            status=STATUS.active,
            project=self.project
        )

        self.url = reverse(
            'geokey_webresources:ajax_webresource_update',
            kwargs={
                'project_id': self.project.id,
                'webresource_id': self.webresource.id
            }
        )

    def _put(self, data, user):
        """Make test PUT method."""
        request = self.factory.put(self.url, data)
        force_authenticate(request, user=user)

        return self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

    def test_put_with_anonymous(self):
        """
        Test PUT with with anonymous.

        It should return 404 response.
        """
        response = self._put(
            {'status': 'inactive'},
            AnonymousUser()
        )
        self.assertEqual(response.status_code, 404)
        self.assertEqual(
            WebResource.objects.get(pk=self.webresource.id).status,
            self.webresource.status
        )

    def test_put_with_user(self):
        """
        Test PUT with with user.

        It should return 404 response.
        """
        response = self._put(
            {'status': 'inactive'},
            self.user
        )
        self.assertEqual(response.status_code, 404)
        self.assertEqual(
            WebResource.objects.get(pk=self.webresource.id).status,
            self.webresource.status
        )

    def test_put_with_contributor(self):
        """
        Test PUT with with contributor.

        It should return 403 response.
        """
        response = self._put(
            {'status': 'inactive'},
            self.contributor
        )
        self.assertEqual(response.status_code, 403)
        self.assertEqual(
            WebResource.objects.get(pk=self.webresource.id).status,
            self.webresource.status
        )

    def test_put_with_admin(self):
        """
        Test PUT with with admin.

        It should return 200 response.
        """
        response = self._put(
            {'status': 'inactive'},
            self.admin
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            WebResource.objects.get(pk=self.webresource.id).status,
            STATUS.inactive
        )

    def test_put_when_wrong_status(self):
        """
        Test PUT with with admin, when status is wrong.

        It should return 400 response.
        """
        response = self._put(
            {'status': 'wrong'},
            self.admin
        )
        self.assertEqual(response.status_code, 400)
        self.assertEqual(
            WebResource.objects.get(pk=self.webresource.id).status,
            self.webresource.status
        )

    def test_put_when_no_project(self):
        """
        Test PUT with with admin, when project does not exist.

        It should return 404 response.
        """
        self.project.delete()

        response = self._put(
            {'status': 'inactive'},
            self.admin
        )
        self.assertEqual(response.status_code, 404)

    def test_put_when_no_webresource(self):
        """
        Test PUT with with admin, when web resource does not exist.

        It should return 404 response.
        """
        self.webresource.delete()

        response = self._put(
            {'status': 'inactive'},
            self.admin
        )
        self.assertEqual(response.status_code, 404)

    def test_put_when_project_is_locked(self):
        """
        Test PUT with with admin, when project is locked.

        It should return 403 response.
        """
        self.project.islocked = True
        self.project.save()

        response = self._put(
            {'status': 'inactive'},
            self.admin
        )
        self.assertEqual(response.status_code, 403)
        self.assertEqual(
            WebResource.objects.get(pk=self.webresource.id).status,
            self.webresource.status
        )

# ###########################
# TESTS FOR PUBLIC API
# ###########################

class AllWebResourcesAPITest(TestCase):
    """Test all web resources via API."""

    def setUp(self):
        """Set up test."""
        self.factory = APIRequestFactory()
        self.view = AllWebResourcesAPI.as_view()

        self.user = UserFactory.create()
        self.contributor = UserFactory.create()
        self.admin = UserFactory.create()

        self.project = ProjectFactory.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )
        self.webresource_1 = WebResourceFactory.create(
            status=STATUS.active,
            project=self.project
        )
        self.webresource_2 = WebResourceFactory.create(
            status=STATUS.inactive,
            project=self.project
        )

        self.url = reverse(
            'geokey_webresources:api_all_webresources',
            kwargs={
                'project_id': self.project.id
            }
        )

    def _get(self, user):
        """Make test GET method."""
        request = self.factory.get(self.url)
        force_authenticate(request, user=user)

        return self.view(
            request,
            project_id=self.project.id
        ).render()

    def test_get_with_user(self):
        """
        Test GET with with user.

        Project is private and not everyone can contribute to it by default.

        It should return 404 response.
        """
        response = self._get(self.user)
        self.assertEqual(response.status_code, 404)

    def test_get_with_contributor(self):
        """
        Test GET with with contributor.

        Contributors can access active web resources, but only active web
        resources should be included.

        It should return 200 response.
        """
        response = self._get(self.contributor)
        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content)
        self.assertEqual(len(content), 1)
        self.assertEqual(content[0]['id'], self.webresource_1.id)

    def test_get_with_admin(self):
        """
        Test GET with with admin.

        Admins can access active web resources, but only active web resources
        should be included.

        It should return 200 response.
        """
        response = self._get(self.admin)
        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content)
        self.assertEqual(len(content), 1)
        self.assertEqual(content[0]['id'], self.webresource_1.id)

    def test_get_when_no_webresources(self):
        """
        Test GET with contributor and admin.

        Even when there are no web resources, an empty array should be still
        returned.

        It should return 200 response.
        """
        self.webresource_1.delete()
        self.webresource_2.delete()

        response = self._get(self.contributor)
        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content)
        self.assertEqual(len(content), 0)

        response = self._get(self.admin)
        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content)
        self.assertEqual(len(content), 0)

class SingleWebResourceAPITest(TestCase):
    """Test single web resource via API."""

    def setUp(self):
        """Set up test."""
        self.factory = APIRequestFactory()
        self.view = SingleWebResourceAPI.as_view()

        self.user = UserFactory.create()
        self.contributor = UserFactory.create()
        self.admin = UserFactory.create()

        self.project = ProjectFactory.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )
        self.webresource = WebResourceFactory.create(
            status=STATUS.active,
            project=self.project
        )

        self.url = reverse(
            'geokey_webresources:api_single_webresource',
            kwargs={
                'project_id': self.project.id,
                'webresource_id': self.webresource.id
            }
        )

    def _get(self, user):
        """Make test GET method."""
        request = self.factory.get(self.url)
        force_authenticate(request, user=user)

        return self.view(
            request,
            project_id=self.project.id,
            webresource_id=self.webresource.id
        ).render()

    def test_get_with_user(self):
        """
        Test GET with user.

        Project is private and not everyone can contribute to it by default.

        It should return 404 response.
        """
        response = self._get(self.user)
        self.assertEqual(response.status_code, 404)

    def test_get_with_contributor(self):
        """
        Test GET with contributor.

        Contributors can access active web resources.

        It should return 200 response.
        """
        response = self._get(self.contributor)
        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content)
        self.assertEqual(content['id'], self.webresource.id)

    def test_get_with_admin(self):
        """
        Test GET with admin.

        Admins can access active web resources.

        It should return 200 response.
        """
        response = self._get(self.admin)
        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content)
        self.assertEqual(content['id'], self.webresource.id)

    def test_get_when_no_webresource(self):
        """
        Test GET with contributor and admin.

        It should return 404 response.
        """
        self.webresource.delete()

        response = self._get(self.contributor)
        self.assertEqual(response.status_code, 404)

        response = self._get(self.admin)
        self.assertEqual(response.status_code, 404)

    def test_get_when_webresource_is_inactive(self):
        """
        Test GET with contributor and admin.

        Inactive web resources cannot be accessed.

        It should return 404 response.
        """
        self.webresource.status = STATUS.inactive
        self.webresource.save()

        response = self._get(self.contributor)
        self.assertEqual(response.status_code, 404)

        response = self._get(self.admin)
        self.assertEqual(response.status_code, 404)


text:
Raffaele Garofalo (Nápoles, 18 de Novembro de 1851 — Nápoles, 18 de Abril de 1934) foi um magistrado, jurista e criminólogo italiano, um dos mais importantes da escola criminal positiva (Scuola criminale positiva). Foi feito senador do Reino de Itália no ano de 1909.

Criminologistas
Juristas da Itália
Juristas do século XX
Magistrados da Itália
Naturais de Nápoles

redpajama_set_name: RedPajamaWikipedia


text:
RCC Info & News
RCC Church History
RCC Map
Cafe Mazi
Mpact Girls
Ridgeview Youth Ministry
Food and Clothing Banks
Health/Rehab Services
Tenant/Landlord Resources
EasyTithe
- Connection Cafe
- RCC Church History
- RCC Map
- Weekly Bulletin
- Announcement Requests
- Cafe Mazi
- Children's Ministries
- Mpact Girls
- Royal Rangers
- Seniors Group
- Ridgeview Youth Ministry
- Women's Ministries
- Missionaries We Support
- Computer Access
- Food and Clothing Banks
- Health/Rehab Services
- Homeless Resources
- Tenant/Landlord Resources
- Veteran's Services
- Bible Reading Plans
- Daily Devotionals
Home / RCC Info & News / RCC Church History
In the late 1940's God moved Benjamin O. Taylor to come to Spokane's north side and start a church. He drove around the area asking God where He wanted the church. God spoke to him just north of Rowan Street, and he sat in his car arguing with the Lord because there were no houses there, just woods. When he was certain that this was where the Lord wanted the church, he asked Brother R. J. Carlson, the pastor of First Assembly, if it was ok to contact members from his church that lived in the area for help with the new church. After getting permission, he began going door to door in the area inviting people.
Some of the first people he contacted were the Appel and the Hahn families. In about June 1950 Inez Hahn and Sharon Sleeth joined Brother and Sister Taylor. Norma Hahn came shortly afterward. At that point the congregation then consisted of Brother and Sister Taylor and their children, Sharon and John Sleeth, and Inez and Norma Hahn. The church began meeting at the N. W. Christian School. Sister Marion Good and her family soon joined the group and she became the first Sunday School Superintendent. Not long after that property was obtained on the northeast comer of Ash and Rowan streets and a building was started. In 1953 services were moved to the Field school and the church was named Northside Assembly of God. Elwyn and Katherine Tuttle and family joined about that time. There were probably fewer than 10 people coming on Sunday nights. The evening service started at 5 pm as they were not allowed to use the electricity, and often it was dark in the room when the service ended. As soon as the new building was completed enough to use, the congregation held a parade to celebrate, and the church was renamed Shadle Park Assembly of God.
Before the new building could be completely finished a local developer named Gus Cossa decided he would like the block the church occupied for a shopping center. A trade was made for the land across the street at Ash and Nebraska. The developer helped begin construction on the church sanctuary at its present location. The little congregation moved to Ridgeview School while the new sanctuary was being built. The name was then changed to Ridgeview Chapel Assembly of God, and the sanctuary was dedicated in 1956.
During the time Brother Taylor was pastor the youth group started an Outpost Sunday School at Indian Prairie on Sunday afternoons. Most of the people won to the Lord during that time began coming to church. The youth also began helping out at street meetings in downtown Spokane on Main and Stevens each week, and they visited Nursing homes and shut-ins as well.
Brother and Sister Eldred Nelson became our pastors in 1956. Sister Nelson started a youth choir and the first Sunday School wing and fellowship room (originally called fireside room as there was a large fireplace) was completed. Sister Nelson also started activities for college age singles which attracted a few students from Whitworth College. The congregation was incorporated with the Assemblies of God in 1962.
Brother and Sister A. L. Batterson came as pastors in 1969. His Brother-in-law Duane French came to help and a day care was started which ran for more than 26 years. The second addition with church offices was built during this time. The name of the church was changed to Ridgeview Christian Center.
Brother and Sister French became Senior Pastors in 1979. The church had a music ministry to the neighborhood through a singing Christmas wreath. Pastor French invited youth from the Spokane Junior Symphony to play in the programs. Some of the youth stayed and joined the church youth group.
Brother and Sister J. Edward Nordby became pastors in 1983, followed by Pastor and Mrs. C. David Elms in 1987. It was during Brother Elms' ministry the church sanctuary was remodeled.
Brother and Sister Darwin McIntosh became pastors in 1990. The church was involved in many ministries, including Sunday School, Missionettes, Royal Rangers, Men's and Women's groups, Bible studies, an Honored Citizens group, and a vibrant Youth group. During this time the church began both a ministry to the deaf and a program that bought shoes for students that needed them at Ridgeview Elementary school, right across the street. The church also ran a small food bank and continued to support both foreign and home missionaries as well as local ministries such as the Union Gospel Mission and Anna Ogden Hall.
Ridgeview Christian Center Senior Pastors
Benjamin Orlo Taylor
Dr. and Mrs. Eldred Nelson
Reverend and Mrs. Albert Batterson
Reverend and Mrs. Duane French
Mr. and Mrs. Ed Nordby
Reverend and Mrs. C. David Elms
Reverend and Mrs. Darwin McIntosh
Reverend and Mrs. Russ Tappero
Reverend and Mrs. Darren Bruce
Pastor Eddie Foos

redpajama_set_name: RedPajamaCommonCrawl


text:
CHRISTUS Health Home
CHRISTUS Southeast Texas Health System
CHRISTUS Santa Rosa Health System
CHRISTUS Spohn Health System
CHRISTUS St. Frances Cabrini Hospital
CHRISTUS St. Patrick
CHRISTUS Health Shreveport - Bossier
CHRISTUS St. Michael
CHRISTUS St. Michael Atlanta
CHRISTUS Coushatta Health Care Center
CHRISTUS St. Vincent
CHRISTUS Lake Area Hospital
Locations Directions
About CHRISTUS Santa Rosa
Volunteer and Giving Programs
Service Lines Search
CHRISTUS Santa Rosa Hospital - Alamo Heights
The Children's Hospital of San Antonio
CHRISTUS Santa Rosa Hospital - Medical Center
CHRISTUS Santa Rosa Hospital - Westover Hills
CHRISTUS Santa Rosa Hospital - New Braunfels
Alon Emergency Care
Creekside Town Center Emergency Center
CHRISTUS Santa Rosa Physicians Ambulatory Surgery Center - Ewing Halsell
CHRISTUS Santa Rosa Physicians Ambulatory Surgery Center - New Braunfels
CHRISTUS Santa Rosa Physicians Ambulatory Surgery Center - San Marcos
CHRISTUS Santa Rosa Physicians Ambulatory Surgery Center - Stone Oak
CHRISTUS Transplant Institute
When Your Parents Fight
When You Fight With Your Parents
When You Fight With a Brother or Sister
Tips on Family Fighting
It's hard to believe it, but your parents were once kids, too. It might seem like they don't understand you — but don't give up. Remember that they don't really want to make things difficult for you. Your parents care about you, but sometimes it's just hard for them to easily see your point of view.
A parent's job is to look out for you and keep you safe — until you're old enough to take care of yourself (and some parents have trouble giving up watching out for their kids even then)!
Usually, kids who fight with their parents learn to get along with them eventually. This is especially true if kids are able to talk to their parents about how they feel and what's important to them.
Keep in mind, though, that this can take time and a lot of patience. It's not always easy. Talking to your parents about your opinions — instead of screaming and yelling at them — will also make them listen to you a little more closely. Plus, you'll gain respect and learn how to compromise with them.
Is your little sister always taking your stuff? Is your big brother always picking on you? If you're fighting with your brother or sister a lot and competing for attention from your parents, that's called sibling rivalry. It's completely natural to get into arguments with your siblings.
If you're really bothered by your siblings, however, you might want to talk to them about what's going on. Most of the time, your siblings will listen because deep down (even though they don't like to admit it) they really do like you and don't want to fight either.
you, it's important to tell a parent. It's also important to tell an adult you trust if your parent ever hurts you.
If you think your family needs to work on this, you could call a family meeting to talk about it. In the meeting, everyone should get a chance to talk and a chance to suggest solutions. It's a good way to get everyone working on the problems together.
Sometimes, your parent may ask everyone to visit a family counselor or therapist to talk about the problems and get advice from a professional on how to deal with (and stop) the fighting in your family. It's not always easy to stop families from fighting, but by working together, it can be done.
Reviewed by: W. Douglas Tynan, PhD, ABPP
Getting Along With Parents
Living With Stepparents
Living With a Single Parent
Saying You're Sorry
Taking Charge of Anger
Getting Along With Brothers and Sisters
Talking About Your Feelings
Train Your Temper
Expand Navigation Section The Children's Hospital of San Antonio
Community Health Needs Assessment and Implementation Plan
Expand Navigation Section For Patients & Visitors
Find Financial Assistance
Expand Navigation Section For Healthcare Professionals
The Children's Hospital of San Antonio is affiliated with Baylor College of Medicine : 210-704-2011
© 2017 CHRISTUS Health


text:
Aleah Chapin
Within Wilds - Recent
to Dec 13
Poets & Artists
Sat, Dec 2, 2017 11:00 AM 11:00 Wed, Dec 13, 2017 7:00 PM 19:00
ARCADIA CONTEMPORARY
Town Plaza
Aging Pride
Sat, Nov 18, 2017 12:00 PM 12:00 Sun, Mar 4, 2018 11:30 AM 11:30
Rennweg 6, 1030 Vienna, Austria
With Aging Pride, the Belvedere has dedicated a comprehensive museum exhibition to the highly topical, socio-political subject of age. It is the first exhibition to contrast historical and contemporary artistic positions on the concept of age with regard to gender roles, the assignment of these roles, and inter-generational solidarity.
Women Painting Women: In Earnest
Sun, Oct 22, 2017 12:00 PM 12:00 Sun, Dec 31, 2017 5:00 PM 17:00
J. Wayne Stark Galleries, 4229 TAMU, 275 Joe Routt Blvd, College Station, TX
A Traveling Museum Exhibition
Women Painting Women: In Earnest is an exhibition curated by co-founders Alia El-Bermani and Diane Feissel which honors the human spirit and shares the thoughtful and unique vision of 30 contemporary artists who explore the complexity of being a woman today. This exhibition premiers at the Customs House Museum in Clarskville, TN and then travels to the J. Wayne Stark Galleries at Texas A&M University.
to Nov 4
Within Wilds: Solo Show
Wed, Oct 4, 2017 11:00 AM 11:00 Sat, Nov 4, 2017 6:00 PM 18:00
FLOWERS GALLERY
21 Cork Street
London W1S 3LZ
Intimate, revealing and personal, the latest paintings by American artist Aleah Chapin explore the passage of time as seen through the body; depicting friends and relations, all of whom she has known throughout her life growing up in a unique island community on the US Pacific Northwest Coast.
E: info@flowersgallery.com
to Jun 13
Wed, May 18, 2016 11:00 AM 11:00 Mon, Jun 13, 2016 5:00 PM 17:00
Willard L. Metcalf Award for a young artist of great promise.
In 1986, the Academy received a bequest from Addison M. Metcalf, son of the late member Willard L. Metcalf (1858 - 1925), for an award to honor young artists of great promise. The Willard L. Metcalf Award in Art is a biennial prize of $10,000, and will be presented to Aleah on May 18th at the Academy's annual ceremonial. All winners of the institution's 2016 awards will showcase their work in a special exhibition May 18th - June 12th at the Academy.
633 W 155TH STREET, NEW YORK, NY 10032
Body/Being - solo exhibition
Thu, May 12, 2016 11:00 AM 11:00 Sat, Jun 11, 2016 5:00 PM 17:00
Body/Being
A solo exhibition at Flowers Gallery exploring representations of identity through the physical manifestations of gender and the aging of the body.
to May 1
Cascadia Art Museum - Looking Back, Moving Forward
Thu, Jan 14, 2016 5:00 PM 17:00 Sun, May 1, 2016 5:00 PM 17:00
A Centennial Tribute to Nellie Cornish and the Cornish College of the Arts.
Delving deep into public and private archives, Cascadia presents historic artwork, dance, films, costumes and more, by key Cornish figures such as Merce Cunningham, Robert Joffrey and Mark Tobey.
190 Sunset Ave. #E Edmonds, WA 98020
The Ingram Collection: Bodies!
Sat, Nov 21, 2015 9:00 AM 09:00 Sun, Jan 31, 2016 5:00 PM 17:00
The human figure has been depicted by artists for centuries and is still a constant source of inspiration. Artists have represented the male and female body as a symbol, used its forms and shapes to explore power and movement, presented it to show allegories from mythology or simply celebrated the human body for its beauty, elegance or eroticism. Drawn from The Ingram Collection of Modern British and Contemporary Art, featured artists include Henry Moore, Jacob Epstein, Eduardo Paolozzi, Elisabeth Frink, Ralph Brown, Allen Jones, Reg Butler, Anthony Green and Aleah Chapin.
The Lightbox, Chobham Road, Woking, Surrey, GU21 4AA
The Figure: Painting, Drawing, and Sculpture
12:00 AM 1:00 AM 00:00 01:00
By Margaret McCann, David Kratz and Bob Colacello
"This book is a celebration of figurative art, essential to those interested in both traditional techniques and the latest developments in the art of the figure. An expansive survey of contemporary figurative art, The Figure showcases work by acclaimed artists including Jenny Saville, Eric Fischl, and Will Cotton alongside emerging talents. With a wealth of imagery displaying some of the finest examples of the genre in all mediums, this richly illustrated volume attests to the enduring appeal of the art of the human figure."
Buy this book on amazon
The Complete Artist: How To Succeed In The Creative Industry
By Jason Seiler
"This book is a step by step road-map to creative success. With 400 years of combined knowledge and experience from the industry's most successful artists, painters, illustrators, art directors and entrepreneurs."
Buy this book at Sketchoholic
Take Home A Nude - Art Auction + Party
To Benefit the New York Academy of Art
Sotheby's Auction House, 1334 York Avenue, New York
http://nyaa.edu/nyaa/events/than.html
Solo show at Flowers Gallery, London
Maiden, Mother, Child and Crone
Flowers Gallery, 21 Cork Street, London W1s 3Lz
Opening Reception, 7 October 6-8pm
info@flowersgallery.com, www.flowersgallery.com