~ubuntu-branches/ubuntu/trusty/python-boto/trusty

« back to all changes in this revision

Viewing changes to tests/mturk/cleanup_tests.py

  • Committer: Package Import Robot
  • Author(s): Eric Evans
  • Date: 2012-04-15 20:21:21 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20120415202121-3fpf6q355s0xqpyu
Tags: 2.3.0-1
* New upstream release (Closes: #664478)
* Update debian/watch for Boto's move to Github.  Thanks Scott
  Moser. (Closes: #650480)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import itertools
 
2
 
 
3
from _init_environment import SetHostMTurkConnection
 
4
 
 
5
def description_filter(substring):
 
6
        return lambda hit: substring in hit.Title
 
7
 
 
8
def disable_hit(hit):
 
9
        return conn.disable_hit(hit.HITId)
 
10
 
 
11
def dispose_hit(hit):
 
12
        # assignments must be first approved or rejected
 
13
        for assignment in conn.get_assignments(hit.HITId):
 
14
                if assignment.AssignmentStatus == 'Submitted':
 
15
                        conn.approve_assignment(assignment.AssignmentId)
 
16
        return conn.dispose_hit(hit.HITId)
 
17
 
 
18
def cleanup():
 
19
        """Remove any boto test related HIT's"""
 
20
 
 
21
        global conn
 
22
        
 
23
        conn = SetHostMTurkConnection()
 
24
 
 
25
 
 
26
        is_boto = description_filter('Boto')
 
27
        print 'getting hits...'
 
28
        all_hits = list(conn.get_all_hits())
 
29
        is_reviewable = lambda hit: hit.HITStatus == 'Reviewable'
 
30
        is_not_reviewable = lambda hit: not is_reviewable(hit)
 
31
        hits_to_process = filter(is_boto, all_hits)
 
32
        hits_to_disable = filter(is_not_reviewable, hits_to_process)
 
33
        hits_to_dispose = filter(is_reviewable, hits_to_process)
 
34
        print 'disabling/disposing %d/%d hits' % (len(hits_to_disable), len(hits_to_dispose))
 
35
        map(disable_hit, hits_to_disable)
 
36
        map(dispose_hit, hits_to_dispose)
 
37
 
 
38
        total_hits = len(all_hits)
 
39
        hits_processed = len(hits_to_process)
 
40
        skipped = total_hits - hits_processed
 
41
        fmt = 'Processed: %(total_hits)d HITs, disabled/disposed: %(hits_processed)d, skipped: %(skipped)d'
 
42
        print fmt % vars()
 
43
 
 
44
if __name__ == '__main__':
 
45
        cleanup()