Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added the test script, and updated the ignores

  • Loading branch information...
commit 2690e12bfcc15bf08641bce65ce5399ec4d04e72 1 parent 8ba901c
@exhuma authored
Showing with 135 additions and 1 deletion.
  1. +1 −0  .gitignore
  2. +1 −1  postinst.sh
  3. +133 −0 test.py
View
1  .gitignore
@@ -1,5 +1,6 @@
*egg-info
dev.db
+app.db
dist
env
manage.py
View
2  postinst.sh
@@ -2,6 +2,6 @@
# Post installation script (example)
-python manage manage.py --repository=db_repo --url=sqlite:///dev.db
+python manage manage.py --repository=db_repo --url=sqlite:///app.db
python manage.py version_control
echo "manage.py script created"
View
133 test.py
@@ -0,0 +1,133 @@
+from os import unlink
+import unittest
+
+from migrate.versioning.api import upgrade, db_version, version_control
+from migrate.exceptions import DatabaseNotControlledError
+
+from mypi import db
+
+DB_FILE = 'test.db'
+URI = 'sqlite:///%s' % DB_FILE
+REPO = 'db_repo'
+
+def create_db():
+ """
+ Creates the test DB
+ """
+ try:
+ db_version(URI, REPO)
+ except DatabaseNotControlledError:
+ version_control(URI, REPO)
+
+ upgrade(URI, REPO)
+
+def drop_db():
+ """
+ Removes the test DB
+ """
+ unlink(DB_FILE)
+
+
+class TestProjectManagement(unittest.TestCase):
+
+ def setUp(self):
+ db.rebind(URI)
+ create_db()
+ self.session = db.Session()
+ self.session.expire_on_commit = False
+
+ def tearDown(self):
+ self.session.close()
+ drop_db()
+
+ def testCreate(self):
+ p = db.Project('test', 'john@example.com')
+ self.session.add(p)
+ self.session.commit()
+
+ s2 = db.Session()
+ x = s2.query(db.Project).all()[0]
+ self.assertEqual(x, p)
+
+ def testUniqueness(self):
+ "ensures no duplicates can be entered to the DB"
+ from sqlalchemy.exc import IntegrityError
+ p = db.Project('test', 'john@example.com')
+ dupe = db.Project('test', 'john@example.com')
+ self.session.add(p)
+ self.session.add(dupe)
+ self.assertRaises(IntegrityError, self.session.commit)
+
+class TestInterface(unittest.TestCase):
+
+ def setUp(self):
+ db.rebind(URI)
+ create_db()
+ self.session = db.Session()
+ self.session.expire_on_commit = False
+
+ # Add one example release
+ data = {}
+ data['author_email'] = "john@example.com"
+ data['name'] = "proj1"
+ data['version'] = "1.0"
+ data["license"] = "BSD"
+ data["metadata_version"] = "1"
+ data["home_page"] = "UNKNOWN"
+ data["download_url"] = "UNKNOWN"
+ data["summary"] = "bla"
+ data["platform"] = "linux"
+ data["description"] = "Hello World!"
+ #rel = db.Release.add(self.session, data)
+ self.session.commit()
+
+ def tearDown(self):
+ self.session.close()
+ drop_db()
+
+ def testRegister(self):
+ data = {}
+ data['author_email'] = "jane@example.com"
+ data['name'] = "proj2"
+ data['version'] = "1.0"
+ data["license"] = "BSD"
+ data["metadata_version"] = "1"
+ data["home_page"] = "UNKNOWN"
+ data["download_url"] = "UNKNOWN"
+ data["summary"] = "bla"
+ data["platform"] = "linux"
+ data["description"] = "Hello World!"
+ rel = db.Release.add(self.session, data)
+ self.session.commit()
+
+ self.assertTrue(rel)
+
+ def testUploadWithoutMetadata(self):
+ """
+ Ensures that we are blocking uploads without having metadata from a
+ previous "register" action.
+ """
+
+ data = dict(
+ author_email = "john@example.com",
+ name = "proj1",
+ version = "1.0",
+ md5_digest = "1234",
+ comment = "bla",
+ filetype = "bdist_dumb",
+ pyversion = "2.7",
+ protcol_version = "1",
+ )
+
+ self.assertRaises(ValueError, db.File.add, self.session, data)
+
+def main():
+ """
+ The main method
+ """
+ create_db()
+ drop_db()
+
+if __name__ == '__main__':
+ unittest.main()
+
Please sign in to comment.
Something went wrong with that request. Please try again.