Exemplo n.º 1
0
 def test_downloading_valid_calendars(self, instrument):
     # Handle the two test instruments that we put into the database,
     # which will raise an error because their url values are bogus
     if instrument.name in ['**REMOVED**', '**REMOVED**']:
         pass
     else:
         sc.fetch_xml(instrument)
Exemplo n.º 2
0
 def test_download_with_date(self):
     doc = etree.fromstring(
         sc.fetch_xml(instrument=instrument_db['**REMOVED**'],
                      dt_from=dt.fromisoformat('2018-11-13T00:00:00'),
                      dt_to=dt.fromisoformat('2018-11-13T23:59:59')))
     # This day should have one entry:
     assert len(doc.findall('entry')) == 1
Exemplo n.º 3
0
 def test_fetch_xml_only_dt_from(self):
     # at the time of writing this code (2020-06-26), there were 8 records
     # on the Hitachi S4700 after Jan 1. 2020, which should only increase
     # over time
     xml = sc.fetch_xml(instrument_db['**REMOVED**'],
                        dt_from=dt.fromisoformat('2020-01-01T00:00:00'))
     doc = etree.fromstring(xml)
     assert len(doc.findall('entry')) >= 8
Exemplo n.º 4
0
 def test_fetch_xml_calendar_event_no_entry(self):
     # tests when there is no matching event found
     xml = \
         sc.fetch_xml(instrument=instrument_db['**REMOVED**'],
                      dt_from=dt.fromisoformat('2010-01-01T00:00:00'),
                      dt_to=dt.fromisoformat('2010-01-01T00:00:01'))
     cal_event = sc.CalendarEvent.from_xml(xml)
     assert cal_event is None
Exemplo n.º 5
0
    def test_bad_request_response(self, monkeypatch):
        with monkeypatch.context() as m:

            class MockResponse(object):
                def __init__(self):
                    self.status_code = 404

            def mock_get(url, auth, verify):
                return MockResponse()

            # User bad username so we don't get a valid response or lock miclims
            m.setenv('nexusLIMS_user', 'bad_user')

            # use monkeypatch to use our version of get for requests that
            # always returns a 404
            monkeypatch.setattr(requests, 'get', mock_get)
            with pytest.raises(requests.exceptions.ConnectionError):
                sc.fetch_xml(instrument_db['**REMOVED**'])
Exemplo n.º 6
0
 def test_fetch_xml_calendar_event(self):
     xml = \
         sc.fetch_xml(instrument=instrument_db['**REMOVED**'],
                      dt_from=dt.fromisoformat('2018-11-13T00:00:00'),
                      dt_to=dt.fromisoformat('2018-11-13T23:59:59'))
     cal_event = sc.CalendarEvent.from_xml(xml)
     assert cal_event.title == 'Martensite search'
     assert cal_event.sharepoint_id == 470
     assert cal_event.username == '**REMOVED**'
     assert cal_event.start_time == dt.fromisoformat(
         '2018-11-13T09:00:00-05:00')
Exemplo n.º 7
0
 def test_download_date_w_multiple_entries(self):
     # This should return an event by '**REMOVED**' from 1PM to 5PM on 11/20/2019
     doc = etree.fromstring(
         sc.fetch_xml(instrument=instrument_db['**REMOVED**'],
                      dt_from=dt.fromisoformat('2019-11-20T13:40:20'),
                      dt_to=dt.fromisoformat('2019-11-20T17:30:00')))
     # This day should have one entry (pared down from three):
     assert len(doc.findall('entry')) == 1
     # entry should be user **REMOVED** and title "NexusLIMS computer testing"
     assert doc.find('entry/title').text == "NexusLIMS computer testing"
     assert doc.find(
         'entry/link[@title="UserName"]/'
         'm:inline/feed/entry/content/m:properties/d:UserName',
         namespaces=doc.nsmap).text == "**REMOVED**"
Exemplo n.º 8
0
def dry_run_get_calendar_event(s):
    """
    Get the calendar event that would be used to create a record based off
    the supplied session

    Parameters
    ----------
    s : ~nexusLIMS.db.session_handler.Session
        A session read from the database

    Returns
    -------
    cal_event : ~nexusLIMS.harvester.sharepoint_calendar.CalendarEvent
        A list of strings containing the files that would be included for the
        record of this session (if it were not a dry run)
    """
    xml = _sp_cal.fetch_xml(s.instrument, s.dt_from, s.dt_to)
    cal_event = _sp_cal.CalendarEvent.from_xml(xml)
    _logger.info(cal_event)
    return cal_event
Exemplo n.º 9
0
 def test_fetch_xml_only_dt_to(self):
     # There are five events prior to May 1, 2016 on the Hitachi S4700
     xml = sc.fetch_xml(instrument_db['**REMOVED**'],
                        dt_to=dt.fromisoformat('2016-05-01T00:00:00'))
     doc = etree.fromstring(xml)
     assert len(doc.findall('entry')) == 5
Exemplo n.º 10
0
 def test_fetch_xml_instrument_bogus(self, monkeypatch):
     with monkeypatch.context() as m:
         # use bad username so we don't get a response or lock miclims
         m.setenv('nexusLIMS_user', 'bad_user')
         with pytest.raises(ValueError):
             sc.fetch_xml(instrument=5)
Exemplo n.º 11
0
 def test_fetch_xml_instrument_none(self, monkeypatch):
     with monkeypatch.context() as m:
         # use bad username so we don't get a response or lock miclims
         m.setenv('nexusLIMS_user', 'bad_user')
         with pytest.raises(AuthenticationError):
             sc.fetch_xml(instrument_db['**REMOVED**'])
Exemplo n.º 12
0
 def test_bad_username(self, monkeypatch):
     with monkeypatch.context() as m:
         m.setenv('nexusLIMS_user', 'bad_user')
         with pytest.raises(AuthenticationError):
             sc.fetch_xml(instrument_db['**REMOVED**'])
Exemplo n.º 13
0
 def test_downloading_bad_calendar(self):
     with pytest.raises(KeyError):
         sc.fetch_xml('bogus_instr')