Beispiel #1
0
    def test_fetch(self):
        """Test whether archives are fetched"""

        setup_http_server(empty_mbox=True)

        client = GroupsioClient('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa', verify=False)
        success = client.fetch()

        # Check requests
        expected = [
            {
                'email': ['*****@*****.**'],
                'password': ['aaaaa']
            },
            {
                'limit': ['100'],
            },
            {
                'limit': ['100'],
                'page_token': ['1']
            },
            {
                'group_id': ['7769']
            }
        ]

        http_requests = httpretty.httpretty.latest_requests

        self.assertEqual(len(http_requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])

        self.assertEqual(client.mboxes[0].filepath, os.path.join(self.tmp_path, MBOX_FILE))
        self.assertTrue(success)
Beispiel #2
0
    def test_subscriptions(self):
        """Test whether the method subscriptions works properly"""

        setup_http_server()

        client = GroupsioClient('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa', verify=False)
        subs = [subs for subs in client.subscriptions(per_page=1)]
        self.assertEqual(len(subs), 2)
Beispiel #3
0
    def test_fetch_http_error(self):
        """Test whether HTTP errors are thrown"""

        setup_http_server(empty_mbox=True, http_status_download=400)

        client = GroupsioClient('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa', verify=False)
        with self.assertRaises(requests.exceptions.HTTPError):
            client.fetch()
Beispiel #4
0
    def test_fetch_group_id_not_found(self):
        """Test whether an error is thrown when the group id is not found"""

        setup_http_server(empty_mbox=True)

        client = GroupsioClient('beta/api', self.tmp_path, '*****@*****.**', 'aaaaa', verify=False)
        with self.assertRaises(BackendError):
            client.fetch()
Beispiel #5
0
    def test_subscriptions_http_error(self):
        """Test whether HTTP errors are thrown"""

        setup_http_server(http_status_subscriptions=400)

        client = GroupsioClient('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa', verify=False)

        with self.assertRaises(requests.exceptions.HTTPError):
            _ = [subs for subs in client.subscriptions(per_page=1)]
Beispiel #6
0
    def test_fetch(self):
        """Test whether archives are fetched"""

        setup_http_server(empty_mbox=True)

        client = GroupsioClient('beta+api', self.tmp_path, 'aaaaa', verify=False)
        success = client.fetch()

        self.assertEqual(client.mboxes[0].filepath, os.path.join(self.tmp_path, MBOX_FILE))
        self.assertTrue(success)
Beispiel #7
0
    def test_fetch_no_existing_dir(self):
        """Test whether the dir_path where to store the archives is created if it doesn't exist"""

        setup_http_server(empty_mbox=True)

        # delete the dir path
        os.removedirs(self.tmp_path)

        self.assertFalse(os.path.exists(self.tmp_path))
        client = GroupsioClient('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa', verify=False)
        _ = client.fetch()
        self.assertTrue(os.path.exists(self.tmp_path))
    def test_fetch_http_error(self):
        """Test whether HTTP errors are thrown"""

        groupsio_mbox_archive = read_file('data/groupsio/empty.zip')

        httpretty.register_uri(httpretty.GET,
                               GROUPSIO_API_URL + 'downloadarchives',
                               body=groupsio_mbox_archive,
                               status=400)

        client = GroupsioClient('acme_group', self.tmp_path, 'aaaaa', verify=False)
        with self.assertRaises(requests.exceptions.HTTPError):
            client.fetch()
    def test_fetch(self):
        """Test whether archives are fetched"""

        groupsio_mbox_archive = read_file('data/groupsio/empty.zip')

        httpretty.register_uri(httpretty.GET,
                               GROUPSIO_API_URL + 'downloadarchives',
                               body=groupsio_mbox_archive)

        client = GroupsioClient('acme_group', self.tmp_path, 'aaaaa', verify=False)
        success = client.fetch()

        self.assertEqual(client.mboxes[0].filepath, os.path.join(self.tmp_path, MBOX_FILE))
        self.assertTrue(success)
