Commits

story645 committed a7271ec

tried to add in error message

Comments (0)

Files changed (2)

src/repoman/bitbucket.py

 	
 	"""
 	
-	def __init__(self, action, name):
+	def __init__(self, action, name, msg):
 		self.name = name
 		self.action = action
+		self.msg = msg
 		
 	def __str__(self):
-		return "{} failed for {}".format(self.action, self.name)
+		return "{} failed for {}:\n{}".format(self.action, self.name, self.msg)
 
 	
 def create(name, owner, auth, scm='hg', is_private=True):
 	resp = requests.post(API_URL, auth=auth, data=data)
 	
 	if resp.status_code != 200:
-		raise BitBucketError('create', name)
+		raise BitBucketError('create', name, resp.text)
 	
 	return "https://bitbucket.org/{}/{}".format(owner, name)
 
 	get_url = "{}{}/{}/".format(API_URL, owner, name)
 	resp = requests.get(get_url, auth=auth)
 	if resp.status_code != 200:
-		raise BitBucketError('get', name)
+		raise BitBucketError('get', name, resp.text)
 	return json.loads(resp.content)
 	
 
 		
 	Returns
 	----------
-	dictionary of updated attributes
-		
+	dictionary of updated attributes with an entry for the url
+	
 	
 	See Also
 	----------
 	put_url = "{}{}/{}/".format(API_URL, owner, name)
 	resp = requests.put(put_url, auth=auth, data=data)
 	if resp.status_code != 200:
-		raise BitBucketError('update', name)
-	return json.loads(resp.content)
+		raise BitBucketError('update', name, resp.text)
+	
+	attrs = json.loads(resp.content)
+	attrs['url'] = "https://bitbucket.org/{}/{}".format(owner, attrs['name'])
+	
+	return attrs
 	
 
 def delete(name, owner, auth):
 	del_url = "{}{}/{}/".format(API_URL, owner, name)
 	resp = requests.delete(del_url, auth=auth)
 	if resp.status_code != 204:
-		raise BitBucketError('delete', name)	
+		raise BitBucketError('delete', name, resp.text)	

src/tests/test_bitbucket.py

         bb.create(self.name, self.owner, self.auth)
         
     def tearDown(self):
-        bb.delete(self.name, self.owner, self.auth)
-    
+        try:
+            bb.delete(self.name, self.owner, self.auth)
+        except bb.BitBucketError as e:
+            pass #repo was moved
+            
     def test_attributes(self):
         rdict = bb.attributes(self.name, self.owner, self.auth)
         self.assertEqual(self.owner, rdict['owner'])
         self.assertEqual(lang, rdict['language'])
         self.assertEqual(description, rdict['description'])
         
+    def test_update_name(self):
+        newname = "test3"
+        bb_url = "https://bitbucket.org/{}/{}".format(self.owner, newname)
+        rdict = bb.update(self.name, self.owner, self.auth, dict(name=newname))
+        self.assertEqual(bb_url, rdict['url'])
+        bb.delete(newname, self.owner, self.auth)
         
 class TestBBExceptions(unittest.TestCase):