def setUp(self): setup(context=self) with self.app.app_context(): provider = {'name': 'Test'} dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath( os.path.join(dirname, '../fixtures', self.filename)) with open(fixture, mode='rb') as f: bytes = f.read() parser = EMailRFC822FeedParser() self.items = parser.parse([(1, bytes)], provider)
def test_bad_user(self): filename = 'json-email-bad-user.txt' dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.join(dirname, 'fixtures', filename) with open(fixture, mode='rb') as f: bytes = f.read() parser = EMailRFC822FeedParser() try: with self.assertRaises(IngestEmailError) as exc_context: self.items = parser.parse([(1, bytes)], self.provider) except: self.fail('Expected exception type was not raised.') ex = exc_context.exception self.assertEqual(ex.code, 6001)
def test_parsed_values_Email_Address(self): filename = "googleform1.txt" dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath( os.path.join(dirname, "../fixtures", filename)) with open(fixture, mode="rb") as f: bytes = f.read() parser = EMailRFC822FeedParser() self.items = parser.parse([(1, bytes)], self.provider) self.assertEqual(self.items[0]["headline"], "Arnold 'worried' about maroon-clad Roar") self.assertEqual(self.items[0]["task"]["desk"], 1) self.assertEqual(self.items[0]["original_creator"], 123) self.assertEqual(self.items[0]["urgency"], 2) self.assertEqual(self.items[0]["dateline"]["text"], "BRISBANE, Nov 18 AAP -") self.assertEqual(self.items[0]["byline"], "E Harvey")
def test_parsed_values_Email_Address(self): filename = 'googleform1.txt' dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath( os.path.join(dirname, '../fixtures', filename)) with open(fixture, mode='rb') as f: bytes = f.read() parser = EMailRFC822FeedParser() self.items = parser.parse([(1, bytes)], self.provider) self.assertEqual(self.items[0]['headline'], 'Arnold \'worried\' about maroon-clad Roar') self.assertEqual(self.items[0]['task']['desk'], 1) self.assertEqual(self.items[0]['original_creator'], 123) self.assertEqual(self.items[0]['urgency'], 2) self.assertEqual(self.items[0]['dateline']['text'], 'BRISBANE, Nov 18 AAP -') self.assertEqual(self.items[0]['byline'], 'E Harvey')
def setUp(self): setup(context=self) with self.app.app_context(): # mock one user: user_service = UsersService('users', backend=superdesk.get_backend()) self.user_id = user_service.create([{ 'name': 'user', 'user_type': 'administrator', 'email': '*****@*****.**' }])[0] provider = {'name': 'Test'} dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath( os.path.join(dirname, '../fixtures', self.filename)) with open(fixture, mode='rb') as f: bytes = f.read() parser = EMailRFC822FeedParser() self.items = parser.parse([(1, bytes)], provider)
def test_parsed_values(self): filename = 'googleform.txt' dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath( os.path.join(dirname, '../fixtures', filename)) with open(fixture, mode='rb') as f: bytes = f.read() parser = EMailRFC822FeedParser() self.items = parser.parse([(1, bytes)], self.provider) self.assertEqual(self.items[0]['headline'], 'TEST NZ HEADER') self.assertEqual(self.items[0]['task']['desk'], 1) self.assertEqual(self.items[0]['original_creator'], 123) self.assertEqual(self.items[0]['urgency'], 1) self.assertEqual(self.items[0]['dateline']['text'], 'AUCKLAND, May 5 AAP -') self.assertEqual(self.items[0]['place'][0]['qcode'], 'ADV') self.assertEqual(self.items[0]['flags']['marked_for_legal'], True) self.assertEqual(self.items[0]['priority'], 3) self.assertEqual(self.items[0]['byline'], 'E Harvey')
def setUp(self): setup(context=self) with self.app.app_context(): # mock one user: user_service = UsersService("users", backend=superdesk.get_backend()) self.user_id = user_service.create([{ "name": "user", "user_type": "administrator", "email": "*****@*****.**" }])[0] provider = {"name": "Test"} dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath( os.path.join(dirname, "../fixtures", self.filename)) with open(fixture, mode="rb") as f: bytes = f.read() parser = EMailRFC822FeedParser() self.items = parser.parse([(1, bytes)], provider)
def test_parsed_values(self): filename = "googleform.txt" dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath( os.path.join(dirname, "../fixtures", filename)) with open(fixture, mode="rb") as f: bytes = f.read() parser = EMailRFC822FeedParser() self.items = parser.parse([(1, bytes)], self.provider) self.assertEqual(self.items[0]["headline"], "TEST NZ HEADER") self.assertEqual(self.items[0]["task"]["desk"], 1) self.assertEqual(self.items[0]["original_creator"], 123) self.assertEqual(self.items[0]["urgency"], 1) self.assertEqual(self.items[0]["dateline"]["text"], "AUCKLAND, May 5 AAP -") self.assertEqual(self.items[0]["place"][0]["qcode"], "ADV") self.assertEqual(self.items[0]["flags"]["marked_for_legal"], True) self.assertEqual(self.items[0]["priority"], 3) self.assertEqual(self.items[0]["byline"], "E Harvey")
def setUp(self): setup(context=self) with self.app.app_context(): self.app.data.insert('users', [{ '_id': 123, 'name': 'user', 'user_type': 'administrator', 'email': '*****@*****.**', 'byline': 'E Harvey' }]) self.app.data.insert('desks', [{'_id': 1, 'name': 'new zealand'}]) self.app.data.insert( 'vocabularies', [{ '_id': 'locators', 'items': [{ 'is_active': True, 'name': 'ADV', 'qcode': 'ADV', 'group': '' }] }, { '_id': 'priority', 'items': [{ 'is_active': True, 'name': 'Urgent', 'qcode': '3' }] }]) provider = {'name': 'Test', 'config': {'formatted': True}} dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath( os.path.join(dirname, '../fixtures', self.filename)) with open(fixture, mode='rb') as f: bytes = f.read() parser = EMailRFC822FeedParser() self.items = parser.parse([(1, bytes)], provider)
def test_formatted_email_parser(self): filename = 'json-email.txt' dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.join(dirname, 'fixtures', filename) with open(fixture, mode='rb') as f: bytes = f.read() parser = EMailRFC822FeedParser() self.items = parser.parse([(1, bytes)], self.provider) self.assertEqual(self.items[0]['priority'], 5) self.assertEqual(self.items[0]['sign_off'], 'TA') self.assertEqual(self.items[0]['anpa_category'], [{'qcode': 's'}]) self.assertEqual(self.items[0]['body_html'], '<p>Lorem ipsum</p>') self.assertEqual(self.items[0]['abstract'], 'Abstract-2') self.assertEqual(self.items[0]['headline'], 'Headline-2') self.assertEqual(self.items[0]['original_creator'], 1) self.assertEqual(self.items[0]['task']['desk'], 1) self.assertEqual(self.items[0]['urgency'], 4) self.assertEqual(self.items[0]['type'], 'text') self.assertEqual(self.items[0]['guid'], '<*****@*****.**>') self.assertEqual(self.items[0]['original_source'], '*****@*****.**') self.assertEqual(self.items[0]['slugline'], 'Slugline-2') self.assertEqual(self.items[0]['byline'], 'A Mock Up')
def test_formatted_email_parser(self): filename = "json-email.txt" dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.join(dirname, "../fixtures", filename) with open(fixture, mode="rb") as f: bytes = f.read() parser = EMailRFC822FeedParser() self.items = parser.parse([(1, bytes)], self.provider) self.assertEqual(self.items[0]["priority"], 5) self.assertEqual(self.items[0]["sign_off"], "TA") self.assertEqual(self.items[0]["anpa_category"], [{"qcode": "s"}]) self.assertEqual(self.items[0]["body_html"], "<p>Lorem ipsum</p>") self.assertEqual(self.items[0]["abstract"], "Abstract-2") self.assertEqual(self.items[0]["headline"], "Headline-2") self.assertEqual(self.items[0]["original_creator"], 1) self.assertEqual(self.items[0]["task"]["desk"], 1) self.assertEqual(self.items[0]["urgency"], 4) self.assertEqual(self.items[0]["type"], "text") self.assertEqual(self.items[0]["guid"], "<*****@*****.**>") self.assertEqual(self.items[0]["original_source"], "*****@*****.**") self.assertEqual(self.items[0]["slugline"], "Slugline-2") self.assertEqual(self.items[0]["byline"], "A Mock Up")