def validate_that_the_aggregated_is_calculated_successfully(self): """ validate that the aggregated is calculated successfully """ sum = 0 sum2 = 0 context_json = general_utils.convert_str_to_dict( self.resp.text, general_utils.JSON) if self.method == "min": assert float(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["min"]) == float(self.attributes_value), \ " ERROR - in aggregated with min %s" % (str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["min"])) elif self.method == "max": assert float(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["max"]) == float(Decimal(self.attributes_value) + self.notifications_number - 1), \ " ERROR - in aggregated with max %s" % (str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["max"])) elif self.method == "sum": for i in range(int(self.notifications_number)): v = int(self.attributes_value) + i sum = sum + v assert float(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["sum"]) == float(sum), \ " ERROR - in aggregated with sum %s" % (str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["sum"])) elif self.method == "sum2": for i in range(int(self.notifications_number)): v = int(self.attributes_value) + i sum2 = sum2 + (v * v) assert float(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["sum2"]) == float(sum2), \ " ERROR - in aggregated with sum2 %s" % (str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["sum2"]))
def validate_that_the_aggregated_is_calculated_successfully(self): """ validate that the aggregated is calculated successfully """ sum = 0 sum2 = 0 context_json = general_utils.convert_str_to_dict(self.resp.text, general_utils.JSON) if self.method == "min": assert float(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["min"]) == float(self.attributes_value), \ " ERROR - in aggregated with min %s" % (str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["min"])) elif self.method == "max": assert float(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["max"]) == float(Decimal(self.attributes_value) + self.notifications_number - 1), \ " ERROR - in aggregated with max %s" % (str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["max"])) elif self.method == "sum": for i in range(int(self.notifications_number)): v = int(self.attributes_value) + i sum = sum + v assert float(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["sum"]) == float(sum), \ " ERROR - in aggregated with sum %s" % (str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["sum"])) elif self.method == "sum2": for i in range(int(self.notifications_number)): v = int(self.attributes_value) + i sum2 = sum2 + (v*v) assert float(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["sum2"]) == float(sum2), \ " ERROR - in aggregated with sum2 %s" % (str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["sum2"]))
def verify_that_not_return_aggregated_values(self): """ verify that not return aggregated values """ for i in range (self.attributes_number): context_json = general_utils.convert_str_to_dict(self.resp.text, general_utils.JSON) assert len(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"]) == 0, \ " ERROR - aggregated values are returned:\n %s" % str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"])
def verify_that_not_return_aggregated_values(self): """ verify that not return aggregated values """ for i in range(self.attributes_number): context_json = general_utils.convert_str_to_dict( self.resp.text, general_utils.JSON) assert len(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"]) == 0, \ " ERROR - aggregated values are returned:\n %s" % str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"])
def verify_sth_version(self): """ verify sth version """ if self.sth_verify_version.lower().find("true") >= 0: resp=http_utils.request(http_utils.GET, url=self.sth_url+VERSION) assert resp.status_code == 200, " ERROR - verifying sth version, error in status code. \n code: %s\n body: %s " % (str(resp.status_code), str(resp.text)) dict_json = general_utils.convert_str_to_dict(resp.text, general_utils.JSON) assert dict_json[VERSION] == self.sth_version, " ERROR -- the sth version mismatch...\n received: %s \n expected: %s" % (dict_json[VERSION], self.sth_version)
def verify_sth_version(self): """ verify sth version """ if self.sth_verify_version.lower().find("true") >= 0: resp = http_utils.request(http_utils.GET, url=self.sth_url + VERSION) assert resp.status_code == 200, " ERROR - verifying sth version, error in status code. \n code: %s\n body: %s " % ( str(resp.status_code), str(resp.text)) dict_json = general_utils.convert_str_to_dict( resp.text, general_utils.JSON) assert dict_json[ VERSION] == self.sth_version, " ERROR -- the sth version mismatch...\n received: %s \n expected: %s" % ( dict_json[VERSION], self.sth_version)
def validate_that_the_raw_is_returned_successfully(self): """ validate that the raw is returned successfully """ context_json = general_utils.convert_str_to_dict(self.resp.text, general_utils.JSON) # attributes assert str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["name"]) == "%s_%s" % ( self.attributes_name, u"0", ), " ERROR - in raw with name %s_%s" % (self.attributes_name, u"0") assert ( str(context_json["contextResponses"][0]["contextElement"]["id"]) == self.entity_id ), " ERROR - in raw with entity id %s" % (self.entity_id) assert ( str(context_json["contextResponses"][0]["contextElement"]["type"]) == self.entity_type ), " ERROR - in raw with entity type %s" % (self.entity_type) assert str(context_json["contextResponses"][0]["statusCode"]["code"]) == "200", ( " ERROR - in raw with status code - code %s" % (str(context_json["contextResponses"][0]["statusCode"]["code"])) ) assert str(context_json["contextResponses"][0]["statusCode"]["reasonPhrase"]) == "OK", ( " ERROR - in raw with status code - code %s" % (str(context_json["contextResponses"][0]["statusCode"]["reasonPhrase"])) ) # values values_number = len(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"]) if self.last_n != EMPTY: quantity = self.last_n else: quantity = self.h_limit if values_number < quantity: quantity = values_number for i in range(quantity): if self.last_n == EMPTY: temp_value = Decimal(self.attributes_value) + i + int(self.h_offset) else: temp_value = Decimal(self.attributes_value) + int(self.notifications_number) - i # reverse assert str( context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][i]["attrValue"] ) == str(temp_value), " ERROR - in raw with attribute value in position: %s" % (str(i)) assert ( str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][i]["recvTime"]) != EMPTY ), " ERROR - in raw with recvTime in position: %s" % (str(i))
def validate_that_the_raw_is_returned_successfully(self): """ validate that the raw is returned successfully """ context_json = general_utils.convert_str_to_dict( self.resp.text, general_utils.JSON) # attributes assert str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["name"]) == "%s_%s" % (self.attributes_name, u'0'), \ " ERROR - in raw with name %s_%s" % (self.attributes_name, u'0') assert str(context_json["contextResponses"][0]["contextElement"]["id"]) == self.entity_id, \ " ERROR - in raw with entity id %s" % (self.entity_id) assert str(context_json["contextResponses"][0]["contextElement"]["type"]) == self.entity_type, \ " ERROR - in raw with entity type %s" % (self.entity_type) assert str(context_json["contextResponses"][0]["statusCode"]["code"]) == "200", \ " ERROR - in raw with status code - code %s" % (str(context_json["contextResponses"][0]["statusCode"]["code"])) assert str(context_json["contextResponses"][0]["statusCode"]["reasonPhrase"]) == "OK", \ " ERROR - in raw with status code - code %s" % (str(context_json["contextResponses"][0]["statusCode"]["reasonPhrase"])) # values values_number = len(context_json["contextResponses"][0] ["contextElement"]["attributes"][0]["values"]) if self.last_n != EMPTY: quantity = self.last_n else: quantity = self.h_limit if values_number < quantity: quantity = values_number for i in range(quantity): if self.last_n == EMPTY: temp_value = Decimal(self.attributes_value) + i + int( self.h_offset) else: if int(self.notifications_number) < int(self.last_n): self.last_n = int(self.notifications_number) temp_value = Decimal(self.attributes_value) + int( self.notifications_number) - int(self.last_n) + i assert str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][i]["attrValue"]) == str (temp_value), \ " ERROR - in raw with attribute value in position: %s" % (str(i)) assert str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][i]["recvTime"]) != EMPTY, \ " ERROR - in raw with recvTime in position: %s" % (str(i))
def validate_that_the_aggregated_is_returned_successfully(self): """ validate that the aggregated is returned successfully via REST """ time_zone = 2 dupla = {"month": "year", "day": "month", "hour": "day", "minute": "hour", "second": "minute"} offset = int(general_utils.get_date_only_one_value(self.date_time, self.resolution)) origin_year = general_utils.get_date_only_one_value(self.date_time, "year") origin_month = general_utils.get_date_only_one_value(self.date_time, "month") origin_day = general_utils.get_date_only_one_value(self.date_time, "day") origin_hour = int(general_utils.get_date_only_one_value(self.date_time, "hour")) - time_zone if origin_hour < 10: origin_hour = u"0" + str(origin_hour) origin_minute = general_utils.get_date_only_one_value(self.date_time, "minute") origin_second = general_utils.get_date_only_one_value(self.date_time, "second") context_json = general_utils.convert_str_to_dict(self.resp.text, general_utils.JSON) if self.resolution == "month": origin_by_resolution = "%s-01-01T00:00:00.000Z" % (origin_year) # 2015-01-01T00:00:00.000Z elif self.resolution == "day": origin_by_resolution = "%s-%s-01T00:00:00.000Z" % (origin_year, origin_month) elif self.resolution == "hour": offset = offset - time_zone origin_by_resolution = "%s-%s-%sT00:00:00.000Z" % (origin_year, origin_month, origin_day) elif self.resolution == "minute": origin_by_resolution = "%s-%s-%sT%s:00:00.000Z" % (origin_year, origin_month, origin_day, origin_hour) elif self.resolution == "second": offset = int( context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0][ "offset" ] ) c = int(origin_second) - int(offset) if (int(origin_second) - c) < 0: origin_minute = str(int(origin_minute) - 1) origin_by_resolution = "%s-%s-%sT%s:%s:00.000Z" % ( origin_year, origin_month, origin_day, origin_hour, origin_minute, ) else: assert False, ' ERROR - resolution type "%s" is not allowed, review your tests in features...' % ( self.resolution ) # attributes assert str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["name"]) == "%s_%s" % ( self.attributes_name, u"0", ), " ERROR - in aggregated with name %s_%s" % (self.attributes_name, u"0") # values assert ( str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["_id"]["entityId"]) == self.entity_id ), " ERROR - in aggregated with entity id %s" % (self.entity_id) assert ( str( context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["_id"]["entityType"] ) == self.entity_type ), " ERROR - in aggregated with entity type %s" % (self.entity_type) assert str( context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["_id"]["attrName"] ) == "%s_%s" % (self.attributes_name, u"0"), ( " ERROR - in aggregated with name %s_%s" % (self.attributes_name, u"0") ) assert ( str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["_id"]["origin"]) == origin_by_resolution ), " ERROR - in aggregated with origin %s" % (origin_by_resolution) assert ( str( context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["_id"]["resolution"] ) == self.resolution ), " ERROR - in aggregated with resolution %s" % (self.resolution) assert ( str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["_id"]["range"]) == dupla[self.resolution] ), " ERROR - in aggregated with range %s" % (dupla[self.resolution]) # points assert str( context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["offset"] ) == str(offset), " ERROR - in aggregated with offset %s" % (offset) if self.method == "sum": assert float( context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["sum"] ) == float(self.attributes_value), " ERROR - in aggregated with sum %s" % (str(self.attributes_value)) elif self.method == "sum2": assert float( context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["sum2"] ) == (float(self.attributes_value) * float(self.attributes_value)), ( " ERROR - in aggregated with sum2 %s" % (str((float(self.attributes_value) * float(self.attributes_value)))) ) elif self.method == "min": assert float( context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["min"] ) == float(self.attributes_value), " ERROR - in aggregated with min %s" % (str(self.attributes_value)) elif self.method == "max": assert float( context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["max"] ) == float(self.attributes_value), " ERROR - in aggregated with max %s" % (str(self.attributes_value)) # contextElement assert ( str(context_json["contextResponses"][0]["contextElement"]["id"]) == self.entity_id ), " ERROR - in aggregated with entity id %s" % (self.entity_id) assert ( str(context_json["contextResponses"][0]["contextElement"]["type"]) == self.entity_type ), " ERROR - in aggregated with entity type %s" % (self.entity_type) assert ( str(context_json["contextResponses"][0]["contextElement"]["isPattern"]) == "False" ), " ERROR - in aggregated with isPattern equal to false" # context Responses assert ( str(context_json["contextResponses"][0]["statusCode"]["code"]) == "200" ), " ERROR - in aggregated with status Code equal to 200" assert ( str(context_json["contextResponses"][0]["statusCode"]["reasonPhrase"]) == "OK" ), " ERROR - in aggregated with reason Phrase equal to OK"
def validate_that_the_aggregated_is_returned_successfully(self): """ validate that the aggregated is returned successfully via REST """ time_zone = 2 dupla = { "month": "year", "day": "month", "hour": "day", "minute": "hour", "second": "minute" } offset = int( general_utils.get_date_only_one_value(self.date_time, self.resolution)) origin_year = general_utils.get_date_only_one_value( self.date_time, "year") origin_month = general_utils.get_date_only_one_value( self.date_time, "month") origin_day = general_utils.get_date_only_one_value( self.date_time, "day") origin_hour = int( general_utils.get_date_only_one_value(self.date_time, "hour")) - time_zone if origin_hour < 10: origin_hour = u'0' + str(origin_hour) origin_minute = general_utils.get_date_only_one_value( self.date_time, "minute") origin_second = general_utils.get_date_only_one_value( self.date_time, "second") context_json = general_utils.convert_str_to_dict( self.resp.text, general_utils.JSON) if self.resolution == "month": origin_by_resolution = "%s-01-01T00:00:00.000Z" % ( origin_year) # 2015-01-01T00:00:00.000Z elif self.resolution == "day": origin_by_resolution = "%s-%s-01T00:00:00.000Z" % (origin_year, origin_month) elif self.resolution == "hour": offset = offset - time_zone origin_by_resolution = "%s-%s-%sT00:00:00.000Z" % ( origin_year, origin_month, origin_day) elif self.resolution == "minute": origin_by_resolution = "%s-%s-%sT%s:00:00.000Z" % ( origin_year, origin_month, origin_day, origin_hour) elif self.resolution == "second": offset = int(context_json["contextResponses"][0]["contextElement"] ["attributes"][0]["values"][0]["points"][0]["offset"]) c = int(origin_second) - int(offset) if (int(origin_second) - c) < 0: origin_minute = str(int(origin_minute) - 1) origin_by_resolution = "%s-%s-%sT%s:%s:00.000Z" % ( origin_year, origin_month, origin_day, origin_hour, origin_minute) else: assert False, " ERROR - resolution type \"%s\" is not allowed, review your tests in features..." % ( self.resolution) # attributes assert str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["name"]) == "%s_%s" % (self.attributes_name, u'0'), \ " ERROR - in aggregated with name %s_%s" % (self.attributes_name, u'0') # values assert str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["_id"]["attrName"]) == "%s_%s" % (self.attributes_name, u'0'), \ " ERROR - in aggregated with name %s_%s" % (self.attributes_name, u'0') assert str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["_id"]["origin"]) == origin_by_resolution, \ " ERROR - in aggregated with origin %s" % (origin_by_resolution) assert str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["_id"]["resolution"]) == self.resolution, \ " ERROR - in aggregated with resolution %s" % (self.resolution) assert str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["_id"]["range"]) == dupla[self.resolution], \ " ERROR - in aggregated with range %s" % (dupla[self.resolution]) # points assert str(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["offset"]) == str(offset), \ " ERROR - in aggregated with offset %s" % (offset) if self.method == "sum": assert float(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["sum"]) == float(self.attributes_value), \ " ERROR - in aggregated with sum %s" % (str(self.attributes_value)) elif self.method == "sum2": assert float(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["sum2"]) == (float(self.attributes_value)*float(self.attributes_value)), \ " ERROR - in aggregated with sum2 %s" % (str((float(self.attributes_value)*float(self.attributes_value)))) elif self.method == "min": assert float(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["min"]) == float(self.attributes_value), \ " ERROR - in aggregated with min %s" % (str(self.attributes_value)) elif self.method == "max": assert float(context_json["contextResponses"][0]["contextElement"]["attributes"][0]["values"][0]["points"][0]["max"]) == float(self.attributes_value), \ " ERROR - in aggregated with max %s" % (str(self.attributes_value)) # contextElement assert str(context_json["contextResponses"][0]["contextElement"]["id"]) == self.entity_id, \ " ERROR - in aggregated with entity id %s" % (self.entity_id) assert str(context_json["contextResponses"][0]["contextElement"]["type"]) == self.entity_type, \ " ERROR - in aggregated with entity type %s" % (self.entity_type) assert str(context_json["contextResponses"][0]["contextElement"]["isPattern"]) == "False", \ " ERROR - in aggregated with isPattern equal to false" # context Responses assert str(context_json["contextResponses"][0]["statusCode"]["code"]) == "200", \ " ERROR - in aggregated with status Code equal to 200" assert str(context_json["contextResponses"][0]["statusCode"]["reasonPhrase"]) == "OK", \ " ERROR - in aggregated with reason Phrase equal to OK"