def test_crud(self):
        """
        Tests CRUD for testplan model.
        """
        import json

        def create():
            body = json.dumps({
                "name": "CRUD test with rule",
                "rules": [
                    {
                        'ruleType': 'request',
                        'name': 'test_rule_3',
                        'enabled': True,
                        'filter': {
                            'httpProtocol': 'HTTP/1.1',
                            'method': 'GET',
                            'headers': [
                                {'key': 'foo'},
                                {'key': 'fizz', 'value': 'buzz'},
                            ],
                        },
                        'action': {
                            'type': 'modify',
                            'method': 'PUT',
                            'url': 'www.newurl.com/foo/bar',
                            'setHeaders': [
                                {
                                    'key': 'zaphod', 'value': 'beeblebrox',
                                },
                            ],
                            'deleteHeaders': [
                                {
                                    'key': 'foo',
                                },
                            ],
                        }
                    },
                    ],
            })

            self.login(admin_username, admin_password)
            response = self.client.post(path=api_url + "/testplan/",
                                        data=body,
                                        content_type="application/json",
                                        HTTP_X_AUTH_TOKEN=self.x_auth_token)
            self.assertEqual(response.status_code, 200)
            self.assertIn("location", response._headers)
            in_json = json.loads(response.content)
            self.assertIn("id", in_json)
            self.testplan_id = in_json['id']

        def read():
            self.login(admin_username, admin_password)
            response = self.client.get(path=api_url + "/testplan/" + self.testplan_id,
                                       HTTP_X_AUTH_TOKEN=self.x_auth_token)
            self.assertEqual(response.status_code, 200)

        def update():
            body = json.dumps({
                "name": "CRUD test with rule, name updated",
                "rules": [
                    {
                        'ruleType': 'request',
                        'filter': {
                            'httpProtocol': 'HTTP/1.1',
                            'method': 'GET',
                            'headers': [
                                {'key': 'paul bunyon'},
                                {'key': 'companion', 'value': 'blue oxe'},
                            ],
                        },
                        'action': {
                            'type': 'newResponse',
                            'httpProtocol': 'CARRIERPIGEON/1.1',
                            'statusCode': 403,
                            'statusDescription': 'TOO RIDICULOUS',
                            'headers': [
                                {
                                    'key': 'User-Agent',
                                    'value': 'Broken Telescope 1.9'
                                },
                            ],
                            'payload': 'The answer to life, the universe, and everything...is 42.',
                        }
                    },
                    ],
            })

            self.login(admin_username, admin_password)
            response = self.client.put(path=api_url + "/testplan/" + self.testplan_id,
                                       data=body,
                                       content_type="application/json",
                                       HTTP_X_AUTH_TOKEN=self.x_auth_token)
            self.assertEqual(response.status_code, 200)

        def delete():
            self.login(admin_username, admin_password)
            response = self.client.delete(path=api_url + "/testplan/" + self.testplan_id,
                                          HTTP_X_AUTH_TOKEN=self.x_auth_token)
            self.assertEqual(response.status_code, 200)

        print("Testing CREATE in %s" % self.__class__)
        create()

        print("Testing READ in %s" % self.__class__)
        read()

        print("Testing UPDATE in %s" % self.__class__)
        update()

        print("Testing DELETE in %s" % self.__class__)
        delete()
dataset/ETHPy150Open emccode/heliosburn/heliosburn/django/hbproject/api/tests.py/TestplanViewTestCase.test_crud/original