~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to test_utility.py

  • Committer: seman.said at canonical
  • Date: 2015-07-20 17:17:45 UTC
  • mto: This revision was merged to the branch mainline in revision 1037.
  • Revision ID: seman.said@canonical.com-20150720171745-38gac67inz3pyocv
Added --all option to schedule all candidates for client-server testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
120
120
 
121
121
    def test_find_candidates_old_buildvars(self):
122
122
        with temp_dir() as root:
123
 
            candidates_path = get_candidates_path(root)
124
 
            os.mkdir(candidates_path)
125
 
            master_path = os.path.join(candidates_path, 'master')
126
 
            os.mkdir(master_path)
127
 
            buildvars_path = os.path.join(master_path, 'buildvars.json')
128
 
            open(buildvars_path, 'w')
 
123
            _, buildvars_path = self.make_candidates_dir(root, 'master')
129
124
            a_week_ago = time() - timedelta(days=7, seconds=1).total_seconds()
130
125
            os.utime(buildvars_path, (time(), a_week_ago))
131
126
            self.assertEqual(list(find_candidates(root)), [])
132
127
 
133
128
    def test_find_candidates_artifacts(self):
134
129
        with temp_dir() as root:
135
 
            candidates_path = get_candidates_path(root)
 
130
            self.make_candidates_dir(root, 'master-artifacts')
 
131
            self.assertEqual(list(find_candidates(root)), [])
 
132
 
 
133
    def test_find_candidates_find_all(self):
 
134
        with temp_dir() as root:
 
135
            master_path, buildvars_path = self.make_candidates_dir(
 
136
                root, '1.23')
 
137
            master_path_2, _ = self.make_candidates_dir(root, '1.24')
 
138
            a_week_ago = time() - timedelta(days=7, seconds=1).total_seconds()
 
139
            os.utime(buildvars_path, (time(), a_week_ago))
 
140
            self.assertItemsEqual(list(find_candidates(root)), [master_path_2])
 
141
            self.assertItemsEqual(list(find_candidates(root, find_all=True)),
 
142
                                  [master_path, master_path_2])
 
143
 
 
144
    def make_candidates_dir(self, root, master_name):
 
145
        candidates_path = get_candidates_path(root)
 
146
        if not os.path.isdir(candidates_path):
136
147
            os.mkdir(candidates_path)
137
 
            master_path = os.path.join(candidates_path, 'master-artifacts')
138
 
            os.mkdir(master_path)
139
 
            open(os.path.join(master_path, 'buildvars.json'), 'w')
140
 
            self.assertEqual(list(find_candidates(root)), [])
 
148
        master_path = os.path.join(candidates_path, master_name)
 
149
        os.mkdir(master_path)
 
150
        buildvars_path = os.path.join(master_path, 'buildvars.json')
 
151
        open(buildvars_path, 'w')
 
152
        return master_path, buildvars_path
141
153
 
142
154
 
143
155
class TestWaitForPort(TestCase):