コード例 #1
0
    def test_get_interpretation(self):
        """Return one interpretation with a matching interpretation_guid
        
        Searches by iId.
        """
        logger.info("\nInserting domain.")
        domain_ins_output = bpc.create_domain(bpr._get_domain_collection(), example_domain_json)
        dId = bpc._get_domain_id_by_name(bpr._get_domain_collection(), example_domain_json["dName"])
        logger.info("{} record(s) inserted with ID {}".format(domain_ins_output, dId))
        
        logger.info("Inserting interpretation.")
        interpretation_ins_output = bpc.create_interpretation(bpr._get_interpretation_collection(), example_interpretation_json)
        iId = bpc._get_interpretation_id_by_name(bpr._get_interpretation_collection(), example_interpretation_json["iName"])
        logger.info("%s record(s) inserted with ID: %s" % (interpretation_ins_output, iId))
        
        if domain_ins_output == "1" and interpretation_ins_output == "1":
            interpretation = bpc.get_interpretation(bpr._get_interpretation_collection(), example_interpretation_json["iId"])
            logger.info(interpretation)
            assert interpretation is not None
        
            logger.info("Deleting domain with ID: %s" % dId)
            del_output = bpc.delete_domain(bpr._get_domain_collection(), bpr._get_interpretation_collection(), dId)
            logger.info("{} record(s) deleted.".format(del_output))

            logger.info("Deleting interpretation with ID: %s" % iId)
            del_output = bpc.delete_interpretation(bpr._get_interpretation_collection(), iId)
            logger.info("{} record(s) deleted.".format(del_output))
        else:
            pass # Pass because there was an error in the domain or interpretation insert        
コード例 #2
0
    def test_get_domain_catalog(self):
        """Return all domains in the domain collection
        
        Sorts by dName
        """
        logger.info("\nInserting domain.")
        domain_ins_output = bpc.create_domain(bpr._get_domain_collection(), example_domain_json)
        dId = bpc._get_domain_id_by_name(bpr._get_domain_collection(), example_domain_json["dName"])
        logger.info("{} record(s) inserted with ID {}".format(domain_ins_output, dId))
        
        logger.info("Inserting interpretation.")
        interpretation_ins_output = bpc.create_interpretation(bpr._get_interpretation_collection(), example_interpretation_json)
        iId = bpc._get_interpretation_id_by_name(bpr._get_interpretation_collection(), example_interpretation_json["iName"])
        logger.info("%s record(s) inserted with ID: %s" % (interpretation_ins_output, iId))
        
        if domain_ins_output == "1" and interpretation_ins_output == "1":
            domain_coll = bpc.get_domain_catalog(bpr._get_domain_collection())
            logger.info(domain_coll)
            result_list = json.loads(domain_coll)
            assert result_list is not None
            
            for result_json in result_list: 
                logger.info(str(result_json))
        
            logger.info("Deleting domain with ID: %s" % dId)
            del_output = bpc.delete_domain(bpr._get_domain_collection(), bpr._get_interpretation_collection(), dId)
            logger.info("{} record(s) deleted.".format(del_output))

            logger.info("Deleting interpretation with ID: %s" % iId)
            del_output = bpc.delete_interpretation(bpr._get_interpretation_collection(), iId)
            logger.info("{} record(s) deleted.".format(del_output))
        else:
            pass # Pass because there was an error in the domain or interpretation insert
コード例 #3
0
    def test_get_interpretations_by_domain(self):
        """Return all interpretations corresponding to a domain_guid
        
        Sorts by iName
        """
        logger.info("\nInserting domain.")
        domain_ins_output = bpc.create_domain(bpr._get_domain_collection(), example_domain_json)
        dId = bpc._get_domain_id_by_name(bpr._get_domain_collection(), example_domain_json["dName"])
        logger.info("{} record(s) inserted with ID {}".format(domain_ins_output, dId))
        
        logger.info("Inserting interpretation.")
        interpretation_ins_output = bpc.create_interpretation(bpr._get_interpretation_collection(), example_interpretation_json)
        iId = bpc._get_interpretation_id_by_name(bpr._get_interpretation_collection(), example_interpretation_json["iName"])
        logger.info("%s record(s) inserted with ID: %s" % (interpretation_ins_output, iId))
        
        if domain_ins_output == "1" and interpretation_ins_output == "1":
            get_i_by_d = bpc.get_interpretations_by_domain(bpr._get_interpretation_collection(), example_interpretation_json["iDomainId"])
            logger.info(get_i_by_d)
            result_list = json.loads(get_i_by_d)
            
            for result_json in result_list: 
                logger.info(result_json["iId"])
        
            logger.info("Deleting domain with ID: %s" % dId)
            del_output = bpc.delete_domain(bpr._get_domain_collection(), bpr._get_interpretation_collection(), dId)
            logger.info("{} record(s) deleted.".format(del_output))

            logger.info("Deleting interpretation with ID: %s" % iId)
            del_output = bpc.delete_interpretation(bpr._get_interpretation_collection(), iId)
            logger.info("{} record(s) deleted.".format(del_output))
        else:
            pass # Pass because there was an error in the domain or interpretation insert
