def test_initialization(self): """Test whether attributes are initializated""" backend = Groupsio('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa', tag='test') self.assertEqual(backend.group_name, 'beta+api') self.assertEqual(backend.email, '*****@*****.**') self.assertEqual(backend.password, "aaaaa") self.assertEqual(backend.uri, 'https://groups.io/g/beta+api') self.assertEqual(backend.dirpath, self.tmp_path) self.assertEqual(backend.origin, 'https://groups.io/g/beta+api') self.assertEqual(backend.tag, 'test') self.assertTrue(backend.verify) # When tag is empty or None it will be set to # the value in uri backend = Groupsio('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa') self.assertEqual(backend.origin, 'https://groups.io/g/beta+api') self.assertEqual(backend.tag, 'https://groups.io/g/beta+api') backend = Groupsio('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa', tag='') self.assertEqual(backend.origin, 'https://groups.io/g/beta+api') self.assertEqual(backend.tag, 'https://groups.io/g/beta+api') backend = Groupsio('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa', verify=False, tag='') self.assertEqual(backend.origin, 'https://groups.io/g/beta+api') self.assertEqual(backend.tag, 'https://groups.io/g/beta+api') self.assertFalse(backend.verify)
def test_initialization(self): """Test whether attributes are initializated""" backend = Groupsio('acme_group', self.tmp_path, 'aaaaa', tag='test') self.assertEqual(backend.group_name, 'acme_group') self.assertEqual(backend.api_token, 'aaaaa') self.assertEqual(backend.uri, 'https://groups.io/g/acme_group') self.assertEqual(backend.dirpath, self.tmp_path) self.assertEqual(backend.origin, 'https://groups.io/g/acme_group') self.assertEqual(backend.tag, 'test') self.assertTrue(backend.verify) # When tag is empty or None it will be set to # the value in uri backend = Groupsio('acme_group', self.tmp_path, 'aaaaa') self.assertEqual(backend.origin, 'https://groups.io/g/acme_group') self.assertEqual(backend.tag, 'https://groups.io/g/acme_group') backend = Groupsio('acme_group', self.tmp_path, 'aaaaa', tag='') self.assertEqual(backend.origin, 'https://groups.io/g/acme_group') self.assertEqual(backend.tag, 'https://groups.io/g/acme_group') backend = Groupsio('acme_group', self.tmp_path, 'aaaaa', verify=False, tag='') self.assertEqual(backend.origin, 'https://groups.io/g/acme_group') self.assertEqual(backend.tag, 'https://groups.io/g/acme_group') self.assertFalse(backend.verify)
def test_fetch_from_date(self): """Test whether it fetches and parses messages since the given date""" setup_http_server() from_date = datetime.datetime(2018, 5, 5) backend = Groupsio('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa') messages = [m for m in backend.fetch(from_date=from_date)] self.assertEqual(len(messages), 8) message = messages[0] self.assertEqual(message['data']['Message-ID'], '<*****@*****.**>') self.assertEqual(message['origin'], 'https://groups.io/g/beta+api') self.assertEqual(message['uuid'], 'fe0b6b64b4b297796c6139c821ff3d10dee1dc92') self.assertEqual(message['updated_on'], 1526087603.0) self.assertEqual(message['category'], 'message') self.assertEqual(message['tag'], 'https://groups.io/g/beta+api') message = messages[3] self.assertEqual(message['data']['Message-ID'], '<*****@*****.**>') self.assertEqual(message['origin'], 'https://groups.io/g/beta+api') self.assertEqual(message['uuid'], 'bd02e439127edf51df9ecbb15f3e57d473f6418f') self.assertEqual(message['updated_on'], 1527915246.0) self.assertEqual(message['category'], 'message') self.assertEqual(message['tag'], 'https://groups.io/g/beta+api') message = messages[7] self.assertEqual(message['data']['Message-ID'], '<*****@*****.**>') self.assertEqual(message['origin'], 'https://groups.io/g/beta+api') self.assertEqual(message['uuid'], '397508a441b878459cd9deabba034171bce9058d') self.assertEqual(message['updated_on'], 1530334100.0) self.assertEqual(message['category'], 'message') self.assertEqual(message['tag'], 'https://groups.io/g/beta+api')
def test_fetch(self): """Test whether it fetches and parses messages""" setup_http_server() backend = Groupsio('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa') messages = [m for m in backend.fetch()] self.assertEqual(len(messages), 49) message = messages[0] self.assertEqual(message['data']['Message-ID'], '<*****@*****.**>') self.assertEqual(message['origin'], 'https://groups.io/g/beta+api') self.assertEqual(message['uuid'], 'ee0a9d612a20cd359a0492685e2f6db90aaa637f') self.assertEqual(message['updated_on'], 1411493115.0) self.assertEqual(message['category'], 'message') self.assertEqual(message['tag'], 'https://groups.io/g/beta+api') message = messages[25] self.assertEqual(message['data']['Message-ID'], '<*****@*****.**>') self.assertEqual(message['origin'], 'https://groups.io/g/beta+api') self.assertEqual(message['uuid'], 'cb9119226ab58fe0f06f83b6178b217ccbaa28bf') self.assertEqual(message['updated_on'], 1515301791.0) self.assertEqual(message['category'], 'message') self.assertEqual(message['tag'], 'https://groups.io/g/beta+api') message = messages[45] self.assertEqual(message['data']['Message-ID'], '<*****@*****.**>') self.assertEqual(message['origin'], 'https://groups.io/g/beta+api') self.assertEqual(message['uuid'], '73e23136f519e3534ae8372da9457e7f8967b526') self.assertEqual(message['updated_on'], 1528518785.0) self.assertEqual(message['category'], 'message') self.assertEqual(message['tag'], 'https://groups.io/g/beta+api')
def test_fetch_empty(self): """Test whether an empty mbox is stored when the group is empty""" setup_http_server(empty_mbox=True) backend = Groupsio('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa') messages = [m for m in backend.fetch()] self.assertListEqual(messages, [])
def test_search_fields(self): """Test whether the search_fields is properly set""" setup_http_server() backend = Groupsio('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa') messages = [m for m in backend.fetch()] for message in messages: self.assertEqual(backend.metadata_id(message['data']), message['search_fields']['item_id']) self.assertEqual(message['search_fields']['group_name'], 'beta+api')
def test_fetch_empty(self): """Test whether an empty mbox is stored when the group is empty""" groupsio_mbox_archive = read_file('data/groupsio/empty.zip') httpretty.register_uri(httpretty.GET, GROUPSIO_API_URL + 'downloadarchives', body=groupsio_mbox_archive) backend = Groupsio('acme_group', self.tmp_path, 'aaaaa') messages = [m for m in backend.fetch()] self.assertListEqual(messages, [])
def test_fetch_from_date(self): """Test whether it fetches and parses messages since the given date""" groupsio_mbox_archive = read_file('data/groupsio/messages.zip') httpretty.register_uri(httpretty.GET, GROUPSIO_API_URL + 'downloadarchives', body=groupsio_mbox_archive) from_date = datetime.datetime(2018, 5, 5) backend = Groupsio('acme_group', self.tmp_path, 'aaaaa') messages = [m for m in backend.fetch(from_date=from_date)] self.assertEqual(len(messages), 8) message = messages[0] self.assertEqual(message['data']['Message-ID'], '<*****@*****.**>') self.assertEqual(message['origin'], 'https://groups.io/g/acme_group') self.assertEqual(message['uuid'], '078f740e54131b8833f69d605eae637b97797295') self.assertEqual(message['updated_on'], 1526087603.0) self.assertEqual(message['category'], 'message') self.assertEqual(message['tag'], 'https://groups.io/g/acme_group') message = messages[3] self.assertEqual(message['data']['Message-ID'], '<*****@*****.**>') self.assertEqual(message['origin'], 'https://groups.io/g/acme_group') self.assertEqual(message['uuid'], 'c4a8db34d926f231ac99f5cc0eb340ed6b404e06') self.assertEqual(message['updated_on'], 1527915246.0) self.assertEqual(message['category'], 'message') self.assertEqual(message['tag'], 'https://groups.io/g/acme_group') message = messages[7] self.assertEqual(message['data']['Message-ID'], '<*****@*****.**>') self.assertEqual(message['origin'], 'https://groups.io/g/acme_group') self.assertEqual(message['uuid'], '787835d4cc343299b8d1a427fa580365bb7feb0d') self.assertEqual(message['updated_on'], 1530334100.0) self.assertEqual(message['category'], 'message') self.assertEqual(message['tag'], 'https://groups.io/g/acme_group')
def test_fetch(self): """Test whether it fetches and parses messages""" groupsio_mbox_archive = read_file('data/groupsio/messages.zip') httpretty.register_uri(httpretty.GET, GROUPSIO_API_URL + 'downloadarchives', body=groupsio_mbox_archive) backend = Groupsio('acme_group', self.tmp_path, 'aaaaa') messages = [m for m in backend.fetch()] self.assertEqual(len(messages), 49) message = messages[0] self.assertEqual(message['data']['Message-ID'], '<*****@*****.**>') self.assertEqual(message['origin'], 'https://groups.io/g/acme_group') self.assertEqual(message['uuid'], '5d668945b4f339563f7bb1497ae097b00c1b2fc1') self.assertEqual(message['updated_on'], 1411493115.0) self.assertEqual(message['category'], 'message') self.assertEqual(message['tag'], 'https://groups.io/g/acme_group') message = messages[25] self.assertEqual(message['data']['Message-ID'], '<*****@*****.**>') self.assertEqual(message['origin'], 'https://groups.io/g/acme_group') self.assertEqual(message['uuid'], 'c4ebc4bdbe8d396302ba67306f9ff1fd51cf19cf') self.assertEqual(message['updated_on'], 1515301791.0) self.assertEqual(message['category'], 'message') self.assertEqual(message['tag'], 'https://groups.io/g/acme_group') message = messages[45] self.assertEqual(message['data']['Message-ID'], '<*****@*****.**>') self.assertEqual(message['origin'], 'https://groups.io/g/acme_group') self.assertEqual(message['uuid'], 'c1ab131763deb7b417e7f26cedb9ae17656ede15') self.assertEqual(message['updated_on'], 1528518785.0) self.assertEqual(message['category'], 'message') self.assertEqual(message['tag'], 'https://groups.io/g/acme_group')