Пример #1
0
 def test_L_wrong_file01(self, tmpdir: py.path.local) -> None:
     "A loggingconfig file containing a list should raise an error"
     fname = str(tmpdir.join('/bla.yaml'))
     data = [1, 2, 3, 4]
     yamlutil.writeyamlfile(data, fname)
     with pytest.raises(RuntimeError):
         serverconfig.read_logging_config(fname)
Пример #2
0
 def setup_class(cls) -> None:
     lverb = True
     if lverb:
         print("SETUP CLASS {}".format(cls))
     cls.faulty_session = FaultySession(TESTqai_url)
     # --
     cls.s = TrackerSession(TESTqai_url)
     cls.s.login(TESTauth_uname, TESTauth_password)
     if not cls.s.is_logged_in():
         raise RuntimeError("login failed")
     rcode, cls.reagent_list = cls.s.get_json(PATH_REAGENT_LIST_REAGENTS)
     assert rcode == HTTP_OK, "called failed"
     # get list of suppliers
     rcode, cls.supplierlst = cls.s.get_json(PATH_REAGENT_LIST_SUPPLIERS)
     assert rcode == HTTP_OK, "called failed"
     if lverb:
         yamlutil.writeyamlfile(cls.supplierlst, "./supplierlst.yaml")
     # lets choose a supplier from the list. Choose the first name in the list.
     cls.selected_supplier_dct = cls.supplierlst[0]
     # retrieve the list of locations and choose some for testing.
     rcode, cls.loclst = cls.s.get_json(PATH_LOCATION_LIST)
     assert rcode == HTTP_OK, "called failed"
     if lverb:
         yamlutil.writeyamlfile(cls.loclst, "./loclist.yaml")
     nameset = frozenset(['SPH\\604\\Research Fridge', 'SPH\\605\\Fridge'])
     cls.testlocs = [d for d in cls.loclst if d['name'] in nameset]
     if len(cls.testlocs) != len(nameset):
         print("loclst '{}'".format(cls.loclst))
         raise RuntimeError("error finding location names {}".format(nameset))
     cls.establish_test_reagent()
Пример #3
0
 def test_S_wrong_file02(self, tmpdir: py.path.local) -> None:
     "A serverconfig file with missing keywords should raise an error."
     fname = str(tmpdir.join('/bla.yaml'))
     dd = dict(VERSION=99)
     yamlutil.writeyamlfile(dd, fname)
     with pytest.raises(RuntimeError):
         serverconfig.read_server_config(fname)
Пример #4
0
 def test_S_wrong_file01(self, tmpdir: py.path.local) -> None:
     "A serverconfig file containing an unknown keyword should raise an error."
     fname = str(tmpdir.join('/bla.yaml'))
     dd = dict(FUNNY=99)
     yamlutil.writeyamlfile(dd, fname)
     with pytest.raises(RuntimeError):
         serverconfig.read_server_config(fname)
Пример #5
0
 def test_L_wrong_file03(self, tmpdir: py.path.local) -> None:
     "A loggingconfig file containing a single dict should pass."
     fname = str(tmpdir.join('/bla.yaml'))
     data = dict(a=1, b=2, gg=77)
     yamlutil.writeyamlfile(data, fname)
     retval = serverconfig.read_logging_config(fname)
     assert retval == data, "failed to read back data"
Пример #6
0
 def test_S_wrong_file03(self, tmpdir: py.path.local) -> None:
     "A serverconfig file containing a list should raise an error."
     fname = str(tmpdir.join('/bla.yaml'))
     dd = dict(a=1, b=2, gg=77)
     data = [1, 2, 3, 4, dd]
     yamlutil.writeyamlfile(data, fname)
     with pytest.raises(RuntimeError):
         serverconfig.read_server_config(fname)