Beispiel #10
0
    def test_fetch_empty(self):
        """Test whether it does not store anything when the list of archives is empty"""

        setup_http_server(empty_mbox=True)

        client = GroupsioClient('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa', verify=False)
        success = client.fetch()

        self.assertEqual(client.mboxes[0].filepath, os.path.join(self.tmp_path, MBOX_FILE))

        _zip = zipfile.ZipFile(client.mboxes[0].filepath)
        with _zip.open(_zip.infolist()[0].filename) as _file:
            content = _file.read()

        self.assertEqual(content, b'')
        self.assertTrue(success)
Beispiel #11
0
    def test_init(self):
        """Check attributes initialization"""

        client = GroupsioClient('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa')
        self.assertIsInstance(client, GroupsioClient)
        self.assertEqual(client.uri, 'https://groups.io/g/beta+api')
        self.assertEqual(client.dirpath, self.tmp_path)
        self.assertEqual(client.group_name, 'beta+api')
        self.assertTrue(client.verify)

        client = GroupsioClient('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa', verify=False)
        self.assertIsInstance(client, GroupsioClient)
        self.assertEqual(client.uri, 'https://groups.io/g/beta+api')
        self.assertEqual(client.dirpath, self.tmp_path)
        self.assertEqual(client.group_name, 'beta+api')
        self.assertFalse(client.verify)
    def test_fetch_no_existing_dir(self):
        """Test whether the dir_path where to store the archives is created if it doesn't exist"""

        groupsio_mbox_archive = read_file('data/groupsio/empty.zip')

        httpretty.register_uri(httpretty.GET,
                               GROUPSIO_API_URL + 'downloadarchives',
                               body=groupsio_mbox_archive)

        # delete the dir path
        os.removedirs(self.tmp_path)

        self.assertFalse(os.path.exists(self.tmp_path))
        client = GroupsioClient('acme_group', self.tmp_path, 'aaaaa', verify=False)
        _ = client.fetch()
        self.assertTrue(os.path.exists(self.tmp_path))
    def test_init(self):
        """Check attributes initialization"""

        client = GroupsioClient('acme_group', self.tmp_path, 'aaaaa')

        self.assertIsInstance(client, GroupsioClient)
        self.assertEqual(client.uri, 'https://groups.io/g/acme_group')
        self.assertEqual(client.dirpath, self.tmp_path)
        self.assertEqual(client.group_name, 'acme_group')
        self.assertTrue(client.verify)

        client = GroupsioClient('acme_group', self.tmp_path, 'aaaaa', verify=False)

        self.assertIsInstance(client, GroupsioClient)
        self.assertEqual(client.uri, 'https://groups.io/g/acme_group')
        self.assertEqual(client.dirpath, self.tmp_path)
        self.assertEqual(client.group_name, 'acme_group')
        self.assertFalse(client.verify)
    def test_fetch_empty(self):
        """Test whether it does not store anything when the list of archives is empty"""

        groupsio_mbox_archive = read_file('data/groupsio/empty.zip')

        httpretty.register_uri(httpretty.GET,
                               GROUPSIO_API_URL + 'downloadarchives',
                               body=groupsio_mbox_archive)

        client = GroupsioClient('acme_group', self.tmp_path, 'aaaaa', verify=False)
        success = client.fetch()

        self.assertEqual(client.mboxes[0].filepath, os.path.join(self.tmp_path, MBOX_FILE))

        _zip = zipfile.ZipFile(client.mboxes[0].filepath)
        with _zip.open(_zip.infolist()[0].filename) as _file:
            content = _file.read()

        self.assertEqual(content, b'')
        self.assertTrue(success)
    def test_fetch_from_date(self):
        """Test whether archives are fetched after a given date"""

        setup_http_server()

        client = GroupsioClient('beta+api', self.tmp_path, '*****@*****.**', 'aaaaa', ssl_verify=False)
        from_date = datetime.datetime(2019, 1, 1)
        success = client.fetch(from_date=from_date)

        # Check requests
        expected = [
            {
                'email': ['*****@*****.**'],
                'password': ['aaaaa']
            },
            {
                'limit': ['100'],
            },
            {
                'limit': ['100'],
                'page_token': ['1']
            },
            {
                'group_id': ['7769'],
                'start_time': ['2019-01-01T00:00:00 00:00']
            }
        ]

        http_requests = httpretty.httpretty.latest_requests

        self.assertEqual(len(http_requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])

        self.assertEqual(client.mboxes[0].filepath, os.path.join(self.tmp_path, MBOX_FILE))
        self.assertTrue(success)