Posts

Showing posts from October, 2015

[Django] How to Find the Performance Bottlenecks in Your Django Views?

Image
Do you want to find the performance bottlenecks in your Django Views? I recently found this article that introduces nice tools for us to check the performance issues in Django. How to do it? Please follow this URL:
http://djangotricks.blogspot.tw/2015/01/performance-bottlenecks-in-django-views.html

To setup line profiling, install line_profiler and django-devserver to you virtual environment: (myproject_env)$ pip install line_profiler (myproject_env)$ pip install django-devserver Then make sure that you have the following settings in your settings.py or local_settings.py: # settings.py INSTALLED_APPS = ( # ... 'devserver', ) MIDDLEWARE_CLASSES = ( # ... 'devserver.middleware.DevServerMiddleware', ) DEVSERVER_MODULES = ( 'devserver.modules.sql.SQLRealTimeModule', 'devserver.modules.sql.SQLSummaryModule', 'devserver.modules.profile.ProfileSummaryModule', # Modules not enabled by default 'devserver.modules.p…

[Selenium] How to use xpath to define the locator in Selenium Library?

Image
When I first time touch Selenium library in Robot Framework, the first question mark coming up in my mind is "How to use xpath to define the locator?"

 Here is an example. If I want to select the listbox that is near by my email td tag, and the HTML looks like the follows:


There could be several ways to do so. But, I like to use this way to achieve the action that I described below. "Select From List" is the standard keyword to do the action for selecting a list, but you have to give the locator. Based on my HTML code, the answer is this:

Another example, if I want to select the checkbox that is near by my email td tag, I can use the following way to do so:


Or, if I want to get some information in a table, what can I do for this?
OK, if I have the table's HTML code like this:

I can use "Get Table Cell" keyword with xpath //table[@class='your table's class name'] and the information in which row and column, then you can finish the task to g…

[Python] How can I patch a Python decorator before it wraps a function?

Image
As title, Python decorator could be a problem if you want to write some unit cases that test these functions which contains decorators because you cannot use Mock to patch your decorators. Why? Please refer to the following link to check out:
http://stackoverflow.com/questions/7667567/can-i-patch-a-python-decorator-before-it-wraps-a-function
Decorators are applied at function definition time. For most functions, this is when the module is loaded. (Functions that are defined in other functions have the decorator applied each time the enclosing function is called.) So if you want to monkey-patch a decorator, what you need to do is: Import the module that contains itDefine the mock decorator functionSet e.g.module.decorator = mymockdecoratorImport the module(s) that use the decorator, or use it in your own module
Let me give an exmple: Here is a decorator function(user_passes_test) in the following file path /usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py
If you have …

[SSH] To examine the Linux PAM for login mechanism

Image
Based on Linux PAM module, we can easily configure the related pam file and use the functionality that it provides. I just examine login authentication mechanism from PAM a little bit. The scenario is like this:
  I change the login authentication mechanism from key pair to password and to see what happens in /var/log/auth.log if I give the wrong password.


/etc/ssh/sshd_config
The value to change:
PubkeyAuthenticationyes ==> no PasswordAuthenticationno ==> yes
$> service ssh restart

After restarting ssh daemon, I give the wrong password and then I can see the error message in the log file:

The following image is for reference if everything is correct.