pypi / tests / test_store.py

import distutils2

from distutils2.metadata import DistributionMetadata

import os
import unittest
import config
import pkg_resources
import cStringIO


import store
import trove

DATA_DIR = os.path.join(os.path.dirname(trove.__file__), "tests", "data")
CONFIG_FILE = os.path.join(DATA_DIR, "config.ini")
DUMP = os.path.join(DATA_DIR, "test_dump.sql")
DUMP_DATA = os.path.join(DATA_DIR, "test_dump-data.sql")

user1 = ("user1", "pass", "test@admin.org", None)
user2 = ("user2", "pass", "test@admin.org", None)
user3 = ("user3", "pass", "test3@admin.org", None)

class TestStore ( unittest.TestCase ):

    def setUp(self):
        self.store = store.Store( config.Config( CONFIG_FILE ) )
        self.store.open()
        self.store.get_cursor().execute("".join(open(DUMP).readlines()))

    def tearDown(self):
        self.store.close()

    def test_store_package(self):
        PKG_INFO = os.path.join(DATA_DIR, 'PKG-INFO')
        metadata = DistributionMetadata(PKG_INFO)
        metadata = dict(metadata.items())
        packages = self.store.get_package("pypi", "0.1")

        self.assertRaises(TypeError, packages.values) 
        self.store.store_package("pypi", "0.1", metadata)

        packages = self.store.get_package("pypi", "0.1")    
        assert len(packages.values()) == 21

        packages = self.store.get_package("pypi", "0.2")
        self.assertRaises(TypeError, packages.values) 

        package = self.store.store_package("pypi", "0.1", metadata)
        assert package is None

        metadata['author'] = 'Foo'
        package = self.store.store_package("pypi", "0.1", metadata)

        assert package is not None

    def test_create_user(self):        
        self.store.store_user(*user1)

        assert self.store.get_user("user1") is not None
        self.assertRaises(ValueError, self.store.store_user, *user2)

    def test_get_users(self):
        self.store.store_user(*user1)
        self.store.store_user(*user3)
        self.assertTrue(len(self.store.get_users())==2)

    def test_get_user(self):
        self.store.store_user(*user1)
        self.assertTrue('user1' in self.store.get_user("user1").values())

    def test_get_user_by_email(self):
        self.store.store_user(*user1)
        self.assertTrue('user1' in self.store.get_user_by_email("test@admin.org").values())

    def test_sshkeys(self):
        self.store.store_user(*user1)
        assert len(self.store.get_sshkeys('user1')) == 0

        self.store.add_sshkey('user1', "sfasfaf")
        assert len(self.store.get_sshkeys('user1')) == 1

        self.store.delete_sshkey(self.store.get_sshkeys('user1')[0].values()[0])
        assert len(self.store.get_sshkeys('user1')) == 0

    def test_get_openid(self):
        self.store.store_user(*user1)
        assert len(self.store.get_openids('user1')) == 0

        self.store.associate_openid('user1', 'openid_user1')
        assert len(self.store.get_openids('user1')) == 1

    def test_get_user_by_openid(self):
        self.store.store_user(*user1)
        assert 'user1' not in self.store.get_user_by_openid('openid_user1')

        self.store.associate_openid('user1', 'openid_user1')
        assert 'user1' in self.store.get_user_by_openid('openid_user1')

        self.store.drop_openid('openid_user1')
        assert 'user1' not in self.store.get_user_by_openid('openid_user1')
    
#     def test_openid_provider(self):
#         self.assertTrue(False)

#     def test_role(self):
#         self.asserTrue(False)

#     def test_oth(self):
#         self.assertTrue(False)

#     def test_user_package(self):
#         self.asserTrue(False)
        
#     def test_user_package_details(self):
#         self.assertTrue(False)

#     def test_trows(self):
#         self.assertTrue(False)

#     def test_tally(self):
#         self.assertTrue(False)

#     def test_browse(self):
#         self.assertTrue(False)

#     def test_file_handling(self):
#         self.assertTrue(False)

#     def test_logging(self):
#         self.assertTrue(False)
        
#     def test_upload_times(self):
#         self.assertTrue(False)

#     def test_mirror(self):
#         self.assertTrue(False)

#     def test_cookie(self):
#         self.assertTrue(False)

#     def test_session(self):
#         self.assertTrue(False)

#     def test_nonce(self):
#         self.assertTrue(False)

if __name__ == '__main__':
    unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.