Skip to content

Commit

Permalink
adding migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
talos committed Mar 12, 2012
1 parent 257e3ac commit 6b91d11
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
34 changes: 27 additions & 7 deletions caustic/migrations.py
@@ -1,11 +1,13 @@
'''TEMPORARY: persistence should be done in another way!
#!usr/bin/env python

'''
This is a bootstrap loader for the basic openscrape instructions.
'''

from database import collection
from models import Instruction
HOST = 'http://localhost:7100'
USER = 'openscrape'
import json

collection.drop()
import requests

instructions = [
{
Expand Down Expand Up @@ -321,5 +323,23 @@
}
]

for instruction in instructions:
collection.save(Instruction(**instruction).to_python())

s = requests.session(headers={'accept': 'application/json text/javascript'})
r = s.post('%s/' % HOST, data={
'action':'signup',
'user': USER
})
if r.status_code == 400:
r = s.post('%s/' % HOST, data={
'action':'login',
'user': USER
})

assert r.status_code == 200, r.content

for i in instructions:
r = s.put('%s/%s/instructions/%s' % (HOST, USER, i['name']), data = {
'instruction': json.dumps(i['json']),
'tags': json.dumps([str(e) for e in i.get('tags', [])])
})
assert r.status_code == 201, r.content
9 changes: 1 addition & 8 deletions caustic/server.py
Expand Up @@ -47,7 +47,7 @@ def get_current_user(self):
cookie session. Returns `None` if there is no current user.
"""
id = self.get_cookie('session', None, self.application.cookie_secret)
return self.application.users.get(id)
return self.application.users.get(id) if id else None

def set_current_user(self, user):
"""
Expand All @@ -72,13 +72,6 @@ def is_json_request(self):
# HANDLERS
#
class IndexHandler(Handler):
def trace(self):
"""
Trace provides ping-like functionality, letting clients
know whether the server is available.
"""
return self.render(status_code=204)

def post(self):
"""
Logging in and out.
Expand Down
1 change: 0 additions & 1 deletion test/test_server_json.py
Expand Up @@ -25,7 +25,6 @@ def _signup(self, user):
'action': 'signup',
'user' : user
})
#self.assertEqual(200, r.status_code, r.content)
if r.status_code == 200:
self.created_accounts.append(user)
return r
Expand Down

0 comments on commit 6b91d11

Please sign in to comment.