# Path: studio/tests/lib/helpers.py
# def log_in(app, login, password):
#     response = app.get(url('/login'),
#             params={
#                 'login': login,
#                 'password': password,
#                 })
#     assert response.status.startswith('302 ')
# 
# def log_out(app):
#     response = app.get(url('/logout'))
#     assert response.status.startswith('302 ')


import simplejson 
from studio.tests import *
from studio.model import *
from studio.tests.lib.helpers import log_in, log_out
        assert response.location.find('signin') >= 0

    def test_delete(self):
        id1, id2 = self._insert_datastores()
        log_in(self.app, 'admin', 'password')
        response = self.app.delete(url('DataStores', id=id1), status=204)
        results = meta.Session.query(DataStore).all()
        assert len(results) == 1
        assert results[0].id == id2
        assert results[0].name == 'datastore2'
        assert results[0].type == 'path'
        assert results[0].ogrstring == 'file://my/path'
        log_out(self.app)
        # test forbidden user
        log_in(self.app, 'enduser', 'password')
        response = self.app.delete(url('DataStores', id=id1), status=403)
        log_out(self.app)
        # test anonymous user
        response = self.app.delete(url('DataStores', id=id1), status=302)
        assert response.location.find('signin') >= 0

    def test_show(self):
        id1, id2 = self._insert_datastores()
        log_in(self.app, 'admin', 'password')
        response = self.app.get(url('DataStores', id=id1, test="true"))
        assert response.response.content_type == 'application/json'
        r = simplejson.loads(response.response._body)
        assert r['id'] == id1
        assert r['type'] == 'postgis'
        assert r['name'] == 'datastore1'

# Path: studio/tests/lib/helpers.py
# def log_in(app, login, password):
#     response = app.get(url('/login'),
#             params={
#                 'login': login,
#                 'password': password,
#                 })
#     assert response.status.startswith('302 ')
# 
# def log_out(app):
#     response = app.get(url('/logout'))
#     assert response.status.startswith('302 ')


# Path: studio/tests/functional/test_datastores.py
import simplejson 
from studio.tests import *
from studio.model import *
from studio.tests.lib.helpers import log_in, log_out

        assert response.location.find('signin') >= 0

    def test_delete(self):
        id1, id2 = self._insert_datastores()
        log_in(self.app, 'admin', 'password')
        response = self.app.delete(url('DataStores', id=id1), status=204)
        results = meta.Session.query(DataStore).all()
        assert len(results) == 1
        assert results[0].id == id2
        assert results[0].name == 'datastore2'
        assert results[0].type == 'path'
        assert results[0].ogrstring == 'file://my/path'
        log_out(self.app)
        # test forbidden user
        log_in(self.app, 'enduser', 'password')
        response = self.app.delete(url('DataStores', id=id1), status=403)
        log_out(self.app)
        # test anonymous user
        response = self.app.delete(url('DataStores', id=id1), status=302)
        assert response.location.find('signin') >= 0

    def test_show(self):
        id1, id2 = self._insert_datastores()
        log_in(self.app, 'admin', 'password')
        response = self.app.get(url('DataStores', id=id1, test="true"))
        assert response.response.content_type == 'application/json'
        r = simplejson.loads(response.response._body)
        assert r['id'] == id1
        assert r['type'] == 'postgis'
        assert r['name'] == 'datastore1'

        log_out(self.app)