def test_date_format(self): create_static_files() self.selenium.get("{}/static/synoptic/{}/index.html".format( self.live_server_url, self.data.sg1.slug)) self.komboti_div_icon.wait_until_is_displayed() date = self.komboti_div_icon.find_element_by_tag_name("span") self.assertEqual(date.text, "22 Oct 2015 14:20")
def test_chart(self): # We will not compare a bitmap because it is unreliable; instead, we # will verify that an image was created and that the data that was used # in the image creation was correct. See # http://stackoverflow.com/questions/27948126#27948646 # Do the job create_static_files() # Check that it is a png of substantial length filename = os.path.join(settings.ENHYDRIS_SYNOPTIC_ROOT, "chart", str(self.sts2_2.id) + '.png') self.assertTrue(filename.endswith('.png')) self.assertGreater(os.stat(filename).st_size, 100) # Retrieve data datastr = open(filename.replace('png', 'dat')).read() self.assertTrue(datastr.startswith('(array(')) datastr = datastr.replace('array', 'np.array') data_array = eval(datastr) # Check that the data is correct def dt(y, mo, d, h, mi): adelta = datetime(y, mo, d, h, mi) - datetime(1, 1, 1) return adelta.days + 1 + adelta.seconds / 86400.0 desired_result = np.array([ [dt(2015, 10, 23, 15, 00), 40], [dt(2015, 10, 23, 15, 10), 39], [dt(2015, 10, 23, 15, 20), 38.5], ]) np.testing.assert_allclose(data_array, desired_result)
def test_up_to_date_date_shows_green(self): create_static_files() self.selenium.get("{}/static/synoptic/{}/index.html".format( self.live_server_url, self.data.sg1.slug)) self.komboti_div_icon.wait_until_is_displayed() date = self.komboti_div_icon.find_element_by_tag_name("span") self.assertEqual(date.get_attribute("class"), "date recent")
def test_uses_utf8_regardless_locale_setting(self): create_static_files() filename = os.path.join( settings.ENHYDRIS_SYNOPTIC_ROOT, self.data.sg1.slug, "station", str(self.data.sgs_agios.id), "index.html", ) self.assertHtmlContains(filename, "Άγιος Αθανάσιος")
def test_synoptic_station(self): create_static_files() filename = os.path.join(settings.ENHYDRIS_SYNOPTIC_ROOT, self.sg1.slug, "station", str(self.sgs2.id), 'index.html') self.assertHtmlContains(filename, text=textwrap.dedent( """\ <div class="panel panel-default"> <div class="panel-heading">Latest measurements</div> <div class="panel-body"> <dl class="dl-horizontal"> <dt>Last update</dt><dd>2015-10-23 15:20 EET (+0200)</dd> <dt> </dt><dd></dd> <dt>Rain</dt><dd>0.2 mm</dd> <dt>Air temperature</dt><dd>38.5 °C</dd> </dl> </div> </div> """))
def test_value_status(self): create_static_files() self.selenium.get("{}/static/synoptic/{}/index.html".format( self.live_server_url, self.data.sg1.slug)) self.layer_control.wait_until_is_displayed() self.layer_control.click() self.layer_control_rain.wait_until_is_displayed() # Rain should be ok self.layer_control_rain.click() value = self.komboti_div_icon.find_elements_by_tag_name("span")[1] self.assertEqual(value.get_attribute("class"), "value ok") # Wind gust should be high self.layer_control_wind_gust.click() value = self.komboti_div_icon.find_elements_by_tag_name("span")[1] self.assertEqual(value.get_attribute("class"), "value high") # Temperature should be low self.layer_control_temperature.click() value = self.komboti_div_icon.find_elements_by_tag_name("span")[1] self.assertEqual(value.get_attribute("class"), "value low")
def test_synoptic_group(self): create_static_files() filename = os.path.join(settings.ENHYDRIS_SYNOPTIC_ROOT, self.sg1.slug, 'index.html') self.assertHtmlContains(filename, text=textwrap.dedent( """\ <div class="panel panel-default"> <div class="panel-heading"> <a href="station/{}/">Komboti</a> </div> <div class="panel-body"> <dl class="dl-horizontal"> <dt>Last update</dt><dd>2015-10-22 15:20 EET (+0200)</dd> <dt> </dt><dd></dd> <dt>Rain</dt><dd>0 mm</dd> <dt>Air temperature</dt><dd>17 °C</dd> <dt>Wind (speed)</dt><dd>3.0 m/s</dd> <dt>Wind (gust)</dt><dd>4.1 m/s</dd> </dl> </div> </div> """.format(self.sgs1.id))) self.assertHtmlContains(filename, text=textwrap.dedent( """\ <div class="panel panel-default"> <div class="panel-heading"> <a href="station/{}/">Agios Athanasios</a> </div> <div class="panel-body"> <dl class="dl-horizontal"> <dt>Last update</dt><dd>2015-10-23 15:20 EET (+0200)</dd> <dt> </dt><dd></dd> <dt>Rain</dt><dd>0.2 mm</dd> <dt>Air temperature</dt><dd>38.5 °C</dd> </dl> </div> </div> """.format(self.sgs2.id)))
def test_grouped_chart(self): # Here we test the wind speed chart, which is grouped with wind gust. # See the comment in test_chart() above; the same applies here. # Do the job create_static_files() # Check that it is a png of substantial length filename = os.path.join(settings.ENHYDRIS_SYNOPTIC_ROOT, "chart", str(self.sts1_3.id) + '.png') self.assertTrue(filename.endswith('.png')) self.assertGreater(os.stat(filename).st_size, 100) # Retrieve data datastr = open(filename.replace('png', 'dat')).read() self.assertTrue(datastr.startswith('(array(')) datastr = datastr.replace('array', 'np.array') data_array = eval(datastr) # Check that the data is correct def dt(y, mo, d, h, mi): adelta = datetime(y, mo, d, h, mi) - datetime(1, 1, 1) return adelta.days + 1 + adelta.seconds / 86400.0 desired_result = ( np.array([ [dt(2015, 10, 22, 15, 00), 3.7], [dt(2015, 10, 22, 15, 10), 4.5], [dt(2015, 10, 22, 15, 20), 4.1], ]), np.array([ [dt(2015, 10, 22, 15, 00), 2.9], [dt(2015, 10, 22, 15, 10), 3.2], [dt(2015, 10, 22, 15, 20), 3], ]), ) np.testing.assert_allclose(data_array[0], desired_result[0]) np.testing.assert_allclose(data_array[1], desired_result[1])
def setUp(self): self.data = TestData() settings.TEST_MATPLOTLIB = True create_static_files()
def setUp(self): self.data = TestData() settings.TEST_MATPLOTLIB = True self.data.ts_komboti_temperature.set_data( StringIO("2015-10-22 15:10,0,\n")) create_static_files()