Commits

Gabriele Lanaro  committed 9599a26

more tests and a correct handling of login errors and other niceties

  • Participants
  • Parent commits a59d7e5
  • Branches single-blog

Comments (0)

Files changed (5)

 glob:*.pyc
 glob:.ropeproject
 glob:tests/setup_auth.el
+glob:\#*
+glob:.\#*

File blogger-mode.el

   "Starts a buffer with the blogs listed and shows the entries of
   each blog, in Blogger mode"
   (interactive)
-  
-  ;; Fetch the usn and pass and authenticate
-  (when (not (or blogger-username blogger-password))
-    (blogger-prompt-usn-pass))
-  (blogger-authenticate)
-  
-  ;; Loads/Refresh the blog list and prompt for the blog if not defined
-  (blogger-bridge-refresh)
-  (when (not blogger-default-blog-name)
-    (blogger-select-blog))
-  
-  (pop-to-buffer (generate-new-buffer "Blogger"))
-  
-  (let ((buffer-read-only nil))
-    (blogger-create-bloglist))
-  (blogger-mode))
+
+    ;; Fetch the usn and pass and authenticate
+    (when (not (or blogger-username blogger-password))
+      (blogger-prompt-usn-pass))
+    
+    (blogger-authenticate)
+    
+    ;; Loads/Refresh the blog list and prompt for the blog if not defined
+    (blogger-bridge-refresh)
+    (when (not blogger-default-blog-name)
+      (blogger-select-blog))
+    
+    (pop-to-buffer (generate-new-buffer "Blogger"))
+    
+    (let ((buffer-read-only nil))
+      (blogger-create-bloglist))
+    
+    (blogger-mode)
+
+  )
 
 (defun blogger-delete ()
   "Delete post under cursor"
 ;; Utility/Displaying functions
 (defun blogger-authenticate ()
   "authenticate to blogger system"
-  (blogger-bridge-authenticate)
+  (when (not (blogger-bridge-authenticate))
+    (error "Invalid username/password"))
   )
 
 (defun blogger-prompt-usn-pass ()
   (interactive)
   (setq 
    blogger-default-blog-name 
-   (completing-read "Select a Blog (TAB for completion): "(blogger-bridge-get-blog-names))
+   (completing-read "Select a Blog (TAB for completion): " (blogger-bridge-get-blog-names))
    )
   )
 
 (defun blogger-create-bloglist ()
   "Create the list of entries in the selected blog"
   (let (bid blog-name) ;; Fetch blog name and id
+    
     (setq blog-name blogger-default-blog-name)
+    
     (setq bid (blogger-bridge-get-blog-id blog-name))
     ;; Display entries
     (dolist (entry (blogger-bridge-get-entries bid)) 

File blogger_bridge.py

         self.authenticated = False
 
     def authenticate(self):
+        '''Authenticate the user and return True if succeed else False
+        '''
+        
         username = lisp["blogger-username"].value()
         password = lisp["blogger-password"].value()
         
             self.blogger = Blogger(username, password)
             self.authenticated = True
         except:
-            lisp.message("Invalid username, password")
-
+            return False
+        return True
     
     def refresh(self):
         '''refresh the cached list of blogs and entries
     def get_blog_id(self,name):
         '''get a blog by name
         '''
-        
-        return next(blog.id for blog in self.blogs if blog.name == name)
+        try:
+            return next(blog.id for blog in self.blogs if blog.name == name)
+        except StopIteration:
+            lisp.error("Blog name '%s' not correct"%name)
     
     def get_entries(self, blog_id):
         '''get entries of the blog identified by blog_id

File tests/test_blog_error.el

+(load-file "setup_load.el")
+(load-file "setup_auth.el")
+(setq blogger-default-blog-name "asdf")
+(blogger-show)

File tests/test_open_error.el

+(load-file "setup_load.el")
+(load-file "setup_auth.el")
+(setq blogger-username "gabriele.lanaro")
+(setq blogger-password "sdfh")
+(blogger-show)