def test_GIVEN_multiple_channels_WHEN_parse_THEN_have_mulitple_blocks_containing_all_info( self): expected_names = ["BLOCK1", "block_2", "block3"] expected_expected_connectivities = [True, True, False] given_values = ["0.001", "hello", "null"] given_units = ["mA", "", ""] expected_values = ["0.001 mA", "hello", "null"] expected_alarm = ["", "MINOR/LOW", ""] channels = [] for name, connectivity, value, units, alarm in zip( expected_names, expected_expected_connectivities, given_values, given_units, expected_alarm): channels.append( ArchiveMother.create_channel(name=name, is_connected=connectivity, units=units, alarm=alarm, value=value)) json = ArchiveMother.create_info_page(channels) parser = WebPageParser() result = parser.extract_blocks(json) assert_that(result, has_length(len(expected_names))) for name, connectivity, expected_value, alarm in zip( expected_names, expected_expected_connectivities, expected_values, expected_alarm): assert_that(result[name].get_name(), is_(name)) assert_that(result[name].get_alarm(), is_(alarm)) assert_that(result[name].is_connected(), is_(connectivity)) assert_that(result[name].get_description()["value"], is_(expected_value)) assert_that(result[name].get_visibility(), is_(True))
def test_GIVEN_display_set_to_something_weird_WHEN_parse_THEN_title_and_user_appear_as_unavailable( self): title_name = "DAE:TITLE.VAL" title_value = "a title" title_expected_value = InstrumentInformationCollator.PRIVATE_VALUE username_name = "DAE:_USERNAME.VAL" username_value = "username" username_expected_value = InstrumentInformationCollator.PRIVATE_VALUE display_name = "DAE:TITLE:DISPLAY.VAL" display_value = "Blah" channel_values = [ ArchiveMother.create_channel(name=title_name, value=title_value), ArchiveMother.create_channel(name=username_name, value=username_value), ArchiveMother.create_channel(name=display_name, value=display_value) ] self.reader.get_json_from_instrument_archive = Mock( return_value=ArchiveMother.create_info_page(channel_values)) result = self.scraper.collate() assert_that(result["inst_pvs"]["TITLE"]["value"], is_(title_expected_value)) assert_that(result["inst_pvs"]["_USERNAME"]["value"], is_(username_expected_value))
def test_GIVEN_one_channels_WHEN_parse_THEN_block_is_visible(self): expected_name = "BLOCK" json = ArchiveMother.create_info_page( [ArchiveMother.create_channel(expected_name)]) parser = WebPageParser() result = parser.extract_blocks(json) assert_that(result[expected_name].get_visibility(), is_(True))
def test_GIVEN_one_channels_WHEN_parse_THEN_blocks_contain_channel(self): expected_name = "BLOCK" json = ArchiveMother.create_info_page( [ArchiveMother.create_channel(expected_name)]) parser = WebPageParser() result = parser.extract_blocks(json) assert_that(result, has_length(1)) assert_that(result[expected_name].name, is_(expected_name))
def test_GIVEN_one_channels_in_alarm_WHEN_parse_THEN_block_has_alarm(self): expected_name = "BLOCK" expected_alarm = u"INVALID/UDF_ALARM" json = ArchiveMother.create_info_page([ ArchiveMother.create_channel(name=expected_name, alarm=expected_alarm) ]) parser = WebPageParser() result = parser.extract_blocks(json) assert_that(result[expected_name].get_alarm(), is_(expected_alarm))
def test_GIVEN_one_channels_has_value_WHEN_parse_THEN_block_has_value( self): expected_name = "BLOCK" expected_value = u"5.4" json = ArchiveMother.create_info_page([ ArchiveMother.create_channel(name=expected_name, value=expected_value) ]) parser = WebPageParser() result = parser.extract_blocks(json) assert_that(result[expected_name].get_value(), is_(expected_value))
def test_GIVEN_one_channels_with_value_with_incorrect_utf8_in_WHEN_parse_THEN_block_has_correct_utf8_in( self): expected_name = "BLOCK" value = u'mu \\u-062\\u-075' expected_value = u'mu \u00B5' # decimal 181 channel = ArchiveMother.create_channel(name=expected_name, value=value) del channel['Current Value']["Units"] json = ArchiveMother.create_info_page([channel]) parser = WebPageParser() result = parser.extract_blocks(json) assert_that(result[expected_name].get_description()["value"], is_(expected_value))
def test_GIVEN_title_is_hidden_WHEN_parse_but_no_display_or_username_THEN_no_title_or_username_exist( self): display_name = "DAE:TITLE:DISPLAY.VAL" display_value = "No" channel_values = [ ArchiveMother.create_channel(name=display_name, value=display_value) ] self.reader.get_json_from_instrument_archive = Mock( return_value=ArchiveMother.create_info_page(channel_values)) result = self.scraper.collate() assert_that(result["inst_pvs"], not_(has_key("TITLE"))) assert_that(result["inst_pvs"], not_(has_key("_USERNAME")))
def test_GIVEN_one_channels_is_disconnected_WHEN_parse_THEN_block_has_value_null( self): expected_name = "BLOCK" expected_connectivity = False expected_value = u"null" json = ArchiveMother.create_info_page([ ArchiveMother.create_channel(name=expected_name, value=expected_value, is_connected=expected_connectivity) ]) parser = WebPageParser() result = parser.extract_blocks(json) assert_that(result[expected_name].get_value(), is_(expected_value))
def test_GIVEN_one_channels_is_connected_WHEN_parse_THEN_block_is_connected_and_status_reflects_this( self): expected_name = "BLOCK" expected_connectivity = True expected_status = "Connected" json = ArchiveMother.create_info_page([ ArchiveMother.create_channel(name=expected_name, is_connected=expected_connectivity) ]) parser = WebPageParser() result = parser.extract_blocks(json) assert_that(result[expected_name].is_connected(), is_(expected_connectivity)) assert_that(result[expected_name].status, is_(expected_status))
def test_GIVEN_run_duraction_WHEN_parse_THEN_correctly_formatted_duration_returned( self): name = "DAE:RUNDURATION.VAL" value = 5025 units = "s" expected_value = "1 hr 23 min 45 s" self.reader.get_json_from_instrument_archive = Mock( return_value=ArchiveMother.create_info_page([ ArchiveMother.create_channel( name=name, value=value, units=units) ])) result = self.scraper.collate() assert_that(result["inst_pvs"]["RUNDURATION"]["value"], is_(expected_value))
def test_GIVEN_one_channels_is_disconnected_WHEN_parse_THEN_block_is_disconnected_and_status_reflects_this( self): expected_name = "BLOCK" expected_connectivity = False expected_status = "Disconnected" # Don't use constant this is the word expected in the js file. json = ArchiveMother.create_info_page([ ArchiveMother.create_channel(name=expected_name, is_connected=expected_connectivity) ]) parser = WebPageParser() result = parser.extract_blocks(json) assert_that(result[expected_name].is_connected(), is_(expected_connectivity)) assert_that(result[expected_name].status, is_(expected_status))
def test_GIVEN_no_channels_WHEN_parse_THEN_channels_are_blank(self): json = ArchiveMother.create_info_page([]) parser = WebPageParser() result = parser.extract_blocks(json) self.assertEqual(len(result), 0, "Length of result")
def test_GIVEN_displayed_title_as_utf8_characters_in_WHEN_parse_THEN_title_still_has_UTF8_characters_in( self): title_name = "DAE:TITLE.VAL" title_value = u"a title \u0302" display_name = "DAE:TITLE:DISPLAY.VAL" display_value = "Yes" channel_values = [ ArchiveMother.create_channel(name=title_name, value=title_value), ArchiveMother.create_channel(name=display_name, value=display_value) ] self.reader.get_json_from_instrument_archive = Mock( return_value=ArchiveMother.create_info_page(channel_values)) result = self.scraper.collate() assert_that(result["inst_pvs"]["TITLE"]["value"], is_(title_value))
def test_GIVEN_one_channels_with_units_WHEN_parse_THEN_block_has_units( self): expected_name = "BLOCK" units = u'uA hour' value = u'0.000' expected_value = "{} {}".format(value, units) json = ArchiveMother.create_info_page([ ArchiveMother.create_channel(name=expected_name, units=units, value=value) ]) parser = WebPageParser() result = parser.extract_blocks(json) assert_that(result[expected_name].get_description()["value"], is_(expected_value))
def test_GIVEN_one_channels_with_no_units_but_connected_WHEN_parse_THEN_block_has_units( self): """ e.g. CS:PS: PVs """ expected_name = "BLOCK" value = u'0.000' expected_value = "{}".format(value) channel = ArchiveMother.create_channel(name=expected_name, value=value) del channel['Current Value']["Units"] json = ArchiveMother.create_info_page([channel]) parser = WebPageParser() result = parser.extract_blocks(json) assert_that(result[expected_name].get_description()["value"], is_(expected_value))
def test_GIVEN_one_invalid_channels_WHEN_parse_THEN_no_blocks_returned( self): expected_name = "BLOCK" json = ArchiveMother.create_info_page([None]) parser = WebPageParser() result = parser.extract_blocks(json) assert_that(result, has_length(0))
def test_GIVEN_hidden_block_WHEN_parse_THEN_block_is_marked_as_visible( self): block_name = "block" group_name = "group1" expected_is_visible = False self.reader.get_json_from_blocks_archive = Mock( return_value=ArchiveMother.create_info_page( [ArchiveMother.create_channel(name=block_name)])) block = ConfigMother.create_block(block_name, is_visibile=expected_is_visible) group = ConfigMother.create_group(group_name, [block_name]) config = ConfigMother.create_config(blocks=[block], groups=[group]) self.reader.read_config = Mock(return_value=config) result = self.scraper.collate() assert_that(result["groups"][group_name][block_name]["visibility"], is_(expected_is_visible))
def setUp(self): self.reader = Mock() page_info = ArchiveMother.create_info_page([]) self.reader.get_json_from_blocks_archive = Mock(return_value=page_info) self.reader.get_json_from_dataweb_archive = Mock( return_value=page_info) self.reader.get_json_from_instrument_archive = Mock( return_value=page_info) config = ConfigMother.create_config() self.reader.read_config = Mock(return_value=config) self.scraper = InstrumentInformationCollator(reader=self.reader)
def test_GIVEN_display_is_yes_WHEN_parse_THEN_title_and_user_appear_as_set( self): title_name = "DAE:TITLE.VAL" title_value = "a title" username_name = "DAE:_USERNAME.VAL" username_value = "username" display_name = "DAE:TITLE:DISPLAY.VAL" display_value = "Yes" channel_values = [ ArchiveMother.create_channel(name=title_name, value=title_value), ArchiveMother.create_channel(name=username_name, value=username_value), ArchiveMother.create_channel(name=display_name, value=display_value) ] self.reader.get_json_from_instrument_archive = Mock( return_value=ArchiveMother.create_info_page(channel_values)) result = self.scraper.collate() assert_that(result["inst_pvs"]["TITLE"]["value"], is_(title_value)) assert_that(result["inst_pvs"]["_USERNAME"]["value"], is_(username_value))