Tag Archives: python

>Unit Testing

>With apologies to The Monkeys

I thought unit tests were just for fairy tales
Never had the time to do things right
Going live was frantic
Development a drag
Changing all my code got real bad

Then I wrote my tests, now I’m a believer
Without a trace of doubt in my mind
I’m in love – mmmmmmm
I’m a believer, best thing I’ve ever tried

Ahem. Or something. I’ve just made substantial changes to two of our production systems over the last couple of weeks, but thanks to Andy and some stuff we did months ago in a pub, I have tests. They rock. Not saying they’ve nailed everything but certainly they’ve made a big difference.

The first system I changed it was remarkably painless and I felt remarkably confident. The second system was a bit more rushed but the go live had no major issues. The one issue that did crop up I changed on my test system here, ran the unit tests, watched them fail, fixed the code again, ran the tests again, watched them past, svn updated the live system and all was fine. Never felt in much panic and making the fixes was a much more pleasurable experience.

The only problem is – I can now see all the areas I don’t have tests for …

>Django OR statements / conditions


I’m having major problems focusing on one thing at a time at the moment. I thought that being in Japan would help me but it appears not. I’ve made some changes to how I work recently and I’m going to have a go at documenting what I’m doing with code and sysadmin stuff here. Partly as a brain dump for when I can’t remember how I did stuff and partly to see if it makes it stick in my brain. Past experience shows this won’t be something I keep up by anyway. Today I’m plodding through writing some Django code which is a rewrite of some pure python/sql stuff I did before. I know a lot of sql and therefore am having to force myself to try and use the Django API efficiently as much as possible (partly so I know when I shouldn’t use it). Todays question is how do I do OR statements.

Well according to the docs you setup Q objects. OK … I’ll stay calm. Here’s my current code.

    usages = Usage.objects.filter(parttype=parttypeid)
usages = usages.filter(client=self.client)

Just to point out that I’m doing two conditions here which are AND’ed together. Firstly to find any Usage record with a parttype of whatever parttypeid is and secondly to find any client which is the same as our client record. I could have given the first condition a PartType record or I could have given the second condition an id instead of a Client object. Although these two conditions are given in different lines they won’t be evaluated until I try and access the records at which point just one query will be thrown at the database. I also want to do an OR statement so that whatever is found in the above two statements much match. This is where I must use my Q object. Import it from django.db.models.Q


That looks like a long fieldname. Actually it’s some black magic that Django does for working across relationships. dockcode is a related table to usage, productionline is related to the dockcode table and destination is the actual destination we want to get to. They are double underscores to show you are referring to a related table. I don’t like the syntax but I can live with it for the moment. OK – but we want to look for two possible destination ids. So we end up with this

   qs = ( Q(dockcode__productionline__destination=destinationidA)|                  

And we just add that to our filter which we haven’t actually executed yet. So in total we end up with

    usages = Usage.objects.filter(parttype=parttypeid)
usages = usages.filter(client=self.client)
qs = ( Q(dockcode__productionline__destination=destinationidA)|
usages = usages.filter(qs)

That will return any usage record which has the given parttype, the given client and one of two possible destination ids. Well it will – when you try and access the result.

Repaying your Federal Student Loans

You don’t have to begin repaying your federal student loans until after you leave college or drop below half-time enrollment in your final year of undergraduate study. Paying them off sooner allows you to save money, meet your loans’ repayment goals and avoid default. But not paying them off yet can be difficult because it can mean you miss the payments your monthly federal loan payment is calculated to cover.

The Best Student Loans To Pay For Your MBA (Business School)

What if I don’t finish my federal loan obligations by the end of my current calendar year?

You might be able to avoid extra payments if you wait until after the end of the next calendar year to start repaying the full balance. If your loan balances are very large and interest is due on them each month, your interest wont be paid until you pay off all of your balance. Once the balance is paid off, the balance is removed from your federal student loan and you aren’t on the hook for it anymore. If you’d like to get all the details, be sure to look at this website.

Can I defer my loan payments if I am unable to repay them on time?

If you receive a deferment, your payments will continue to be taken from your paycheck, and interest will continue to accrue on your loans, unless you were enrolled in a Direct Loan Program that allows you to defer repayment after you reach a certain income level. A Direct Loan deferment is different from a Public Service Loan Forgiveness, where you receive the governments largest loan forgiveness program. The same repayment rules apply to the two types of deferments, including the ability to defer your federal loans when you’re unemployed. If you do not know whether you qualify for a deferment, you can inquire about them from the Repayment Estimator in the StudentLoans.gov website.

What if I meet the income requirements for the Public Service Loan Forgiveness program?

If you qualify for Public Service Loan Forgiveness and are currently in default, you can stop making payments and receive a Direct Loan disbursement. During the process of a Direct Loan disbursement, you will have the opportunity to establish new repayment plans with the U.S. Department of Education.

What if I meet the income requirements for a Pay As You Earn repayment plan?

If you qualify for a Pay As You Earn repayment plan and have non-Federal student loan debt, you can stop making payments and receive a Direct Loan disbursement. During the process of a Direct Loan disbursement, you will have the opportunity to establish new repayment plans with the U.S. Department of Education. You can also temporarily stop making payments if you have not made any payments on the current plan within two years of becoming eligible for the plan.