コード例 #4
0
 def test_create_interpretation(self):
     """Assert one record inserted 
     
     Relies on a correct interpretation_object (json) being passed in.
     Malformed jsons will corrupt the database schema.
     """
     logger.info("\nInserting interpretation.")
     ins_output = bpc.create_interpretation(bpr._get_interpretation_collection(), example_interpretation_json)
     iId = bpc._get_interpretation_id_by_name(bpr._get_interpretation_collection(), example_interpretation_json["iName"])
     logger.info("{} record(s) inserted.".format(ins_output))
     assert ins_output == iId
     
     logger.info("Deleting interpretation with ID: %s" % iId)
     del_output = bpc.delete_interpretation(bpr._get_interpretation_collection(), iId)
     logger.info("%s record(s) deleted." % del_output)
コード例 #5
0
def delete_interpretation(interpretation_guid):
    """Return the deleted count
    
    Deletes an interpretation from the interpretation collection
    """
    current_app.logger.info("Retrieving delete interpretation request.")
    output = bpc.delete_interpretation(_get_interpretation_collection(), interpretation_guid)
    current_app.logger.debug(output)
    
    if output == 1:
        return str(output), status.HTTP_202_ACCEPTED
    elif output > 1:
        return str(output), status.HTTP_409_CONFLICT
    else:
        return str(output), status.HTTP_404_NOT_FOUND
コード例 #6
0
 def test_create_bad_interpretation(self):
     logger.info("\nInserting interpretation.")
     ins_output_1 = bpc.create_interpretation(bpr._get_interpretation_collection(), example_interpretation_json)
     iId = bpc._get_interpretation_id_by_name(bpr._get_interpretation_collection(), example_interpretation_json["iName"])
     logger.info("{} record(s) inserted with ID {}".format(ins_output_1, iId))
     assert ins_output_1 == iId
     
     logger.info("Inserting duplicate interpretation.")
     ins_output_2 = bpc.create_interpretation(bpr._get_interpretation_collection(), example_interpretation_json)
     assert ins_output_2 == "-1"        
    
     logger.info("Successfully rejected a duplicate interpretation name")
     
     logger.info("Deleting interpretation with ID: %s" % iId)
     del_output = bpc.delete_interpretation(bpr._get_interpretation_collection(), iId)
     logger.info("%s record(s) deleted." % del_output)
コード例 #7
0
    def test_delete_interpretation(self):
        """Return the number of records deleted (0 or 1)

        Only deletes the first occurrence of a matching Mongo document.
        """
        logger.info("\nInserting interpretation.")
        ins_output = bpc.create_interpretation(bpr._get_interpretation_collection(), example_interpretation_json)
        iId = bpc._get_interpretation_id_by_name(bpr._get_interpretation_collection(), example_interpretation_json["iName"])
        logger.info("{} record(s) inserted with ID {}".format(ins_output, iId))
        assert ins_output == iId
        
        if ins_output == "1":
            logger.info("Deleting interpretation with ID: %s" % example_interpretation_json["iId"])
            del_output = bpc.delete_interpretation(bpr._get_interpretation_collection(), example_interpretation_json["iId"])
            logger.info("%s record(s) deleted." % del_output)
            assert del_output == "1"
        else:
            pass # Pass because there was an error in the interpretation insert
コード例 #8
0
def delete_interpretation(interpretation_guid):
    """Return the deleted count
    
    Deletes an interpretation from the interpretation collection
    """
    try:
        current_app.logger.info("Retrieving delete interpretation request.")
        output = bpc.delete_interpretation(_get_interpretation_collection(), interpretation_guid)
        current_app.logger.debug(output)
        
        if output == 1:
            return str(output), status.HTTP_202_ACCEPTED
        elif output > 1:
            return str(output), status.HTTP_409_CONFLICT
        else:
            return str(output), status.HTTP_404_NOT_FOUND
    except Exception as exc:
        current_app.logger.error("Unable to reach MongoDB.")
        current_app.logger.error(exc)
        return ("Unable to reach MongoDB"), status.HTTP_503_SERVICE_UNAVAILABLE