Exemplo n.º 1
0
    def test_plot_sharing_invalid_argument(self):

        # Raise an error if sharing argument is incorrect
        # correct arguments {'public, 'private', 'secret'}

        kwargs = {"filename": "invalid-sharing-argument", "sharing": "privste"}

        with self.assertRaisesRegexp(PlotlyError,
                                     "The 'sharing' argument only accepts"):
            py.plot(self.simple_figure, **kwargs)
Exemplo n.º 2
0
    def test_plot_sharing_invalid_argument(self):

        # Raise an error if sharing argument is incorrect
        # correct arguments {'public, 'private', 'secret'}

        kwargs = {'filename': 'invalid-sharing-argument',
                  'sharing': 'privste'}

        with self.assertRaisesRegexp(
                PlotlyError,
                "The 'sharing' argument only accepts"):
            py.plot(self.simple_figure, **kwargs)
Exemplo n.º 3
0
 def test_plot_invalid(self):
     fig = {
         'data': [
             {
                 'x': [1, 2, 3],
                 'y': [2, 1, 2],
                 'z': [3, 4, 1]
             }
         ]
     }
     with self.assertRaises(ValueError):
         py.plot(fig, auto_open=False, filename='plot_invalid')
Exemplo n.º 4
0
 def test_plot_invalid(self):
     fig = {
         'data': [
             {
                 'x': [1, 2, 3],
                 'y': [2, 1, 2],
                 'z': [3, 4, 1]
             }
         ]
     }
     with self.assertRaises(ValueError):
         py.plot(fig, auto_open=False, filename='plot_invalid')
Exemplo n.º 5
0
    def test_plot_world_readable_sharing_conflict_1(self):

        # Raise an error if world_readable=False but sharing='public'

        kwargs = {'filename': 'invalid-privacy-setting',
                  'world_readable': False,
                  'sharing': 'public'}

        with self.assertRaisesRegexp(
                PlotlyError,
                'setting your plot privacy to both public and private.'):
            py.plot(self.simple_figure, **kwargs)
Exemplo n.º 6
0
    def test_plot_world_readable_sharing_conflict_1(self):

        # Raise an error if world_readable=False but sharing='public'

        kwargs = {'filename': 'invalid-privacy-setting',
                  'world_readable': False,
                  'sharing': 'public'}

        with self.assertRaisesRegexp(
                PlotlyError,
                'setting your plot privacy to both public and private.'):
            py.plot(self.simple_figure, **kwargs)
Exemplo n.º 7
0
    def test_plot_world_readable_sharing_conflict_1(self):

        # Raise an error if world_readable=False but sharing='public'

        kwargs = {
            "filename": "invalid-privacy-setting",
            "world_readable": False,
            "sharing": "public",
        }

        with self.assertRaisesRegexp(
                PlotlyError,
                "setting your plot privacy to both public and private."):
            py.plot(self.simple_figure, **kwargs)
Exemplo n.º 8
0
    def test_private_plot_response_with_and_without_share_key(self):

        # The json file of the private plot should be 404 and once
        # share_key is added it should be 200

        kwargs = {
            "filename": "is_share_key_included2",
            "world_readable": False,
            "auto_open": False,
            "sharing": "private",
        }

        private_plot_url = py.plot(self.simple_figure, **kwargs)
        private_plot_response = requests.get(private_plot_url + ".json")

        # The json file of the private plot should be 404
        self.assertEqual(private_plot_response.status_code, 404)

        secret_plot_url = py.add_share_key_to_url(private_plot_url)
        urlsplit = six.moves.urllib.parse.urlparse(secret_plot_url)
        secret_plot_json_file = six.moves.urllib.parse.urljoin(
            urlsplit.geturl(), "?.json" + urlsplit.query)
        secret_plot_response = requests.get(secret_plot_json_file)

        # The json file of the secret plot should be 200
        self.assertTrue(secret_plot_response.status_code, 200)
Exemplo n.º 9
0
 def test_plot_valid(self):
     fig = {
         'data': [
             {
                 'x': (1, 2, 3),
                 'y': (2, 1, 2)
             }
         ],
         'layout': {'title': {'text': 'simple'}}
     }
     url = py.plot(fig, auto_open=False, filename='plot_valid')
     saved_fig = py.get_figure(url)
     self.assertEqual(saved_fig['data'][0]['x'], fig['data'][0]['x'])
     self.assertEqual(saved_fig['data'][0]['y'], fig['data'][0]['y'])
     self.assertEqual(saved_fig['layout']['title']['text'],
                      fig['layout']['title']['text'])
