Advertisement
Guest User

Untitled

a guest
Jan 29th, 2014
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import pytest
  2.  
  3. from mediagoblin.tools import pagination
  4.  
  5. #the next 30 lines for the db cursor handle
  6. from sqlalchemy import Column,Integer
  7. from sqlalchemy.ext.declarative import declarative_base
  8. from sqlalchemy.orm import relationship
  9. from sqlalchemy import create_engine
  10. from sqlalchemy.orm import sessionmaker
  11.  
  12. Base=declarative_base()
  13.  
  14. class Example(Base):
  15. __tablename__="example"
  16. id = Column(Integer,primary_key=True)
  17. testVar = Column(Integer,nullable=False)
  18.  
  19. engine = create_engine('sqlite:///sqlalchemyExample.db')
  20. Base.metadata.create_all(engine)
  21.  
  22. DBSession = sessionmaker(bind=engine)
  23. session = DBSession()
  24.  
  25. obj1 = Example(testVar=1)
  26. obj2 = Example(testVar=2)
  27. obj3 = Example(testVar=3)
  28. obj4 = Example(testVar=4)
  29. obj5 = Example(testVar=5)
  30. session.add(obj1)
  31. session.add(obj2)
  32. session.add(obj3)
  33. session.add(obj4)
  34. session.add(obj5)
  35. session.commit()
  36. #all this just for one db cursor handle :O
  37.  
  38.  
  39. class TestPagination:
  40. cur = session.query(Example)
  41. paginator = pagination.Pagination(page=3,cursor=cur,per_page=3)
  42. def test_get_page_url_explicit(self):
  43. base_url = "www.google.com/"
  44. get_params = {'query1':'hello','query2':'goodbye'}
  45. page_no = 4
  46. assert self.paginator.get_page_url_explicit(base_url, get_params, page_no) == "www.google.com/?query2=goodbye&query1=hello&page=4"
  47.  
  48. def test_properties(self):
  49. assert self.paginator.total_count == 5
  50. assert self.paginator.pages == 2
  51.  
  52.  
  53. session.expunge_all()
  54. session.commit()
  55. session.close()
  56. Base.metadata.drop_all(engine)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement