コード例 #1
0
def simian() -> str:
    service = Dna()
    try:
        Validator.request(request.data)
        dna = json.loads(request.data).get("dna", [])
        item = service.store(dna)
        return make_response("", 200 if item.get('is_simian', False) else 403)
    except Exception as exc:
        return make_response({'status': "error", 'message': str(exc)}, 500)
コード例 #2
0
 def testGenerateStats(self, boto3_resource: MagicMock):
     boto3_resource.return_value.Table.return_value.scan.return_value = {
         'Count': 40,
         'ScannedCount': 140
     }
     obj = Dna()
     expected = {
         '_id': "1",
         'simians': 40,
         'humans': 100,
         'ratio': Decimal("0.4")
     }
     self.assertEqual(expected, asyncio.run(obj._Dna__generateStats()))
コード例 #3
0
 def testStore(self, simian_analyzer: MagicMock, hashlib_md5: MagicMock,
               validator_check: MagicMock, boto3_resource: MagicMock):
     dna = ["CTGAGA", "CTAACC", "TCACGT", "ATACTT", "CCTTGT", "TCTTTT"]
     validator_check.return_value = True
     boto3_resource.return_value.Table.return_value.put_item.return_value = True
     boto3_resource.return_value.Table.return_value.scan.return_value = {
         'Count': 40,
         'ScannedCount': 140
     }
     hash_md5 = "XXX-123-HASH-789-XXX"
     hashlib_md5.return_value.hexdigest.return_value = hash_md5
     simian_analyzer.return_value = True
     obj = Dna()
     expected = {'_id': hash_md5, 'dna': dna, 'is_simian': True}
     self.assertEqual(expected, obj.store(dna))
コード例 #4
0
 def testStats(self, boto3_resource: MagicMock):
     simians = "40"
     humans = "100"
     ratio = "0.4"
     boto3_resource.return_value.Table.return_value.scan.return_value = {
         'Items': [{
             'simians': Decimal(simians),
             'humans': Decimal(humans),
             'ratio': Decimal(ratio)
         }]
     }
     obj = Dna()
     expected = {
         'count_mutant_dna': simians,
         'count_human_dna': humans,
         'ratio': ratio
     }
     self.assertEqual(expected, obj.stats())
コード例 #5
0
 def testIsSimian(self, simian_analyzer: MagicMock):
     dna = ["CTGAGA", "CTAACC", "TCACGT", "ATACTT", "CCTTGT", "TCTTTT"]
     simian_analyzer.return_value = True
     obj = Dna()
     self.assertTrue(obj.isSimian(dna))
コード例 #6
0
 def testCalcRatioZero(self):
     simians = 40
     humans = 0
     expected = Decimal("0").quantize(Decimal("1.0"))
     self.assertEqual(expected, Dna._Dna__calcRatio(simians, humans))
コード例 #7
0
 def testGenerateId(self, hashlib_md5: MagicMock):
     dna = ["CTGAGA", "CTAACC", "TCACGT", "ATACTT", "CCTTGT", "TCTTTT"]
     expected = "XXX-123-HASH-789-XXX"
     hashlib_md5.return_value.hexdigest.return_value = expected
     self.assertEqual(expected, Dna._Dna__generateId(dna))
コード例 #8
0
def stats() -> str:
    service = Dna()
    return make_response(service.stats())