Exemplo n.º 10
0
 def test_plot_valid(self):
     fig = {
         'data': [
             {
                 'x': (1, 2, 3),
                 'y': (2, 1, 2)
             }
         ],
         'layout': {'title': {'text': 'simple'}}
     }
     url = py.plot(fig, auto_open=False, filename='plot_valid')
     saved_fig = py.get_figure(url)
     self.assertEqual(saved_fig['data'][0]['x'], fig['data'][0]['x'])
     self.assertEqual(saved_fig['data'][0]['y'], fig['data'][0]['y'])
     self.assertEqual(saved_fig['layout']['title']['text'],
                      fig['layout']['title']['text'])
Exemplo n.º 11
0
    def test_plot_url_given_sharing_key(self):

        # Give share_key is requested, the retun url should contain
        # the share_key

        validate = True
        fig = plotly.tools.return_figure_from_figure_or_data(
            self.simple_figure, validate)
        kwargs = {
            "filename": "is_share_key_included2",
            "world_readable": False,
            "auto_open": False,
            "sharing": "secret",
        }
        plot_url = py.plot(fig, **kwargs)

        self.assertTrue("share_key=" in plot_url)
Exemplo n.º 12
0
    def test_plot_url_response_given_sharing_key(self):

        # Given share_key is requested, get request of the url should
        # be 200

        kwargs = {'filename': 'is_share_key_included',
                  'fileopt': 'overwrite',
                  'auto_open': False,
                  'world_readable': False,
                  'sharing': 'secret'}

        plot_url = py.plot(self.simple_figure, **kwargs)
        # shareplot basically always gives a 200 if even if permission denied
        # embedplot returns an actual 404
        embed_url = plot_url.split('?')[0] + '.embed?' + plot_url.split('?')[1]
        response = requests.get(embed_url)

        self.assertEqual(response.status_code, 200)
Exemplo n.º 13
0
 def test_plot_valid(self):
     fig = {
         "data": [{
             "x": (1, 2, 3),
             "y": (2, 1, 2)
         }],
         "layout": {
             "title": {
                 "text": "simple"
             }
         },
     }
     url = py.plot(fig, auto_open=False, filename="plot_valid")
     saved_fig = py.get_figure(url)
     self.assertEqual(saved_fig["data"][0]["x"], fig["data"][0]["x"])
     self.assertEqual(saved_fig["data"][0]["y"], fig["data"][0]["y"])
     self.assertEqual(saved_fig["layout"]["title"]["text"],
                      fig["layout"]["title"]["text"])
Exemplo n.º 14
0
    def test_plot_url_response_given_sharing_key(self):

        # Given share_key is requested, get request of the url should
        # be 200

        kwargs = {'filename': 'is_share_key_included',
                  'fileopt': 'overwrite',
                  'auto_open': False,
                  'world_readable': False,
                  'sharing': 'secret'}

        plot_url = py.plot(self.simple_figure, **kwargs)
        # shareplot basically always gives a 200 if even if permission denied
        # embedplot returns an actual 404
        embed_url = plot_url.split('?')[0] + '.embed?' + plot_url.split('?')[1]
        response = requests.get(embed_url)

        self.assertEqual(response.status_code, 200)
Exemplo n.º 15
0
    def test_plot_url_response_given_sharing_key(self):

        # Given share_key is requested, get request of the url should
        # be 200

        kwargs = {
            "filename": "is_share_key_included2",
            "auto_open": False,
            "world_readable": False,
            "sharing": "secret",
        }

        plot_url = py.plot(self.simple_figure, **kwargs)
        # shareplot basically always gives a 200 if even if permission denied
        # embedplot returns an actual 404
        embed_url = plot_url.split("?")[0] + ".embed?" + plot_url.split("?")[1]
        response = requests.get(embed_url)

        self.assertEqual(response.status_code, 200)
Exemplo n.º 16
0
 def test_plot_invalid_args_1(self):
     with self.assertRaises(TypeError):
         py.plot(x=[1, 2, 3], y=[2, 1, 2], auto_open=False,
                 filename='plot_invalid')
Exemplo n.º 17
0
 def test_plot_invalid_args_2(self):
     with self.assertRaises(ValueError):
         py.plot([1, 2, 3], [2, 1, 2],
                 auto_open=False,
                 filename="plot_invalid")
Exemplo n.º 18
0
 def test_plot_invalid_args_1(self):
     with self.assertRaises(TypeError):
         py.plot(x=[1, 2, 3],
                 y=[2, 1, 2],
                 auto_open=False,
                 filename="plot_invalid")
Exemplo n.º 19
0
 def test_plot_invalid(self):
     fig = {"data": [{"x": [1, 2, 3], "y": [2, 1, 2], "z": [3, 4, 1]}]}
     with self.assertRaises(ValueError):
         py.plot(fig, auto_open=False, filename="plot_invalid")
Exemplo n.º 20
0
 def test_plot_invalid_args_2(self):
     with self.assertRaises(ValueError):
         py.plot([1, 2, 3], [2, 1, 2], auto_open=False,
                 filename='plot_invalid')