Пример #7
0
    def establish_test_reagent(cls):
        lverb = True
        # next, retrieve the list of users and choose our testing user.
        rcode, userlst = cls.s.get_json(PATH_USER_LIST)
        assert rcode == HTTP_OK, "called failed"
        if lverb:
            yamlutil.writeyamlfile(userlst, "./userlst.yaml")
        cls.test_user_login = '******'
        fndlst = [d for d in userlst if d['login'] == cls.test_user_login]
        if len(fndlst) != 1:
            print("userlst: {}".format(userlst))
            raise RuntimeError('failed to find test user')
        cls.test_user = fndlst[0]
        test_user_id = cls.test_user['id']
        cls.test_stat_lst = [
            {'status': 'MADE',
             'occurred': '1956-03-31T00:00:00Z',
             'qcs_user_id': test_user_id},
            {'status': 'EXPIRED',
             'occurred': '1956-03-31T00:00:00Z',
             'qcs_user_id': test_user_id},
            {'status': 'RUO_EXPIRED',
             'occurred': '1956-03-31T00:00:00Z',
             'qcs_user_id': test_user_id}]

        cls.test_reagent_item_lot_num = 'testlotAAA'
        cls.test_reagent_item_notes = "A fictitious stock item for software testing purposes"
        cls.test_itema_rfid = random_string(8)
        # --- create or retrieve a test reagent
        cls.test_reagent_name = "Whisky-Cola"
        cls.test_reagent_catnum = '9999'
        cls.test_reagent_id = None
        # if we have a reagent of this name, lets use it
        fndlst = [d for d in cls.reagent_list if d['name'] == cls.test_reagent_name]
        if len(fndlst) > 0:
            if lverb:
                print("found a test reagent {}".format(fndlst[0]))
            cls.test_reagent_id = fndlst[0]['id']
        else:
            pdct = {'basetype': 'stockchem',
                    'name': cls.test_reagent_name,
                    'category': 'Other Chemicals',
                    'notes': 'essential equipment',
                    'storage': '',
                    'needs_validation': None,
                    'expiry_time': 30,
                    'supplier': cls.selected_supplier_dct['name'],
                    'catalog_number': cls.test_reagent_catnum,
                    'date_msds_expires': 'never',
                    'msds_filename': ''}
            rcode, postres = cls.s.post_json(TPATH_REAGENT_SAVE, data=pdct, retries=1)
            if lverb:
                print("POSTreagent save {}".format(postres))
            assert rcode == HTTP_CREATED, "call failed"
            cls.test_reagent_id = postres['id']
        print("goot ID {}".format(cls.test_reagent_id))
        assert cls.test_reagent_id is not None, "cannot get test reagent id"
Пример #8
0
 def check_dump(self, fname: str, data: typing.Any, lverb: bool) -> None:
     """Dump some data, read it back and compare to the original"""
     yamlutil.writeyamlfile(data, fname)
     if lverb:
         with open(fname, "r") as fi:
             print("the file is '{}'".format(fi.read()))
     # now read it back and compare
     newnn = yamlutil.readyamlfile(fname)
     print("new time is {}".format(newnn))
     assert data == newnn, "saved and restored data is not equal!"
Пример #9
0
 def test_reagent_list_and_show01(self):
     """Get information about a specific reagent"""
     lverb = True
     reagent_id = self.test_reagent_id
     reagent_name = self.test_reagent_name
     pdct = {'id': reagent_id}
     rcode, reagent_show = self.s.get_json(PATH_REAGENT_SHOW, params=pdct)
     assert rcode == HTTP_OK, "call failed"
     if lverb:
         print("showing reagent: '{}: '{}".format(reagent_id, reagent_name))
         for dat, fn in [(reagent_show, "./reagentshow.yaml")]:
             yamlutil.writeyamlfile(dat, fn)
Пример #10
0
 def test_location_items(self):
     """Find all reagents at a specific location"""
     lverb = False
     selected_loc = self.testlocs[0]
     loc_id = selected_loc['id']
     loc_name = selected_loc['name']
     query_dct = {'id': loc_id}
     if lverb:
         print("search for reagents at locid {}: '{}'".format(loc_id, loc_name))
     rcode, rlst = self.s.get_json(PATH_REAGENT_LOCITEMS, params=query_dct)
     assert rcode == HTTP_OK, "call failed"
     if lverb:
         print("goot {}".format(rlst))
         for dat, fn in [(rlst, "./locitems.yaml")]:
             yamlutil.writeyamlfile(dat, fn)
Пример #11
0
 def test_S_wrong_values01(self, tmpdir: py.path.local) -> None:
     "A serverconfig file with the wrong values should raise an error."
     fname = str(tmpdir.join('/bla.yaml'))
     dd = serverconfig.read_server_config(
         get_testfilename('test02.OK.yaml'))
     # remove keys that are not meant to be on file...
     dnew = dict(
         [tt for tt in dd.items() if tt[0] in serverconfig.known_set])
     for k, brokenval in [('VERSION', serverconfig.VERSION_FLT + 0.1),
                          ('RFID_REGION_CODE', 'blaa'), ('TIME_ZONE', '?'),
                          ('TIME_ZONE', 'moon')]:
         # with mock.patch.dict(dnew, values={k: brokenval}):
         with mock.patch.dict(dnew, {k: brokenval}):
             yamlutil.writeyamlfile(dnew, fname)
             with pytest.raises(RuntimeError):
                 serverconfig.read_server_config(fname)
