コード例 #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_create_bad_domain(self):
     logger.info("\nInserting domain.")
     ins_output_1 = 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("1 record(s) inserted with ID {}".format(ins_output_1))
     assert ins_output_1 == dId
     
     logger.info("Inserting duplicate domain.")
     ins_output_2 = bpc.create_domain(bpr._get_domain_collection(), example_domain_json)
     assert ins_output_2 == "-1"
     
     logger.info("Successfully rejected a duplicate domain name")
     
     logger.info("Deleting domain with ID: %s" % dId)
     del_output = bpc.delete_domain(bpr._get_domain_collection(), bpr._get_interpretation_collection(), dId)
     logger.info("%s record(s) deleted." % del_output)
コード例 #3
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
コード例 #4
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
コード例 #5
0
 def test_create_domain(self):
     """Assert one record inserted 
     
     Relies on a correct domain_object (json) being passed in.
     Malformed jsons will corrupt the database schema.
     """
     logger.info("\nInserting domain.")
     result = 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("1 record(s) inserted with ID {}".format(dId))
     assert dId == dId
     
     logger.info("Deleting domain with ID: %s" % dId)
     del_output = bpc.delete_domain(bpr._get_domain_collection(), bpr._get_interpretation_collection(), dId)
     logger.info("%s record(s) deleted." % del_output)
コード例 #6
0
    def test_delete_domain(self):
        """Return the number of records deleted (0 or 1)

        Only deletes the first occurrence of a matching Mongo document.
        """
        logger.info("\nInserting 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(ins_output, dId))
        
        if ins_output == "1":
            logger.info("Deleting domain with ID: %s" % example_domain_json["dId"])
            del_output = bpc.delete_domain(bpr._get_domain_collection(), bpr._get_interpretation_collection(), example_domain_json["dId"])
            logger.info("%s record(s) deleted." % del_output)
            assert del_output == "1"
        else:
            pass # Pass because there was an error in the domain insert
コード例 #7
0
def create_domain():
    """Return the Object Id of the inserted object if successful
    Return "0" if the action was unsuccessful
    
    Creates a domain object in the domain collection
    """
    current_app.logger.info("Received create domain request.")
    if request.headers['Content-Type'] == 'application/json':
        current_app.logger.debug("Content type is application/json")
        domain_object = request.json
        current_app.logger.debug("domain_object: " , domain_object)
        output = bpc.create_domain(_get_domain_collection(), domain_object)
        current_app.logger.debug(output)
        
        
        if output == "-1":
            return output, status.HTTP_403_FORBIDDEN  
        else:
            return output, status.HTTP_201_CREATED
コード例 #8
0
def create_domain():
    """Return the Object Id of the inserted object if successful
    Return "0" if the action was unsuccessful
    
    Creates a domain object in the domain collection
    """
    try: 
        current_app.logger.info("Received create domain request.")
        if request.headers['Content-Type'] == 'application/json':
            current_app.logger.debug("Content type is application/json")
            domain_object = request.json
            current_app.logger.debug("domain_object: " , domain_object)
            output = bpc.create_domain(_get_domain_collection(), domain_object)
            current_app.logger.debug(output)
            
            
            if output == "-1":
                return output, status.HTTP_403_FORBIDDEN  
            else:
                return output, status.HTTP_201_CREATED
    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