tdd/lab-workbook.rst
author Madhusudan.C.S <madhusudancs@gmail.com>
Tue, 07 Sep 2010 16:49:56 +0530
changeset 129 6e237b9442cd
parent 128 29e6b1d5e5f5
child 130 e5d183dce985
permissions -rw-r--r--
Adding a huge question for lab exercise 4.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
126
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
======================================
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
Lab Workbook - Test Driven Development
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
======================================
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
The notation that follows every question denotes the level on the
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
Revised Bloom's Taxonomy.
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
Lab - 1
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
=======
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
  1. Write a stub function for calculating the LCM of two numbers.
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
  2. Write the tests for the LCM function, place the tests in if
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
     __name__ == '__main__': part of the Python file. Demonstrate that
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
     the tests fail.
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
  3. Implement the code for the LCM function, using the gcd function
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
     provided in the examples in the chapter. Demonstrate the tests
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
     pass. (For the algorithm refer to Wikipedia - [0])
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
  4. Alternatively, build a set of test cases, preferably a large
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
     number of cases, place it in a text file and use these test cases
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
     to test your LCM function. Demonstrate that tests still continue
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
     to pass.
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
[0] - http://en.wikipedia.org/wiki/Least_common_multiple#Reduction_by_the_greatest_common_divisor
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
Lab - 2
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
=======
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
127
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    28
  1. Write the stub function, followed by the tests(demonstrating the
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    29
     failed tests), in turn followed by the code(demonstrating the
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    30
     passing tests) to calculate the number of days between two
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    31
     dates. Name your function num_of_days(). The function should take
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    32
     two arguments, both being tuples. Each tuple represents the date
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    33
     in the format of (dd, mm, yyyy) where dd, mm and yyyy are
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    34
     integers.
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    35
  2. Rewrite the num_of_days() function to take the start date as an
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    36
     optional argument. If the start date is not specified calculate
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    37
     the number of days between the only specified date since Unix
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    38
     epoch. Prior to manipulating the code to do this, make sure you
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    39
     change the tests, make them fail and then refactor the code.
126
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
Lab -3
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
======
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
128
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    45
  1. Move the tests that were written to GCD function in the examples
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    46
     of this chapter to a separate function called test_gcd(). Do the
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    47
     same for LCM function and num_of_days() function. Make sure when
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    48
     the respective Python files are executed as stand alone scripts
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    49
     these tests executed.
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    50
  2. Put all these files in a single directory called utils and run
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    51
     the nosetests command. Make a report of the results.
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    52
  3. Write doctests to each of the above functions. Demonstrate and
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    53
     report the results as executed by running the doctests using
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    54
     doctest.testmod() function and using nosetests command.
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    55
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    56
Lab - 4
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    57
=======
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    58
129
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    59
  1. Consider the following use case: We are given a large list of
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    60
     items called *data* where each item is a again a list with three
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    61
     values: username, which is a string; status of the user which
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    62
     can be one of the following three strings 'new', 'valid' or
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    63
     'invalid'; and the last login time which is a datetime Python
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    64
     object.  Write a function called **query** that takes a filter
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    65
     dictionary as a parameter and returns the result of the items in
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    66
     the *data* list. They keys of the dictionary can be 'user',
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    67
     'status' and 'logtime' and their corresponding values can be any
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    68
     of the valid values for the corresponding key. Example filter
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    69
     dictionary::
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    70
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    71
       filter = {
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    72
           'user': 'john'
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    73
           'status': 'new'
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    74
           }
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    75
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    76
     Place your function in a file called query.py. Before writing the
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    77
     actual function, follow the test driven development
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    78
     approach. First write a stub, fail the tests and then write the
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    79
     code and make sure the tests pass. Specifically use unittest
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    80
     framework to test this function. Place your tests in a file
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    81
     called test_query.py
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    82
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    83
     A developer wrote a small utility function in a file named
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    84
     user_utils.py which uses your **query** function which looks as
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    85
     follows::
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    86
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    87
       def login_util(user=None):
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    88
           """Takes a user name and returns his last login time if the
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    89
           user is a valid user, else return None. If the user is
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    90
           'host' it returns the last login time of all the users.
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    91
           """
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    92
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    93
           filter_dict = {
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    94
               'user': user
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    95
               'status': 'active'
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    96
               }
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    97
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    98
           if user == 'host':
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    99
               filter_dict['status'] + ['new', 'invalid']
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   100
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   101
           return query(filter_dict)
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   102
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   103
     Unfortunately the developer did not provide us with the test
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   104
     cases. We wrote the following test cases for you to only discover
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   105
     that the function miserably fails. 
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   106
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   107
     The tests were placed in a file called test_user_utils.py and we
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   108
     have used the unittest framework::
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   109
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   110
       import query
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   111
       import user_utils
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   112
       import unittest
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   113
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   114
       class TestUserUtils(unittest.TestCase):
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   115
        
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   116
           def setUp(self):
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   117
               """Boiler plate method to provide common data to all
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   118
               the test methods.
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   119
               """
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   120
               self.test_names = ['Alex', 'Guido', 'Thomas', 'host',
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   121
                   'Tom', 'James']
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   122
               self.data_len = len(query.data)
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   123
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   124
           def test_login_utils(self):
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   125
               """Tests for the login_utils function.
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   126
               """
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   127
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   128
               for name in self.test_names:
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   129
                   if name == 'host':
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   130
                       assertEqual(len(user_utils.login_utils(name)), self.data_len)
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   131
                   else:
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   132
                       assertLess(len(user_utils.login_utils(name)), self.data_len)
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   133
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   134
           def tearDown(self):
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   135
               """Boiler plate method to clean up all the data created
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   136
               for tests.
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   137
               """
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   138
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   139
               del self.test_names
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   140
               del self.data_len
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   141
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   142
     Fix the bug, run the tests to make sure the function passes the
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   143
     tests and if possible refactor the code with a better approach.