
from django.test import TestCase


class SimpleTest(TestCase):
    def test_basic_addition(self):
        """
        Tests that 1 + 1 always equals 2.
        """
        self.assertEqual(1 + 1, 2)

from django.test import TestCase
from django.core.urlresolvers import reverse

from publicbody.models import PublicBody

class PublicBodyTest(TestCase):
    fixtures = ['auth.json', 'publicbodies.json', 'foirequest.json']

    def test_web_page(self):
        response = self.client.get(reverse('publicbody-list'))
        self.assertEqual(response.status_code, 200)
        pb = PublicBody.objects.all()[0]
        response = self.client.get(reverse('publicbody-show', kwargs={"slug": pb.slug}))
        self.assertEqual(response.status_code, 200)
        response = self.client.get(reverse('publicbody-show_json', kwargs={"pk": pb.pk, "format": "json"}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'], 'application/json')
        self.assertIn('"name":', response.content)
        self.assertIn('"laws": [{', response.content)
        response = self.client.get(reverse('publicbody-show_json', kwargs={"slug": pb.slug, "format": "json"}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'], 'application/json')

    def test_csv(self):
        csv = PublicBody.export_csv()
        self.assertTrue(csv)

    def test_search(self):
        response = self.client.get(reverse('publicbody-search')+"?q=umwelt")
        self.assertIn("Umweltbundesamt", response.content)
        self.assertEqual(response['Content-Type'], 'application/json')

Test public body showing, json view and csv export
Test public body showing, json view and csv export
+ from django.test import TestCase
+ from django.core.urlresolvers import reverse
  
- from django.test import TestCase
+ from publicbody.models import PublicBody
  
+ class PublicBodyTest(TestCase):
+     fixtures = ['auth.json', 'publicbodies.json', 'foirequest.json']
  
- class SimpleTest(TestCase):
-     def test_basic_addition(self):
-         """
-         Tests that 1 + 1 always equals 2.
-         """
-         self.assertEqual(1 + 1, 2)
+     def test_web_page(self):
+         response = self.client.get(reverse('publicbody-list'))
+         self.assertEqual(response.status_code, 200)
+         pb = PublicBody.objects.all()[0]
+         response = self.client.get(reverse('publicbody-show', kwargs={"slug": pb.slug}))
+         self.assertEqual(response.status_code, 200)
+         response = self.client.get(reverse('publicbody-show_json', kwargs={"pk": pb.pk, "format": "json"}))
+         self.assertEqual(response.status_code, 200)
+         self.assertEqual(response['Content-Type'], 'application/json')
+         self.assertIn('"name":', response.content)
+         self.assertIn('"laws": [{', response.content)
+         response = self.client.get(reverse('publicbody-show_json', kwargs={"slug": pb.slug, "format": "json"}))
+         self.assertEqual(response.status_code, 200)
+         self.assertEqual(response['Content-Type'], 'application/json')
  
+     def test_csv(self):
+         csv = PublicBody.export_csv()
+         self.assertTrue(csv)
+ 
+     def test_search(self):
+         response = self.client.get(reverse('publicbody-search')+"?q=umwelt")
+         self.assertIn("Umweltbundesamt", response.content)
+         self.assertEqual(response['Content-Type'], 'application/json')
+ 
Test public body showing, json view and csv export
## Code Before:

from django.test import TestCase


class SimpleTest(TestCase):
    def test_basic_addition(self):
        """
        Tests that 1 + 1 always equals 2.
        """
        self.assertEqual(1 + 1, 2)

## Instruction:
Test public body showing, json view and csv export
## Code After:
from django.test import TestCase
from django.core.urlresolvers import reverse

from publicbody.models import PublicBody

class PublicBodyTest(TestCase):
    fixtures = ['auth.json', 'publicbodies.json', 'foirequest.json']

    def test_web_page(self):
        response = self.client.get(reverse('publicbody-list'))
        self.assertEqual(response.status_code, 200)
        pb = PublicBody.objects.all()[0]
        response = self.client.get(reverse('publicbody-show', kwargs={"slug": pb.slug}))
        self.assertEqual(response.status_code, 200)
        response = self.client.get(reverse('publicbody-show_json', kwargs={"pk": pb.pk, "format": "json"}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'], 'application/json')
        self.assertIn('"name":', response.content)
        self.assertIn('"laws": [{', response.content)
        response = self.client.get(reverse('publicbody-show_json', kwargs={"slug": pb.slug, "format": "json"}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'], 'application/json')

    def test_csv(self):
        csv = PublicBody.export_csv()
        self.assertTrue(csv)

    def test_search(self):
        response = self.client.get(reverse('publicbody-search')+"?q=umwelt")
        self.assertIn("Umweltbundesamt", response.content)
        self.assertEqual(response['Content-Type'], 'application/json')
