Esempio n. 1
0
    def test_create(self):
        # This tests the create type, create function and accessing the
        # attributes
        Equipment.create_type('Test Equipment Type')
        obs = Equipment.create('Test Equipment Type', 'New Equipment')
        self.assertEqual(obs.external_id, 'New Equipment')
        self.assertEqual(obs.equipment_type, 'Test Equipment Type')
        self.assertIsNone(obs.notes)
        obs.notes = 'New notes'
        self.assertEqual(obs.notes, 'New notes')

        # Test creation failure due to non-existent type
        self.assertRaises(LabmanUnknownIdError, Equipment.create,
                          'Non-existent Equipment Type', 'New Equipment 2')

        # Test creation failure due to duplicated external id
        self.assertRaises(LabmanDuplicateError, Equipment.create,
                          'Test Equipment Type', 'New Equipment')
Esempio n. 2
0
    def test_create(self):
        # This tests the create type, create function and accessing the
        # attributes
        try:
            Equipment.create_type('Test Equipment Type')

            # Test type creation failure due to duplicated description
            self.assertRaises(LabmanDuplicateError, Equipment.create_type,
                              'Test Equipment Type')

            obs = Equipment.create('Test Equipment Type', 'New Equipment')
            self.assertEqual(obs.external_id, 'New Equipment')
            self.assertEqual(obs.equipment_type, 'Test Equipment Type')
            self.assertIsNone(obs.notes)
            obs.notes = 'New notes'
            self.assertEqual(obs.notes, 'New notes')

            # Test creation failure due to non-existent type
            self.assertRaises(LabmanUnknownIdError, Equipment.create,
                              'Non-existent Equipment Type', 'New Equipment 2')

            # Test creation failure due to duplicated external id
            self.assertRaises(LabmanDuplicateError, Equipment.create,
                              'Test Equipment Type', 'New Equipment')
        finally:
            # not in TearDown as this clean-up is specific to this test only;
            # running sql directly on the db from a test isn't pretty, but it
            # is still preferable to interdependence between tests.
            # Deletes both values that should have been added to db as well
            # as values whose add should have failed (just in case this test
            # failed by not preventing those additions).
            with sql_connection.TRN as TRN:
                sql = """DELETE
                         FROM labman.equipment
                         WHERE external_id in
                          ('New Equipment', 'New Equipment 2');
                         DELETE
                         FROM labman.equipment_type
                         WHERE description in ('Test Equipment Type',
                          'Non-existent Equipment Type');"""
                TRN.add(sql)
                TRN.execute()
Esempio n. 3
0
 def post(self):
     equipment_type = self.get_argument('equipment_type')
     external_id = self.get_argument('external_id')
     equipment = Equipment.create(equipment_type, external_id)
     self.write({'equipment': equipment.id})