# Path: bibserver/web.py
# def load_account_for_login_manager(userid):
# def set_current_user():
# def standard_authentication():
# def query(path='Record'):
# def content():
# def home():
# def users():
#     def get(self):
#     def post(self):
#     def get(self):
#     def post(self):
#     def get(self):
#     def post(self):
# def note(nid=''):
# def default(path):
# class UploadView(MethodView):
# class CreateView(MethodView):
# class NoUploadOrCreate(MethodView):


from nose.tools import assert_equal
from base import *
from bibserver import web, ingest
import urllib
import os
        res = self.app.post('/upload?format=bibtex&collection='+urllib.quote_plus('"My Test Collection"'),
            data = {'upfile': (open('test/data/sample.bibtex'), 'sample.bibtex')},
            headers={'REMOTE_USER': Fixtures.account.id}
            )
        assert res.status == '302 FOUND', res.status
        # Now we have to trigger the ingest handling of the ticket
        # which is normally done asynchronously
        for state in ('new', 'downloaded', 'parsed'):
            for t in ingest.get_tickets(state):
                ingest.determine_action(t)
        
        endnum = dao.Record.query().total
        assert_equal(endnum, startnum+1)

    # TODO: re-enable
    # This does not work because login in the previous method appears to
    # persist to this method. Not sure how to fix this ...
    def _test_upload_post_401(self):
        bibtex_data = open('test/data/sample.bibtex').read()
        res = self.app.post('/upload',
            data=dict(
                format='bibtex',
                collection='My Test Collection',
                data=bibtex_data,
                )
            )
        assert res.status == '401 UNAUTHORIZED', res.status

    def test_query(self):
        res = self.app.get('/query')

# Path: bibserver/web.py
# def load_account_for_login_manager(userid):
# def set_current_user():
# def standard_authentication():
# def query(path='Record'):
# def content():
# def home():
# def users():
#     def get(self):
#     def post(self):
#     def get(self):
#     def post(self):
#     def get(self):
#     def post(self):
# def note(nid=''):
# def default(path):
# class UploadView(MethodView):
# class CreateView(MethodView):
# class NoUploadOrCreate(MethodView):


# Path: test/test_web.py
from nose.tools import assert_equal
from base import *
from bibserver import web, ingest
import urllib
import os

        res = self.app.post('/upload?format=bibtex&collection='+urllib.quote_plus('"My Test Collection"'),
            data = {'upfile': (open('test/data/sample.bibtex'), 'sample.bibtex')},
            headers={'REMOTE_USER': Fixtures.account.id}
            )
        assert res.status == '302 FOUND', res.status
        # Now we have to trigger the ingest handling of the ticket
        # which is normally done asynchronously
        for state in ('new', 'downloaded', 'parsed'):
            for t in ingest.get_tickets(state):
                ingest.determine_action(t)
        
        endnum = dao.Record.query().total
        assert_equal(endnum, startnum+1)

    # TODO: re-enable
    # This does not work because login in the previous method appears to
    # persist to this method. Not sure how to fix this ...
    def _test_upload_post_401(self):
        bibtex_data = open('test/data/sample.bibtex').read()
        res = self.app.post('/upload',
            data=dict(
                format='bibtex',
                collection='My Test Collection',
                data=bibtex_data,
                )
            )
        assert res.status == '401 UNAUTHORIZED', res.status

    def test_query(self):
        res = self.app.get('/query')

        assert res.status == '200 OK', res.status