Esempio n. 1
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()
Esempio n. 2
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()
    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()
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
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(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)
Esempio n. 8
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)
    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_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)