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)
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))