예제 #1
0
    def test_create_ag_kits(self):
        with self.assertRaises(ValueError):
            db.create_ag_kits([(1, 9999999999)])
        db.create_barcodes(15)
        kits = db.create_ag_kits([(1, 2), (5, 2)])

        obs = db._con.execute_fetchall("SELECT * from ag.ag_handout_kits")
        self.assertEqual(len(obs), 5)

        obs = db._con.execute_fetchall("SELECT * from ag.ag_handout_barcodes")
        self.assertEqual(len(obs), 15)
예제 #2
0
    def test_create_ag_kits(self):
        with self.assertRaises(ValueError):
            db.create_ag_kits([(1, 9999999999)])
        db.create_barcodes(15)
        kits = db.create_ag_kits([(1, 2), (5, 2)])

        obs = db._con.execute_fetchall("SELECT * from ag.ag_handout_kits")
        self.assertEqual(len(obs), 5)

        obs = db._con.execute_fetchall("SELECT * from ag.ag_handout_barcodes")
        self.assertEqual(len(obs), 15)
예제 #3
0
    def test_remaining_barcodes(self):
        with self.assertRaises(ValueError):
            db.remaining_barcodes(999999999999)

        barcodes = db.remaining_barcodes()
        exp = []
        self.assertEqual(barcodes, exp)

        db.create_barcodes(5)

        barcodes = db.remaining_barcodes()
        exp = ['000010861', '000010862', '000010863', '000010864', '000010865']
        self.assertEqual(barcodes, exp)

        barcodes = db.remaining_barcodes(2)
        self.assertEqual(barcodes, ['000010861', '000010862'])
예제 #4
0
    def test_remaining_barcodes(self):
        with self.assertRaises(ValueError):
            db.remaining_barcodes(999999999999)

        barcodes = db.remaining_barcodes()
        exp = []
        self.assertEqual(barcodes, exp)

        db.create_barcodes(5)

        barcodes = db.remaining_barcodes()
        exp = ['000010861', '000010862', '000010863', '000010864', '000010865']
        self.assertEqual(barcodes, exp)

        barcodes = db.remaining_barcodes(2)
        self.assertEqual(barcodes, ['000010861', '000010862'])
예제 #5
0
    def test_get_unassigned_barcodes(self):
        with self.assertRaises(ValueError):
            db.get_unassigned_barcodes(999999999)

        obs = db.get_unassigned_barcodes()
        self.assertEqual(obs, [])
        barcodes = db.create_barcodes(3)
        obs = db.get_unassigned_barcodes()
        self.assertEqual(obs, barcodes)
        obs = db.get_unassigned_barcodes(1)
        self.assertEqual(obs, [barcodes[0]])
예제 #6
0
    def test_get_unassigned_barcodes(self):
        with self.assertRaises(ValueError):
            db.get_unassigned_barcodes(999999999)

        obs = db.get_unassigned_barcodes()
        self.assertEqual(obs, [])
        barcodes = db.create_barcodes(3)
        obs = db.get_unassigned_barcodes()
        self.assertEqual(obs, barcodes)
        obs = db.get_unassigned_barcodes(1)
        self.assertEqual(obs, [barcodes[0]])
예제 #7
0
    def test_create_barcodes(self):
        con = db._con
        sql_bc = "SELECT barcode FROM barcode"
        bc = [['000000001'], ['000000002'], ['000000003'], ['000000004'],
              ['000006616'], ['000010860']]

        barcodes = db.create_barcodes(3)
        self.assertEqual(barcodes, ['000010861', '000010862', '000010863'])

        bc.extend([['000010861'], ['000010862'], ['000010863']])
        obs = con.execute_fetchall(sql_bc)
        self.assertItemsEqual(obs, bc)
예제 #8
0
    def test_create_barcodes(self):
        con = db._con
        sql_bc = "SELECT barcode FROM barcode"
        bc = [['000000001'], ['000000002'], ['000000003'], ['000000004'],
              ['000006616'], ['000010860']]

        barcodes = db.create_barcodes(3)
        self.assertEqual(barcodes, ['000010861', '000010862', '000010863'])

        bc.extend([['000010861'], ['000010862'], ['000010863']])
        obs = con.execute_fetchall(sql_bc)
        self.assertItemsEqual(obs, bc)
예제 #9
0
    def post(self):
        # create barcodes
        msg = ""
        newbc = []
        assignedbc = []
        projects = []
        action = self.get_argument("action")
        num_barcodes = int(self.get_argument('numbarcodes'))

        if action == "create":
            newbc = db.create_barcodes(num_barcodes)
            msg = ("%d Barcodes created! Please wait for barcode download" %
                   num_barcodes)

        elif action == "assign":
            projects = [
                url_unescape(p).encode('utf-8')
                for p in self.get_arguments('projects')
            ]
            new_project = self.get_argument('newproject').strip()
            try:
                if new_project:
                    db.create_project(new_project)
                    projects.append(new_project)
                assignedbc = db.assign_barcodes(num_barcodes, projects)
            except ValueError as e:
                msg = u"ERROR! %s" % e.message
            else:
                projects = [p.decode('utf-8') for p in projects]
                tmp = u"%d barcodes assigned to %s, please wait for download."
                msg = tmp % (num_barcodes, ", ".join(projects))

        else:
            raise HTTPError(400, 'Unknown action: %s' % action)

        project_names = db.getProjectNames()
        remaining = len(db.get_unassigned_barcodes())
        self.render("ag_new_barcode.html",
                    currentuser=self.current_user,
                    projects=project_names,
                    remaining=remaining,
                    msg=msg,
                    newbc=newbc,
                    assignedbc=assignedbc,
                    assign_projects=", ".join(projects))
예제 #10
0
    def post(self):
        # create barcodes
        msg = ""
        newbc = []
        assignedbc = []
        projects = []
        action = self.get_argument("action")
        num_barcodes = int(self.get_argument('numbarcodes'))

        if action == "create":
            newbc = db.create_barcodes(num_barcodes)
            msg = ("%d Barcodes created! Please wait for barcode download"
                   % num_barcodes)

        elif action == "assign":
            projects = [url_unescape(p).encode('utf-8')
                        for p in self.get_arguments('projects')]
            new_project = self.get_argument('newproject').strip()
            try:
                if new_project:
                    db.create_project(new_project)
                    projects.append(new_project)
                assignedbc = db.assign_barcodes(num_barcodes, projects)
            except ValueError as e:
                msg = u"ERROR! %s" % e.message
            else:
                projects = [p.decode('utf-8') for p in projects]
                tmp = u"%d barcodes assigned to %s, please wait for download."
                msg = tmp % (num_barcodes, ", ".join(projects))

        else:
            raise HTTPError(400, 'Unknown action: %s' % action)

        project_names = db.getProjectNames()
        remaining = len(db.get_unassigned_barcodes())
        self.render("ag_new_barcode.html", currentuser=self.current_user,
                    projects=project_names, remaining=remaining,
                    msg=msg, newbc=newbc, assignedbc=assignedbc,
                    assign_projects=", ".join(projects))