Commits

Daniel Holth committed 722e78d

add table for storing OpenID associations

Comments (0)

Files changed (3)

ponzi_openid/tables.py

+from sqlalchemy import Column, Integer, Unicode, ForeignKey
+from sqlalchemy.orm import relationship
+from sqlalchemy.ext.declarative import declarative_base
+
+from ponzi_auth.tables import User, initialize as initialize_auth
+
+Base = declarative_base()
+
+class OpenID(Base):
+    """Store the OpenIDs associated with each user. When an OpenID is
+    provided, the application should log in the associated user."""
+    
+    __tablename__ = 'ponzi_openid'
+    association_id = Column(Integer, primary_key=True)
+    user_id = Column(Integer, ForeignKey(User.user_id), index=True)
+    openid = Column(Unicode(256), nullable=False, index=True, unique=True)
+    user = relationship(User, backref='openids')
+
+    def __repr__(self):
+        return 'openid:%r' % (self.openid,)
+
+def initialize(session):
+    Base.metadata.create_all(session.bind)
+

ponzi_openid/templates/base.jinja2

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 {% block head %}
 <title>{% block title %}Pyramid OpenID{% endblock %}</title>
-{% block css %}{% endblock%}
+{% block css %}
+<link rel="stylesheet" type="text/css" href="{{request.scheme}}://yui.yahooapis.com/combo?3.2.0/build/cssreset/reset-min.css&3.2.0/build/cssfonts/fonts-min.css&3.2.0/build/cssgrids/grids-min.css">
+{% endblock%}
 {% endblock %}
 </head>
 <body>

ponzi_openid/tests.py

 import unittest
+import sqlalchemy.orm
+import sqlalchemy
 
 from pyramid.configuration import Configurator
 from pyramid import testing
         from ponzi_openid import models
         request = None
         assert models.get_root(request) is not None
+
+    def test_association(self):
+        from ponzi_openid import tables
+        import ponzi_auth.tables
+
+        engine = sqlalchemy.create_engine('sqlite:///:memory:', echo=True)
+        Session = sqlalchemy.orm.sessionmaker(bind=engine)
+        session = Session()
+
+        ponzi_auth.tables.initialize(session)
+        tables.initialize(session)
+
+        user = ponzi_auth.tables.User(username=u'')
+        openid = tables.OpenID(openid='openid.example.org')
+        user.openids.append(openid)
+
+        session.add(user)
+        session.commit()
+
+