"""
test_plot_mpl:
==============

A module intended for use with Nose.

"""
from __future__ import absolute_import

import matplotlib

# Force matplotlib to not use any Xwindows backend.
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from nose.plugins.attrib import attr
from nose.tools import raises

from plotly import exceptions
from plotly.plotly import plotly as py
from plotly.tests.utils import PlotlyTestCase


class PlotMPLTest(PlotlyTestCase):
    @raises(exceptions.PlotlyError)
    def test_update_type_error(self):
        fig, ax = plt.subplots()
        ax.plot([1, 2, 3])
        update = []
        py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False)

    @raises(exceptions.PlotlyError)
    def test_update_validation_error(self):
        fig, ax = plt.subplots()
        ax.plot([1, 2, 3])
        update = {'invalid': 'anything'}
        py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False)

    @attr('slow')
    def test_update(self):
        fig, ax = plt.subplots()
        ax.plot([1, 2, 3])
        title = 'new title'
        update = {'layout': {'title': title}}
        url = py.plot_mpl(fig, update=update, filename="nosetests",
                          auto_open=False)
        un = url.replace("https://plot.ly/~", "").split('/')[0]
        fid = url.replace("https://plot.ly/~", "").split('/')[1]
        pfig = py.get_figure(un, fid)
        assert pfig['layout']['title'] == title

"""
test_plot_mpl:
==============

A module intended for use with Nose.

"""
from __future__ import absolute_import

import matplotlib

# Force matplotlib to not use any Xwindows backend.
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from nose.plugins.attrib import attr
from nose.tools import raises

from plotly import exceptions
from plotly.plotly import plotly as py
from unittest import TestCase


class PlotMPLTest(TestCase):
    def setUp(self):
        py.sign_in('PlotlyImageTest', '786r5mecv0',
                   plotly_domain='https://plot.ly')

    @raises(exceptions.PlotlyError)
    def test_update_type_error(self):
        fig, ax = plt.subplots()
        ax.plot([1, 2, 3])
        update = []
        py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False)

    @raises(exceptions.PlotlyError)
    def test_update_validation_error(self):
        fig, ax = plt.subplots()
        ax.plot([1, 2, 3])
        update = {'invalid': 'anything'}
        py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False)

    @attr('slow')
    def test_update(self):
        fig, ax = plt.subplots()
        ax.plot([1, 2, 3])
        title = 'new title'
        update = {'layout': {'title': title}}
        url = py.plot_mpl(fig, update=update, filename="nosetests",
                          auto_open=False)
        un = url.replace("https://plot.ly/~", "").split('/')[0]
        fid = url.replace("https://plot.ly/~", "").split('/')[1]
        pfig = py.get_figure(un, fid)
        assert pfig['layout']['title'] == title

add authentication to mpl tests