Lean Startup, Software Testing and Python
 

Why you should learn some AngularJS as a test developer

As a test developer, I love making tools, and I like to share my tools. It is always great to hear about how cool your tools are or how much their lives have been made easier.

Most of my tools are written in Python. Simply because it is quick to prototype and there are lots of libraries around Internet.  But it has changed a bit after I started writing more JavaScript code in my current assignment. There are lots of new, exciting things happening around JS world now. As for me, I am really happy that I found AngularJS.

In the past it wasn’t easy to distribute my tools, one reason is that not everyone has Python on their machine. It is totally different with JS. If you have a browser, you can run my code. It can be remote on a server, it can also be in a local folder.

It is also super simple to have nice-looking UI in JS, because HTML/CSS is much easier to tweak. I am not saying I don’t like command-line interface, just sometimes it is more intuitive to have a cool graph. There are also many ready framework you can grab from the internet, including one of my favorite Twitter Bootstrap. Not to mention countless JS plugins to show off/manipulate your data.

With all that being said, if you are a craftsman in heart like me, you should definitely try out some JS framework yourself too. You will not be disappointed:)


Setup Postgresql, Python2.7 and Django using virtualenv on CentOS 6.3

Setup server is always a pain in the ass (if you don’t know chef or other similar tools). It took me two days to get my django app running on the VPS. My problem is there are a lot of tutorials on the website, but few of them cover everything. Also the tutorials are not always working for me, there are many weird problems that are very difficult to Google. So I made some notes for myself, hope it can help you as well.

Postgresql 9.2 on CentOS 6.3

  • Order of entries in pg_hba.conf is important. Always add the new user to the top of the list (that means before host all all).
  • If localhost gives you ident error, try connect using -h 127.0.0.1. Might be your VPS is using ipv6 address for localhost.
  • initdb with UTF8 support when your database is still empty.

Deploy Django using Apache + WSGI + Virtualenv

It seems simple from beginning because I have configured it with non-daemon mode before. This time I try to make it run in daemon mode. The tricky thing is there are many reasons for you to end up with a “ImportError: No module named django.core.wsgi” error. Here is a list you can go through to figure it out:

  • did you install mod_wsgi.so using yum? The module in yum is only for Python 2.6 so you have to compile your own mod_wsgi.so file.
  • run “ldd mod_wsgi.so” to check if libpython.2.7.so.1 shows up. if not, you have to recompile python2.7 and mod_wsgi with –enable-shared option.
  • if it still gets that error, check the permission setting for your virtualenv folder, is the user running daemon has enough privilege?

Template tag “follow_all_url” failed to render unfollow links in django-activity-stream

I have been trying django-activity-stream for weeks now and it is a great Django app. Everything worked great until today, when the tag “follow_all_url” stops rendering unfollow urls.

I tracked back the problem back to a function in class DisplayActivityFollowUrl in activity_tags.py file:

def render(self, context):
    actor_instance = self.actor.resolve(context)
    content_type = ContentType.objects.get_for_model(actor_instance).pk
    if Follow.objects.is_following(context.get('user'), actor_instance):
        return reverse('actstream_unfollow', kwargs={
            'content_type_id': content_type, 'object_id': actor_instance.pk})
    if self.actor_only:
        return reverse('actstream_follow', kwargs={
            'content_type_id': content_type, 'object_id': actor_instance.pk})
    return reverse('actstream_follow_all', kwargs={
        'content_type_id': content_type, 'object_id': actor_instance.pk})

context.get(‘user’) is supposed to get the request.user, but instead it gets nothing. A similar question on stackflow indicates that a setting might be missing, which is not the case but I think it is something wrong with how I created the view. I use class-based generic view and here is how my get_context_data() looks like:

def get_context_data(self, **kwargs):
	ctx = kwargs
	ctx['users'] = User.objects.all()
	return super(StreamView, self).get_context_data(**ctx)

Doesn’t look like it is the problem:(

I remember at first I used activity-stream with pinax-project-account project, and it worked with pinax-user-account app which also does something with the context_processing setting. In this new project I remove the user-account app and switched it with django-social-auth, maybe it missed something in my context?

I haven’t found a solution yet, but I will post the update to the problem here. For now, I think I can temporarily change that line to context.get(‘request’).user instead.


Update:
It was quite stupid actually, I have an object list in the template called “users”, so in a for loop each iterated item is called “user”. Change that to “people” solved the problem.


Bad UX from Prismatic

I was just like many others who signed up on Prismatic last week after read this post on TechCrunch. While I enjoyed some of the articles from it (I guess AI is still learning about my interests), there is one thing disturbs me when I checked my twitter today.

All of the articles I checked on Prismatic app were shared on my Twitter (and probably also could be on Facebook, but I didn’t grant them:)), instead of what I wanted to share. Unfortunately later I figured out how to turn off sharing on Prismatic’s website, but it is still very annoying. My friends must think my account was hijacked and turned into a spamming machine…

