I've already wrote a bit abouttesting in python. Since that, I've adopted nose and django-nose and I'm quite satisfied with the result.
However, I was still feeling frustrated as I wasn't able to find a way of mocking/stubbing certain modules in my code easily without having duplicate settings.py.
Later I figured out that I'm missing very simple and natural solution for some reason: as views are just functions I could simply import them and do whatever I want with them! The only thing I have to do is to construct HttpRequest object. So, the typical example will look like:
This, however, doesn't make much sense without injecting some mocked stuff. Mock object could be created in setUp like that:
Obviously it's also possible to just imported stubbed versions as well. Anyway, I prefer to go with mocks if I don't need to implement some complicated logic for testing, and create them on fly.
In order to inject this stuff, I modify func_globals property of the function:
So we just use our mocked version of 'foo' instead of 'foo' instead and also override some global function that makes requests to some remote service. This approach doesn't look very clean to my opinion, but it works almost fine. There are some problems with it however: if the view is decorated, we have to figure out how to reach the original function. For standard decorators like login we know that view is accessible as 'view_func' property, but if there are several of them including third party ones, it could be a bit troublesome to figure out what is the original view; on the other hand I don't think it'd be hard to solve these problems.
Anyway, I'm quite happy with this solution.
Friday, February 12, 2010
Saturday, January 9, 2010
Few words about December trip to CA
Stayed 2.5 weeks in CA in December, 2009. It was surprisingly cold, esp. during the first week of my stay - from 6th to 12th.
This time wasn't driving around much but spent few nights in San Francisco instead. One of the place visited was Tommy's, tasted some tequilas and I must say that tequila is quite nice. :)
Also visited Ruby Skye and also liked it, despite of the fact that some techno DJ (forgot the name) was performing that night and I'm not much into techno.
Made the picture of it on the other day:

Also visited some other places and met some FreeBSD people -- happy about that.
Some random pic of San Francisco:

