コード例 #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
ファイル: service.py プロジェクト: robertoarruda/dna_simian
 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
コード例 #3
0
 def testRequestInvalidDnaSequence(self):
     data = '{"dna": [0]}'
     with self.assertRaises(Exception, msg="INVALID_DNA_SEQUENCE"):
         Validator.request(data)
コード例 #4
0
 def testCheck(self):
     dna = ["CTGAGA", "CTAACC", "TCACGT", "ATACTT", "CCTTGT", "TCTTTT"]
     self.assertTrue(Validator.check(dna))
コード例 #5
0
 def testRequestInvalidDna(self):
     data = '{"dna": "A"}'
     with self.assertRaises(Exception, msg="INVALID_DNA"):
         Validator.request(data)
コード例 #6
0
 def testRequestInvalid(self):
     data = '{"dna": ["CTGAGA"'
     with self.assertRaises(Exception, msg="INVALID_REQUEST_DATA"):
         Validator.request(data)
コード例 #7
0
 def testRequestEmpty(self):
     data = None
     with self.assertRaises(Exception, msg="INVALID_REQUEST_DATA"):
         Validator.request(data)
コード例 #8
0
 def testIsNitrogenousBaseError2(self):
     sequence = "CTGAGa"
     with self.assertRaises(Exception, msg="INVALID_DNA"):
         Validator.isNitrogenousBase(sequence)
コード例 #9
0
 def testRequest(self):
     data = '{"dna": ["CTGAGA", "CTAACC", "TCACGT", "ATACTT", "CCTTGT", "TCTTTT"]}'
     self.assertTrue(Validator.request(data))
コード例 #10
0
 def testIsNitrogenousBase(self):
     sequence = "CTGAGA"
     self.assertTrue(Validator.isNitrogenousBase(sequence))
コード例 #11
0
 def testSizeIsCorrectError(self):
     sequence = "CTGAGA"
     size = len(sequence) + 10
     with self.assertRaises(Exception, msg="INVALID_DNA_SEQUENCE"):
         Validator.sizeIsCorrect(sequence, size)
コード例 #12
0
 def testSizeIsCorrect(self):
     sequence = "CTGAGA"
     size = len(sequence)
     self.assertTrue(Validator.sizeIsCorrect(sequence, size))
コード例 #13
0
 def testIsEmptyError(self):
     dna = []
     size = len(dna)
     with self.assertRaises(Exception, msg="INVALID_DNA"):
         Validator.isEmpty(size)
コード例 #14
0
 def testIsEmpty(self):
     dna = ["CTGAGA", "CTAACC", "TCACGT", "ATACTT", "CCTTGT", "TCTTTT"]
     size = len(dna)
     self.assertTrue(Validator.isEmpty(size))