Commits

Anonymous committed 22736d0

fix buildout and upgrade the test coverage

Comments (0)

Files changed (6)

 log
 parts
 tmp
-pypi.egg-info
+pypi.egg-info
+
+# test
+tests/.coverage
      WSGIUtils
      BeautifulSoup
      coverage
-     ipdb
+     ipython
+     ipdb     
      pypi
 extra-path = $(buildout:dir)/envs/lib/python2.6/site-packages/distutils2/
 
 
             If "new_version" is supplied, insert it into the sequence and
             return the ordering value for it.
+
+            TODO: Shouldn't return the current release number if no new_version
         '''
         cursor = self.get_cursor()
         # load up all the version strings for this package and sort them

tests/.coverage

Binary file removed.

tests/data/PKG-INFO2

+Metadata-Version: 1.2
+Name: CLVault
+Version: 0.5
+Summary: Command-Line utility to store and retrieve passwords
+Home-page: http://bitbucket.org/tarek/clvault
+Author: Tarek Ziade
+Author-email: tarek@ziade.org
+License: PSF
+Keywords: keyring,password,crypt
+Requires-Dist: foo; sys.platform == 'okook'
+Requires-Dist: bar; sys.platform == '%s'
+Download-URL: http://www.google.com
+Platform: UNKNOWN
+Description: CLVault
+       |=======
+       |
+       |CLVault uses Keyring to provide a command-line utility to safely store
+       |and retrieve passwords.
+       |
+       |Install it using pip or the setup.py script::
+       |
+       |    $ python setup.py install
+       |
+       |    $ pip install clvault
+       |
+       |Once it's installed, you will have three scripts installed in your
+       |Python scripts folder, you can use to list, store and retrieve passwords::
+       |
+       |    $ clvault-set blog
+       |    Set your password:
+       |    Set the associated username (can be blank): tarek
+       |    Set a description (can be blank): My blog password
+       |    Password set.
+       |
+       |    $ clvault-get blog
+       |    The username is "tarek"
+       |    The password has been copied in your clipboard
+       |
+       |    $ clvault-list
+       |    Registered services:
+       |    blog    My blog password
+       |
+       |
+       |*clvault-set* takes a service name then prompt you for a password, and some
+       |optional information about your service. The password is safely stored in
+       |a keyring while the description is saved in a ``.clvault`` file in your
+       |home directory. This file is created automatically the first time the command
+       |is used.
+       |
+       |*clvault-get* copies the password for a given service in your clipboard, and
+       |displays the associated user if any.
+       |
+       |*clvault-list* lists all registered services, with their description when
+       |given.
+       |
+       |
+       |Project page: http://bitbucket.org/tarek/clvault
+       |

tests/test_store.py

 import distutils2
 
-from distutils2.metadata import DistributionMetadata
+from distutils2.metadata import DistributionMetadata, _ATTR2FIELD
 
 import os
 import unittest
 user2 = ("user2", "pass", "test@admin.org", None)
 user3 = ("user3", "pass", "test3@admin.org", None)
 
+_FIELD2ATTR = dict([(value,key) for key,value in _ATTR2FIELD.items()])
+
 class TestStore ( unittest.TestCase ):
 
+    def _convert_to_attr(self, metadata):
+        """convert field name to attribute cause pypi is using field name and 
+        not attribute like in distutils2
+        """
+        return dict([(_FIELD2ATTR[key], value) for key,value in metadata.items()]) 
+
     def setUp(self):
         self.store = store.Store( config.Config( CONFIG_FILE ) )
         self.store.open()
         self.store.get_cursor().execute("".join(open(DUMP).readlines()))
 
+        self.PKG_INFO = os.path.join(DATA_DIR, 'PKG-INFO')
+        self.pkg_info_metadata = DistributionMetadata(self.PKG_INFO)
+        self.metadata = self._convert_to_attr(self.pkg_info_metadata)
+
+        self.PKG_INFO2 = os.path.join(DATA_DIR, 'PKG-INFO2')
+        self.pkg_info_metadata2 = DistributionMetadata(self.PKG_INFO2)
+        self.metadata2 = self._convert_to_attr(self.pkg_info_metadata2)
+
     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")
+        package = self.store.get_package("pypi", "0.1")
 
-        self.assertRaises(TypeError, packages.values) 
-        self.store.store_package("pypi", "0.1", metadata)
+        self.assertRaises(TypeError, package.values) 
+        self.store.store_package("pypi", "0.1", self.metadata)
 
-        packages = self.store.get_package("pypi", "0.1")    
-        assert len(packages.values()) == 21
+        package = self.store.get_package("pypi", "0.1")    
+        assert len(package.values()) == 21
 
-        packages = self.store.get_package("pypi", "0.2")
-        self.assertRaises(TypeError, packages.values) 
+        package = self.store.get_package("pypi", "0.2")
+        self.assertRaises(TypeError, package.values) 
 
-        package = self.store.store_package("pypi", "0.1", metadata)
+        package = self.store.get_package("pypi", "0.1")
+        package = dict(package.items())
+        package = self.store.store_package("pypi", "0.1", package)
         assert package is None
 
-        metadata['author'] = 'Foo'
-        package = self.store.store_package("pypi", "0.1", metadata)
+        self.metadata['author'] = 'Foo'
+        package = self.store.store_package("pypi", "0.1", self.metadata)
 
         assert package is not None
 
+    def test_fix_ordering(self):
+        self.store.store_package("pypi", "0.2", self.metadata)
+
+        assert self.store.fix_ordering("pypi", "0.2") == 10.0
+
+        self.store.store_package("pypi", "0.1", self.metadata)
+
+        assert self.store.fix_ordering("pypi", "0.2") == 11.0    
+        assert self.store.fix_ordering("pypi", "0.1") == 10.0
+
+    def test_has_package(self):
+        assert self.store.has_package('pypi') == 0
+
+        self.store.store_package("pypi", "0.1", self.metadata)
+        assert self.store.has_package('pypi') == 1
+
+        self.store.store_package("pypi", "0.2", self.metadata)
+        assert self.store.has_package('pypi') == 1
+
+        self.store.store_package("PYPI2", "0.1", self.metadata)
+        assert self.store.has_package('pypi2') == 0
+
+    def test_find_package(self):
+        assert len(self.store.find_package('pypi')) == 0
+
+        self.store.store_package("pypi", "0.1", self.metadata)
+        assert len(self.store.find_package('pypi')) == 1
+
+        self.store.store_package("pypi", "0.2", self.metadata)
+        assert len(self.store.find_package('pypi')) == 1
+
+        self.store.store_package("PYPI2", "0.1", self.metadata)
+        assert len(self.store.find_package('pypi2')) == 1
+
+        self.store.store_package("PYPI", "0.3", self.metadata)
+        assert len(self.store.find_package('pypi')) == 2
+
+    def test_has_release(self):
+        assert self.store.has_release("pypi", "0.1") == False
+
+        self.store.store_package("pypi", "0.1", self.metadata)
+
+        assert self.store.has_release("pypi", "0.1") == True
+        assert self.store.has_release("pypi", "0.2") == False
+
+        assert self.store.has_release("PYPI", "0.1") == False
+        assert self.store.has_release("false package", "0.1") == False
+
+    def test_get_cheesecake_index(self):
+        """get_cheesecake_index ????"""
+
+    def test_get_package(self):
+        self.store.store_package("CLVault", "0.5", self.metadata2)
+        package = self.store.get_package("CLVault", "0.5")
+        package_info = package.as_dict()
+
+        # just to be sure
+        assert dict(package.items()) == package_info
+        
+        for key in package_info.keys():
+            if self.pkg_info_metadata2.is_metadata_field(key):
+                store_value = package_info.get(key)
+                metad_value = self.pkg_info_metadata2.get(key)           
+                if metad_value in ('UNKNOWN', []):
+                    metad_value = None
+                if store_value in ('UNKNOWN', [], u'{}'):
+                    store_value = None
+                if isinstance(metad_value,list) and \
+                        isinstance(store_value, unicode):
+                    store_value = store_value.strip('{}').split(',')
+                self.assertEqual(store_value, metad_value, 
+                                 "Invalid metadata comparison for key %s (%s != %s)" \
+                                     % (key, store_value, metad_value))
+
+    def test_get_package_url(self):
+        self.store.store_package("CLVault", "0.5", self.metadata2)
+        assert len(self.store.get_package_urls("CLVault")) == 1
+        
+        self.store.store_package("CLVault", "0.6", self.metadata2)        
+        assert len(self.store.get_package_urls("CLVault")) == 2
+        assert self.store.get_package_urls("CLVault2") is None
+        
+        url = self.store.get_package_urls("CLVault")
+        url = url.pop()
+        assert url == ('http://www.google.com', 'download', '0.6 download_url')
+
+    def test_get_stable_version(self):
+        assert False
+
+    def test_get_packages(self):
+        assert len(self.store.get_packages()) == 0
+        
+        self.store.store_package("CLVault", "0.5", self.metadata2)
+        
+        assert len(self.store.get_packages()) == 1
+        
+        self.store.store_package("CLVault", "0.6", self.metadata2)
+
+        assert len(self.store.get_packages()) == 1
+
+    def test_get_journal(self):
+        self.store.store_package("CLVault", "0.5", self.metadata2)
+        journal = self.store.get_journal("CLVault", "0.5")
+        
     def test_create_user(self):        
         self.store.store_user(*user1)
 
 
     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())
+        users = self.store.get_user_by_email("test@admin.org").values()
+        self.assertTrue('user1' in users)
 
     def test_sshkeys(self):
         self.store.store_user(*user1)