# Path: tsuru_autoscale/datasource/forms.py
# class DataSourceForm(forms.Form):
#     name = forms.CharField()
#     url = forms.CharField()
#     method = forms.CharField()
#     body = forms.CharField(required=False)
#     headers = forms.CharField(required=False)
# 
# Path: tsuru_autoscale/datasource/client.py
# def host():
# def new(data, token):
# def list(token):
# def remove(name, token):
# def get(name, token):


from django.test import TestCase
from django.core.urlresolvers import reverse
from tsuru_autoscale.datasource.forms import DataSourceForm
from tsuru_autoscale.datasource import client
import httpretty
import mock
import os
        response = self.client.post(url, {})
        self.assertFalse(response.context['form'].is_valid())

    @mock.patch("tsuru_autoscale.datasource.client.list")
    @mock.patch("tsuru_autoscale.datasource.client.new")
    def test_new_post(self, new_mock, list_mock):
        data = {
            'url': u'someurl',
            'body': u'',
            'headers': u'',
            'name': u'name',
            'method': u'GET',
        }

        url = "{}?TSURU_TOKEN=bla".format(reverse("datasource-new"))
        response = self.client.post(url, data)

        url = "{}?TSURU_TOKEN=bla".format(reverse("datasource-list"))
        self.assertRedirects(response, url)
        new_mock.assert_called_with(data, "bla")


class DataSourceListTest(TestCase):
    @mock.patch("tsuru_autoscale.datasource.client.list")
    def test_list(self, list_mock):
        url = "{}?TSURU_TOKEN=bla".format(reverse("datasource-list"))
        response = self.client.get(url)

        self.assertTemplateUsed(response, "datasource/list.html")
        self.assertIn('list', response.context)

# Path: tsuru_autoscale/datasource/forms.py
# class DataSourceForm(forms.Form):
#     name = forms.CharField()
#     url = forms.CharField()
#     method = forms.CharField()
#     body = forms.CharField(required=False)
#     headers = forms.CharField(required=False)
# 
# Path: tsuru_autoscale/datasource/client.py
# def host():
# def new(data, token):
# def list(token):
# def remove(name, token):
# def get(name, token):


# Path: tsuru_autoscale/datasource/tests.py
from django.test import TestCase
from django.core.urlresolvers import reverse
from tsuru_autoscale.datasource.forms import DataSourceForm
from tsuru_autoscale.datasource import client
import httpretty
import mock
import os

        response = self.client.post(url, {})
        self.assertFalse(response.context['form'].is_valid())

    @mock.patch("tsuru_autoscale.datasource.client.list")
    @mock.patch("tsuru_autoscale.datasource.client.new")
    def test_new_post(self, new_mock, list_mock):
        data = {
            'url': u'someurl',
            'body': u'',
            'headers': u'',
            'name': u'name',
            'method': u'GET',
        }

        url = "{}?TSURU_TOKEN=bla".format(reverse("datasource-new"))
        response = self.client.post(url, data)

        url = "{}?TSURU_TOKEN=bla".format(reverse("datasource-list"))
        self.assertRedirects(response, url)
        new_mock.assert_called_with(data, "bla")


class DataSourceListTest(TestCase):
    @mock.patch("tsuru_autoscale.datasource.client.list")
    def test_list(self, list_mock):
        url = "{}?TSURU_TOKEN=bla".format(reverse("datasource-list"))
        response = self.client.get(url)

        self.assertTemplateUsed(response, "datasource/list.html")
        self.assertIn('list', response.context)

        list_mock.assert_called_with("bla")