def test_parseRecord(self, mocker): testEncRec = {'body': '{"url": "www.testing.url"}'} testURL = 's3.testing.url' mockCoverParse = mocker.patch('service.CoverParse')() mockCoverParse.s3CoverURL = testURL mockKinesisPut = MagicMock() mocker.patch.dict('os.environ', {'DB_UPDATE_STREAM': 'testing'}) outURL = parseRecord(testEncRec, mockKinesisPut) assert outURL == testURL mockCoverParse.storeCover.assert_called_once() mockKinesisPut.putKinesis.assert_called_once()
def test_parseRecord_missingBody(self): missingBodyRecord = {'record': '{"data": "data"}'} with pytest.raises(DataError): parseRecord(missingBodyRecord, 'outManager')
def test_parseRecord_invalidJSON(self): malformedJSON = {'body': '{"field: "its missing a quotation mark"}'} with pytest.raises(DataError): parseRecord(malformedJSON, 'outManager')
def test_parseRecords_bad_stage(self, mock_json): res = parseRecord({'body': {'data': ''}}) mock_json.assert_called_once() self.assertFalse(res)
def test_parseRecords(self, mock_enhance, mock_json): res = parseRecord({'body': {'data': ''}}) mock_enhance.assert_called_once() mock_json.assert_called_once() self.assertTrue(res)