The more time I spend in SF, the more I like it.
This time wasn't driving around much but spent few nights in San Francisco instead. One of the place visited was Tommy's, tasted some tequilas and I must say that tequila is quite nice. :)
Also visited Ruby Skye and also liked it, despite of the fact that some techno DJ (forgot the name) was performing that night and I'm not much into techno.
Made the picture of it on the other day:
Also visited some other places and met some FreeBSD people -- happy about that.
Some random pic of San Francisco:
The more time I spend in SF, the more I like it.
Labels:
trip
Saturday, January 2, 2010
Bazylum -- a tool to track x11 windows activity
I was always wondering how much time per day I spend in firefox or, say, pidgin. So I finally managed to implement a tool which would track that. I called it bazylum - "lazy bum" joined together and first chars swapped. Funny, but after such a transformation it still has quite sensible meaning. :-) According to urbandict, bazy means being doing nothing. Lum is more ambiguous word, check it if interested as well.
Getting back to the tool itself. It basically reports how much time a certain window was active, here's the sample:
So, from that report I can see that the majority of time I've spent in urxvt (that is good), the second popular window is firefox (aka Navigator) and I spent only 2 minutes chatting in pidgin (also good). Also, it says that average time before window change is just 25 seconds and the longest time when window was active is only about 11 minutes. It means that my concentration is not very good, probably a sign that I suffer from AD/HD.
If you like the idea, you might want to take a look at the project's github page. The tool is written in C and requires sqlite3 and x11 (you will need -dev packages or something like that on binary based distros). To build it, simply type 'make'. Then collector should be started using './bazylumd' -- it will fork into background and start collecting window activity information. You might pass '-f' arg to it and it will stay in the foreground. And use './bazylum stat' to view the report. The tool is obviously on its early stage of development but works alright on my desktop and laptop.
Getting back to the tool itself. It basically reports how much time a certain window was active, here's the sample:
(20:50) novel@dirtyvegas:~/code/bazylum[master] %> ./bazylum stat
urxvt: 9952 sec
Navigator: 3934 sec
gvim: 1818 sec
xv: 1515 sec
pidgin: 121 sec
desktop: 10 sec
Dialog: 6 sec
avg window active time: 25 sec
longest active time: 658 sec
(20:50) novel@dirtyvegas:~/code/bazylum[master] %>
So, from that report I can see that the majority of time I've spent in urxvt (that is good), the second popular window is firefox (aka Navigator) and I spent only 2 minutes chatting in pidgin (also good). Also, it says that average time before window change is just 25 seconds and the longest time when window was active is only about 11 minutes. It means that my concentration is not very good, probably a sign that I suffer from AD/HD.
If you like the idea, you might want to take a look at the project's github page. The tool is written in C and requires sqlite3 and x11 (you will need -dev packages or something like that on binary based distros). To build it, simply type 'make'. Then collector should be started using './bazylumd' -- it will fork into background and start collecting window activity information. You might pass '-f' arg to it and it will stay in the foreground. And use './bazylum stat' to view the report. The tool is obviously on its early stage of development but works alright on my desktop and laptop.
Wednesday, December 30, 2009
Happy New...
It's 31th of December, 2am. I cannot sleep, don't know why -- maybe because of jet lag or because of a bunch of not so pleasant thoughts in my head. Anyway, this year was not boring by any means.
I'm not in a mood to write some lengthy general post, just want to touch professional aspect of my life. I wrote quite a lot of code this year (not very much though, but not bad at all I think). Unfortunately, most of the code ended up being a shelf-ware or ended up only on my computers with me being the only user as I cannot make the code go live because it's not usable for people other than me -- lacks docs, misses general, but not important to me features and so on.
So I really hope to make a dramatic improvement in that sense in the new year.
Happy Holidays to you.
I'm not in a mood to write some lengthy general post, just want to touch professional aspect of my life. I wrote quite a lot of code this year (not very much though, but not bad at all I think). Unfortunately, most of the code ended up being a shelf-ware or ended up only on my computers with me being the only user as I cannot make the code go live because it's not usable for people other than me -- lacks docs, misses general, but not important to me features and so on.
So I really hope to make a dramatic improvement in that sense in the new year.
Happy Holidays to you.
Labels:
personal
Monday, December 21, 2009
Train Girl
I've boarded the train to Moscow sometime around 4-5 pm or something like that. The only other person in a coupe was a girl. A few minutes after train departed I've started talking to her discussing some gibberish that people usually talk about in trains/planes/etc and eventually the talk became very interesting. You know this feeling, when you're talking with somebody and you have so much things to say and you feel that the person you talk with also has a lot of things to say and basically that it would be fine to have a several discussions with this person in parallel at the same time.
So we've been talking until about 1am and discussed lots of topics, including some personal ones, so, about 8 hours or so, quite a lot of time.
I decided that it's definitely worth not to lose a connection with this person, however I was shy to ask a number. We've agreed to go to the subway (the one that under the ground, not food) together and I though I'd ask number there, but somebody meat her right near the train so I had no chance to ask the number.
So I was feeling quite impressed. I was really really angry at myself that I haven't asked her number. I wasn't able to stop thinking about her for a 4 or 5 days (and it's quite a lot of time for me to think about a girl ;]). I even managed to figure out her last name and address.
But now, a bit more than two weeks later I realised that I almost stopped thinking about her. So, now I'm not sure already if I should try to contact her... blah, on one hand I definitely won't loose anything by trying to contact her, on the other hand it doesn't to be a good situation when you're not sure if you like a person or not, at least I don't like it.
Will see how the stuff goes.
So we've been talking until about 1am and discussed lots of topics, including some personal ones, so, about 8 hours or so, quite a lot of time.
I decided that it's definitely worth not to lose a connection with this person, however I was shy to ask a number. We've agreed to go to the subway (the one that under the ground, not food) together and I though I'd ask number there, but somebody meat her right near the train so I had no chance to ask the number.
So I was feeling quite impressed. I was really really angry at myself that I haven't asked her number. I wasn't able to stop thinking about her for a 4 or 5 days (and it's quite a lot of time for me to think about a girl ;]). I even managed to figure out her last name and address.
But now, a bit more than two weeks later I realised that I almost stopped thinking about her. So, now I'm not sure already if I should try to contact her... blah, on one hand I definitely won't loose anything by trying to contact her, on the other hand it doesn't to be a good situation when you're not sure if you like a person or not, at least I don't like it.
Will see how the stuff goes.
Labels:
personal
Doing Nothing Zen
Looks like I've somehow managed to master 'doing nothing' skill. When I was flying from Moscow to SF two weaks ago (I guess it's about 12 hours + 7 hours) the time passed very quick, I wasn't even reading a book or watching movies etc, was just sitting and doing nothing. And that is quite unnatural to me, because I always feel a need to do something and sitting in the plane without an ability to move or do something interesting was a pain in a previous trips. I even thought that I have an ac/hd as it was really hard to not change things quite often.
Moreover, being in bart also doesn't bother me much. I don't use laptop, I don't read books -- not because I don't bring them, I always have it in my bag, but just because I enjoy looking through the window (even though I've seen everything quite a lot of time there) and I feel totally OK about it.
That's probably because I'm quite tired and my brain switched to some 'lazy' mode or something like that, or maybe I'm just getting old. :) I hope I will be feeling same on the long way home.
One more thing I have to learn is how to sleep in a plane.
Moreover, being in bart also doesn't bother me much. I don't use laptop, I don't read books -- not because I don't bring them, I always have it in my bag, but just because I enjoy looking through the window (even though I've seen everything quite a lot of time there) and I feel totally OK about it.
That's probably because I'm quite tired and my brain switched to some 'lazy' mode or something like that, or maybe I'm just getting old. :) I hope I will be feeling same on the long way home.
One more thing I have to learn is how to sleep in a plane.
Labels:
personal
Sunday, November 1, 2009
About St. Petersburg trip
Yesterday night I've returned from St. Petersburg trip I previously wrote about. It takes 25 hours on train to get there (and the same from there to home). Quite a lot of time, but really, not very painful. I've spend about 2 weeks there.
Right from the train we went to the office, it's only 1 subway station away from the rails station. This part of the city is really beautiful. Here's a picture of the office building:

The view of the street leading to the office:

Very nice.
In the evening we've checked in into the hotel. The room is small but accurate:

The only problem with that was the furniture. I cannot even say it is uncomfortable, but it's strange, I mean, I wasn't able to sit or lay comfortably. Also, pillows were unusually small. Anyway, it's just a whim, stuff was generally good for a hotel.
Initially, I thought I will visit various interesting places in SPb - museums, parks, palaces and stuff like that. Later on, I've realized that I've visited them lots of time before but I still don't have an overview of the city. So this time I was just walking on the streets.
I've made some photos of the places I like. I guess they don't have any value from the photographer's point of view, but probably they will make you want visit SPb or at least find a better photos :)






Great city, like it so much :-)
One more good thing about it -- your shoes stays clean even if it's raining everyday. Obviously, it's because the city is very clean.
Ah, I definitely want to visit it again.
PS Here's my bag:

I've managed to cram all my stuff into it and it looks like a giant pregnant bee. Looks even more funnier on my back: imagine a person being shagged by a giant bee, haha.
Right from the train we went to the office, it's only 1 subway station away from the rails station. This part of the city is really beautiful. Here's a picture of the office building:
The view of the street leading to the office:
Very nice.
In the evening we've checked in into the hotel. The room is small but accurate:
The only problem with that was the furniture. I cannot even say it is uncomfortable, but it's strange, I mean, I wasn't able to sit or lay comfortably. Also, pillows were unusually small. Anyway, it's just a whim, stuff was generally good for a hotel.
Initially, I thought I will visit various interesting places in SPb - museums, parks, palaces and stuff like that. Later on, I've realized that I've visited them lots of time before but I still don't have an overview of the city. So this time I was just walking on the streets.
I've made some photos of the places I like. I guess they don't have any value from the photographer's point of view, but probably they will make you want visit SPb or at least find a better photos :)
Great city, like it so much :-)
One more good thing about it -- your shoes stays clean even if it's raining everyday. Obviously, it's because the city is very clean.
Ah, I definitely want to visit it again.
PS Here's my bag:
I've managed to cram all my stuff into it and it looks like a giant pregnant bee. Looks even more funnier on my back: imagine a person being shagged by a giant bee, haha.
Labels:
trip
Subscribe to:
Posts (Atom)