P.S. I will remove all those tweets later so you probably will not see them now.


Better Logging Support in TestComplete

I have been using TestComplete since May. The test suite has been running since June. Not sure if I used TC in the right way. Now it just acts as a giant Java interpreter to execute all the code in JScript  (a fairly slow one in my opinion). I haven’t used too many of TC’s functions.

Anyway if you have to use script test case, you need to deal with logging. TestComplete offers four different levels: event, info, warning, error. Here is my code in my common_function.js file, which stores most of the generic functions:

function log_msg()
{
var msg = join_log_args(arguments);
Indicator.PushText("[msg]: " + msg);
Log.Message(msg);
}

function log_event()
{
var msg = join_log_args(arguments);
Indicator.PushText("[event]: " + msg);
Log.Event(msg);
}

function log_warn()
{
var msg = join_log_args(arguments);
Indicator.PushText("[warn]: " + msg);
Log.Warning(msg);
}

function log_error()
{
var msg = join_log_args(arguments);
Indicator.PushText("[error]: " + msg);
Log.Error(msg);
}

function log_debug()
{
  if(vg_debug) //if debug is on
  {  
    var msg = join_log_args(arguments); 
    var cl_priority = 200; //low priority
    Indicator.PushText("[debug]: " + msg);
    Log.Message(msg, "", cl_priority);
  }
}

function join_log_args(args)
{
  var log_string = "";
  for (var i=0; i < args.length; i++)
  {
    log_string = log_string + args[i] + " ";
  }
  return log_string;
}

So if you want to log something, you just need to use:

log_error(log_prefix, "this is an error, error code:", error_code);

and it will automatically join all the input parameters together.


New Project: Bring Umbrella

Just started a new project called Bring Umbrella. One reason is that I want to polish my Django skills, another reason is that I want to practice lean startup concepts  with a small project.

The Idea

I got the idea when I was caught in the rain without an umbrella. For many times I wish there could be a service to remind me bringing the umbrella before I go out in the morning.

If I ask myself the same questions I posted in Göteborg IT Startup Club group, my answer would be:

  1. Do you use umbrella on a raining day? Yes.
  2. Do you check the weather report before going out/to work? Sometimes.
  3. Do you use your phone to check weather report or reading emails right after getting up in the morning? Yes.

Continue reading


Why you should never build your own test framework at work

Last week I moved parts of home-brewed automated test framework to the robot framework. It went smoother than I thought and the new framework offered more functionalities that I was hoping to implement but didn’t for the sake of time. I wonder why I chose to write my own framework in the first place, since Robot framework came out few years ago. (probably because that test framework started as an experiment at work and was in “trial” ever since)

It reminds me a tip in “Ship It! A Practical Guide to Successful Software Projects”: using an “off the shelf” test framework. To most of the people (including me), it seems unnecessary in the beginning to learn to use a new framework just for a simple task. If I can finish it in a few lines of code, why bother spending days pick up something from start? But what people fail to see is automated test grows. A test suite will stay with the project forever and be executed after every change (that’s why you automated it, right?). As software changes, new functionalities need to be added. A few lines become hundreds or thousands lines of code. If you are lucky like me who created their own framework, you will find most of time you spend are not adding new test cases or data into the suite, but maintaining the framework. Since the framework runs as much as the test cases, or even more, there will be plenty of bugs and issues rising up to the surface. But this wouldn’t happen if you implement your tests with well-known test framework, since there are more people maintaining and it comes far more comprehensive from start.

What if there is currently no frameworks that fit your requirement? The best solution is to, still, choose a popular framework and start adding the missing function to it. There are possibly other people on the planet who would like to have the same function and will use or even improve it. So you spend the same amount of time implementing, but much less time maintaining. The employer should also support this because it saves resource and money.

The best example is Google chromium project. As a company famous of their re-inventing wheels, they are also adopting numbers of open-source tools and frameworks. In chromium they use buildbot for automated build and test instead of making their own framework. So next time think about if you can beat the whole chromium QA team before choosing your own framework over the “off the shelf” stuff:P


A simple SOAP mockup service in Python

I was dealing with SOAP tests a lot last month, and WireShark is little too much for simply checking a SOAP request. So I made a little script to show (not capture) the package content. It might be helpful if one needs automated SOAP testing as well. It’s very tiny (26 lines if use without Gzip) and doesn’t depend on any other modules.

Source code can be found at https://bitbucket.org/zheli/soap_echo_server/. Comments are welcome here:)


Hello world!

This my first post. All English articles will be moved from http://blog.systemsthoughts.com to here in the future.