import requests

from django.test import TestCase
from tastypie.test import ResourceTestCase
from tastypie.models import ApiKey
from django.contrib.auth.models import User

from datapoints.models import Indicator
from source_data.models import Source, Document
# class DataPointApiTestCase(TestCase):
#
#     def set_up(self):
#
#         pass
#
#     def test_the_api(self):
#
#         self.set_up()

class IndicatorResourceTest(ResourceTestCase):

     def setUp(self):
        super(IndicatorResourceTest, self).setUp()

        # Create a user.
        self.username = 'john'
        self.password = 'pass'
        self.user = User.objects.create_user(self.username,
            'john@john.com', self.password)

        # create their api_key
        self.api_key = ApiKey.objects.create(user=self.user)

        self.source = Source.objects.create(
            source_name = 'test',
            source_description = 'test')

        self.document_id = Document.objects.create(
            doc_text = 'test',
            created_by_id = self.user.id,
            guid = 'test').id

        # # create create an indicator
        Indicator.objects.create(name='First Indicator',
            description='First Indicator Description',source=self.source)


     def test_indicator_get(self):

        resp = self.api_client.get('/api/v1/indicator', format='json',\
            username='john',api_key=self.api_key)

        print resp

        pass

    # def test_indicator_get(self):
    #    super(IndicatorResourceTest, self).setUp()
    #
    #    pass



    # def test_get_list_json(self):
    #     resp = self.api_client.get('/api/v1/indicator/', format='json',\
    #         usernmae='john',api_key=self.api_key,\
    #         authentication=self.get_credentials())
    #
    #     # x = resp.__dict__
    #     # pp.pprint(x)
    #
    #     self.assertValidJSONResponse(resp)

@@ -258,148 +258,8 @@
 ent%0A
-# class DataPointApiTestCase(TestCase):%0A#%0A#     def set_up(self):%0A#%0A#         pass%0A#%0A#     def test_the_api(self):%0A#%0A#         self.set_up()
 %0A%0Acl
@@ -986,16 +986,33 @@
 %0A       
+ self.indicator =
  Indicat
@@ -1053,16 +1053,16 @@
 cator',%0A
-
         
@@ -1128,16 +1128,145 @@
 ource)%0A%0A
+        print self.indicator.id%0A        print self.indicator.id%0A        print self.indicator.id%0A        print self.indicator.id%0A%0A
 %0A     de
@@ -1429,18 +1429,81 @@
     
-print 
+# ensure the response is valid%0A        self.assertValidJSONResponse(
 resp
+)
 %0A%0A  

test status code of response