def test__gs_logic():
    # sample prod fixture ids
    _env = settings.env
    LoggingConfiguration.initialize_logger()
    message = "GS LOGIC TEST CASE FAILED"
    print ("*"*100, "Running Test Cases", "*"*100)
    if _env == "stage":
        assert gs_logic("1021985318", 550000) == 0, message
        assert gs_logic("1028525411", 550000) == 0, message
    else:
        assert gs_logic("1152388959", 290000) == 0, message
        assert gs_logic("1060545354", 525000) == 0, message
    print("*" * 100, "Test Cases Execution Successful", "*" * 100)
示例#2
0
 def callback(ch, method, properties, body):
     LoggingConfiguration.update_request_id()
     logger = LoggingConfiguration.get_default_logger()
     logger.info("rabbit mq consumer message received: {}".format(body))
     dict_body = json.loads(body)
     try:
         res = set_gs_flag(dict_body.get('fixtureId'),
                           dict_body.get('price'))
     except Exception as e:
         logger.error("MESSAGE PROCESSING FAILED: {}".format(str(e)))
         traceback.print_exc()
         res = False
     return res
示例#3
0
 def consume(self):
     logger = LoggingConfiguration.get_default_logger()
     self._channel.basic_consume(
         self.get_queue_name(),
         self.callback,
         self.get_auto_ack()
     )
     # start consuming, handle and log error, close connection
     self._channel.start_consuming()
 def set_flag(flag, fixture_data):
     logger = LoggingConfiguration.get_default_logger()
     cc_mysql_connector = CCMySqlConnector()
     if fixture_data:
         fixture_id = fixture_data.pop("fixture_id")
         query = "insert into {} (fixture_id, gs_flag, extra_data) values ('{}', '{}', '{}')".format(
             ABC_GS_FLAG_TABLE, fixture_id, int(flag),
             json.dumps(fixture_data))
         res = cc_mysql_connector.execute(query)
         logger.info("mysql query: {} result: {}".format(query, res))
         return True
     return False
def set_gs_flag(fixture_id, target_price):
    logger = LoggingConfiguration.get_default_logger()
    logger.info("target_price: {}, fixture_id: {}".format(
        target_price, fixture_id))
    if target_price and fixture_id:
        inspection_record = InspectionRecordFetcher.fetch(fixture_id)
        if inspection_record:
            inspection_record = inspection_record[0]
            gs_flag = some_logic(inspection_record, target_price)
            GsFlagQueryExecutor.set_flag(
                gs_flag, get_fixture_data(inspection_record, target_price))
            return gs_flag
    return 0
 def _fetch(appointment_id):
     logger = LoggingConfiguration.get_default_logger()
     inspection_api_uri = "v2/inspection?action=Search&role=storemanager&client=GS-C2C&appointmentId={" \
                          "appointment_id}&user={user} "
     url = INSP_API_HOST + inspection_api_uri.format(
         appointment_id=appointment_id, user=INSP_API_AUTH_USER)
     headers = {"Authorization": "Bearer {}".format(INSP_API_AUTH_TOKEN)}
     response = requests.get(url, headers=headers)
     logger.debug("inspection api response: {}".format(response.text))
     if response.status_code == 200:
         return response.json().get('detail', [])
     else:
         logger.error("INSPECTION API FAIL: {}".format(response.text))
         return list()
    def get_flag(fixture_id=None):
        query = None
        where_clause = None
        flag = None
        cc_mysql_connector = CCMySqlConnector()
        logger = LoggingConfiguration.get_default_logger()

        # processing
        if fixture_id:
            where_clause = "fixture_id={}".format(fixture_id)
        if where_clause:
            query = "select gs_flag from {} where {} order by timestamp desc limit 1".format(
                ABC_GS_FLAG_TABLE, where_clause)
            res = cc_mysql_connector.execute(query)
            flag = res.first()
            if flag:
                flag = flag[0]

        logger.info("mysql query: {} result: {}".format(query, flag))
        return flag
from services.product_transformation_result import gs_logic


def test__gs_logic():
    # sample prod fixture ids
    _env = settings.env
    LoggingConfiguration.initialize_logger()
    message = "GS LOGIC TEST CASE FAILED"
    print ("*"*100, "Running Test Cases", "*"*100)
    if _env == "stage":
        assert gs_logic("1021985318", 550000) == 0, message
        assert gs_logic("1028525411", 550000) == 0, message
    else:
        assert gs_logic("1152388959", 290000) == 0, message
        assert gs_logic("1060545354", 525000) == 0, message
    print("*" * 100, "Test Cases Execution Successful", "*" * 100)


if __name__ == "__main__":
    test__gs_logic()
    LoggingConfiguration.initialize_logger()
    consumer = GsFlagRmqConsumer()
    consumer.consume()


# CREATE TABLE ABC_gs_flag (id INT AUTO_INCREMENT,fixture_id INT NOT NULL,gs_flag INT NOT NULL DEFAULT 0,
# timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY ( id ), KEY(fixture_id));


# ALTER TABLE ABC_gs_flag ADD extra_data JSON;