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 store(self, dna: List[str]) -> dict: Validator.check(dna) item = { '_id': self.__generateId(dna), 'dna': dna, 'is_simian': self.isSimian(dna) } self.dna_table.put_item(Item=item) asyncio.run(self.__generateStats()) return item
def testRequestInvalidDnaSequence(self): data = '{"dna": [0]}' with self.assertRaises(Exception, msg="INVALID_DNA_SEQUENCE"): Validator.request(data)
def testCheck(self): dna = ["CTGAGA", "CTAACC", "TCACGT", "ATACTT", "CCTTGT", "TCTTTT"] self.assertTrue(Validator.check(dna))
def testRequestInvalidDna(self): data = '{"dna": "A"}' with self.assertRaises(Exception, msg="INVALID_DNA"): Validator.request(data)
def testRequestInvalid(self): data = '{"dna": ["CTGAGA"' with self.assertRaises(Exception, msg="INVALID_REQUEST_DATA"): Validator.request(data)
def testRequestEmpty(self): data = None with self.assertRaises(Exception, msg="INVALID_REQUEST_DATA"): Validator.request(data)
def testIsNitrogenousBaseError2(self): sequence = "CTGAGa" with self.assertRaises(Exception, msg="INVALID_DNA"): Validator.isNitrogenousBase(sequence)
def testRequest(self): data = '{"dna": ["CTGAGA", "CTAACC", "TCACGT", "ATACTT", "CCTTGT", "TCTTTT"]}' self.assertTrue(Validator.request(data))
def testIsNitrogenousBase(self): sequence = "CTGAGA" self.assertTrue(Validator.isNitrogenousBase(sequence))
def testSizeIsCorrectError(self): sequence = "CTGAGA" size = len(sequence) + 10 with self.assertRaises(Exception, msg="INVALID_DNA_SEQUENCE"): Validator.sizeIsCorrect(sequence, size)
def testSizeIsCorrect(self): sequence = "CTGAGA" size = len(sequence) self.assertTrue(Validator.sizeIsCorrect(sequence, size))
def testIsEmptyError(self): dna = [] size = len(dna) with self.assertRaises(Exception, msg="INVALID_DNA"): Validator.isEmpty(size)
def testIsEmpty(self): dna = ["CTGAGA", "CTAACC", "TCACGT", "ATACTT", "CCTTGT", "TCTTTT"] size = len(dna) self.assertTrue(Validator.isEmpty(size))