Esempio n. 1
0
    def test_get_artifact_url(self):
        remove_all_keys()
        fb = self.get_store('test_config.yaml')
        tmp_filename = os.path.join(tempfile.gettempdir(),
                                    str(uuid.uuid4()) + '.txt')

        random_str = str(uuid.uuid4())
        with open(tmp_filename, 'w') as f:
            f.write(random_str)

        artifact_key = 'tests/test_' + str(uuid.uuid4())
        artifact = _build({'key': artifact_key})
        fb.put_artifact(artifact, tmp_filename)
        url = fb.get_artifact_url(artifact)
        os.remove(tmp_filename)
        response = requests.get(url)
        self.assertEqual(response.status_code, 200)
        tar_filename = os.path.join(tempfile.gettempdir(),
                                    str(uuid.uuid4()) + '.tgz')
        with open(tar_filename, 'wb') as f:
            f.write(response.content)

        ptar = subprocess.Popen(['tar', '-xf', tar_filename],
                                cwd=tempfile.gettempdir())

        tarout, _ = ptar.communicate()

        with open(tmp_filename, 'r') as f:
            self.assertEqual(f.read(), random_str)

        os.remove(tmp_filename)
        os.remove(tar_filename)
        fb.delete_artifact(artifact)
Esempio n. 2
0
    def test_get_set_noauth_firebase(self):
        remove_all_keys()
        with self.get_provider('test_config.yaml') as fb:
            response = fb._get("authtest/hello")
            self.assertTrue(response is None)

            random_str = str(uuid.uuid4())
            key_path = 'authtest/randomKey'
            fb._set(key_path, random_str)
            self.assertTrue(fb._get(key_path) is None)
            remove_all_keys()
Esempio n. 3
0
    def test_get_set_auth_firebase(self):
        remove_all_keys()
        with self.get_provider('test_config_auth.yaml') as fb:
            response = fb._get("authtest/hello")
            self.assertEquals(response, "world")

            random_str = str(uuid.uuid4())
            key_path = 'authtest/randomKey'
            fb._set(key_path, random_str)

            self.assertTrue(fb._get(key_path) == random_str)
            fb._delete(key_path)
            remove_all_keys()
Esempio n. 4
0
    def test_upload_download_file_noauth(self):
        remove_all_keys()
        fb = self.get_store('test_config.yaml')
        tmp_filename = os.path.join(tempfile.gettempdir(),
                                    str(uuid.uuid4()) + '.txt')

        random_str = str(uuid.uuid4())
        with open(tmp_filename, 'w') as f:
            f.write(random_str)

        key = 'authtest/' + str(uuid.uuid4()) + '.txt'
        fb._upload_file(key, tmp_filename)
        os.remove(tmp_filename)
        fb._download_file(key, tmp_filename)

        self.assertTrue(not os.path.exists(tmp_filename))
Esempio n. 5
0
    def test_get_file_url_auth(self):
        remove_all_keys()
        fb = self.get_store('test_config_auth.yaml')
        tmp_filename = os.path.join(tempfile.gettempdir(),
                                    str(uuid.uuid4()) + '.txt')
        random_str = str(uuid.uuid4())
        with open(tmp_filename, 'w') as f:
            f.write(random_str)

        key = 'authtest/' + str(uuid.uuid4()) + '.txt'
        fb._upload_file(key, tmp_filename)

        url = fb._get_file_url(key)
        response = requests.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'), random_str)
        fb._delete_file(key)
        os.remove(tmp_filename)
Esempio n. 6
0
    def test_upload_download_file_auth(self):
        remove_all_keys()
        fb = self.get_store('test_config_auth.yaml')
        tmp_filename = os.path.join(tempfile.gettempdir(),
                                    str(uuid.uuid4()) + '.txt')

        random_str = str(uuid.uuid4())
        with open(tmp_filename, 'w') as f:
            f.write(random_str)

        key = 'authtest/' + str(uuid.uuid4())
        fb._upload_file(key, tmp_filename)
        os.remove(tmp_filename)

        # test an authorized attempt to delete file
        remove_all_keys()
        fb = self.get_store('test_config.yaml')
        fb._delete_file(key)
        remove_all_keys()
        fb = self.get_store('test_config_auth.yaml')
        # to make sure file is intact and the same as we uploaded

        fb._download_file(key, tmp_filename)

        with open(tmp_filename, 'r') as f:
            line = f.read()
        os.remove(tmp_filename)
        self.assertTrue(line == random_str)

        fb._delete_file(key)
        fb._download_file(key, tmp_filename)
        self.assertTrue(not os.path.exists(tmp_filename))