Пример #12
0
 def test_qai_dump02(self):
     ds = self.s.get_qai_dump()
     assert isinstance(ds, qai_helper.QAIDataset), "QAIDataset expected"
     yamlutil.writeyamlfile(ds, QAI_DUMP_FILE)
Пример #13
0
 def create_test_reagent(cls) -> None:
     """Create some test data to play with.
     If the following do not already exist in the database, we
     create a reagent, and a reagent item.
     """
     lverb = True
     rcode, cls.reagent_dct = cls.s.get_json(PATH_REAGENT_LIST)
     assert rcode == HTTP_OK, "called failed"
     if lverb:
         yamlutil.writeyamlfile(cls.reagent_dct, "./reagentlst.yaml")
     cls.reagent_lst = cls.reagent_dct['items']
     cls.establish_test_reagent()
     # --- create some reagent items
     # see whether we have a reagent item with this rfid: create one if not, and set
     # the item_id
     cls.test_itema_id = None
     cls.test_itema_locid = None
     rcode, reagitemlst = cls.s.get_json(PATH_REAGITEM_LIST,
                                         params=dict(id=cls.test_reagent_id))
     assert rcode == HTTP_OK, "call to PATH_REAGITEM_LIST failed"
     if lverb:
         yamlutil.writeyamlfile(reagitemlst, "./reagitemlst.yaml")
     fndlst = [d for d in reagitemlst if d['rfid'] == cls.test_itema_rfid]
     if len(fndlst) == 0:
         # if there are items, but not one with the expected RFID, then modify the RFID
         # of a record
         cls.test_itema_locid = cls.testlocs[0]['id']
         if len(reagitemlst) > 0:
             print("setting location")
             cls.setlocation(reagitemlst[0]['id'], cls.test_itema_locid)
             print("SETTING RFID\n")
             cls.setRFID(reagitemlst[0]['id'], cls.test_itema_rfid)
         else:
             # create a reagent item
             print("setting new location to {}".format(cls.test_itema_locid))
             itema = {'rfid': cls.test_itema_rfid,
                      'qcs_reag_id': cls.test_reagent_id,
                      'qcs_location_id': cls.test_itema_locid,
                      'lot_num': cls.test_reagent_item_lot_num,
                      'notes': cls.test_reagent_item_notes,
                      'source_ids': [],
                      'statuses': cls.test_stat_lst}
             rcode, res = cls.s.post_json(TPATH_REAGENT_ITEM, data={'items': [itema]})
             assert rcode == HTTP_CREATED, "called failed"
             print("postres '{}'".format(res))
         itm_rec = cls.get_reagent_item_record(cls.test_itema_rfid, isrfid=True)
         cls.test_itema_id = itm_rec['id']
         print('LOC2 {}'.format(itm_rec))
         # raise RuntimeError("Stopping for a test")
     else:
         print("Found item with required RFID")
         assert len(fndlst) == 1, "Database Error: multiple items with same RFID"
         # ensure the required state of an existing reagent item
         print("BLAREC {}".format(fndlst[0]))
         cls.test_itema_id = fndlst[0]['id']
         print("looking for item {}".format(cls.test_itema_id))
         itm_rec = cls.get_reagent_item_record(cls.test_itema_id)
         print("Found required item")
         # ensure that the reagent item is MADE, not IN_USE
         if itm_rec['current_status'] == 'IN_USE':
             res = cls.s.delete_json(PATH_REAGITEM_STATUS,
                                     params=dict(qcs_reag_item_id=cls.test_itema_id,
                                                 status='IN_USE'))
             print("got res {}".format(res))
             itm_rec = cls.get_reagent_item_record(cls.test_itema_id)
         assert itm_rec['current_status'] == 'MADE', 'made status expected'
         cls.test_itema_locid = itm_rec['loc_id']
         # ensure the RFID is what the tests expected
         # if itm_rec['rfid'] != cls.test_itema_rfid:
         #    rcode, res = cls.s.patch_json(TPATH_REAGENT_ITEM,
         #                                  data=dict(id=cls.test_itema_id,
         #                                            rfid=cls.test_itema_rfid))
         #    assert rcode == HTTP_OK, "called failed"
         #    itm_rec = cls.get_reagent_item_record(cls.test_itema_id)
         assert itm_rec['rfid'] == cls.test_itema_rfid, "failed to set RFID"
     print("ITEMREC IS {}".format(itm_rec))
     if itm_rec['loc_id'] is None:
         print("setting item location")
         cls.test_itema_locid = cls.testlocs[0]['id']
         cls.setlocation(cls.test_itema_id, cls.test_itema_locid)
     assert cls.test_itema_id is not None, "failed to determine itema_id"
     assert cls.test_itema_locid is not None, "failed to determine itema_locid"