import os
import app
import unittest
import tempfile
import mock

class HomeTestCase(unittest.TestCase):

    def setUp(self):
        self.db_fd, app.app.config['DATABASE'] = tempfile.mkstemp()
        app.app.config['TESTING'] = True
        self.app = app.app.test_client()
        #app.init_db()

    def tearDown(self):
        os.close(self.db_fd)
        os.unlink(app.app.config['DATABASE'])

    @mock.patch('requests.get')
    def test_property(self, get_mock):
        class MockResponse(object):
            status_code = 200
            def json(self):
                return {
                "title": {
                    "title_number": "AB1234",
                    "address": "123 Fake St",
                    "registered_owners": [
                        {
                            "name": "Victor"
                        }
                    ],
                    "extent": {
                        "geometry": {
                            "type": "MultiPolygon",
                            "coordinates": [
                                [
                                    [
                                        [
                                            14708.755563011973,
                                            6761018.225448865
                                        ]
                                    ]
                                ]
                            ]
                        }
                    }
                }
            }
        get_mock.return_value = MockResponse()
        rv = self.app.get('/properties/EX1354')
        assert 'Your property' in rv.data
        assert '123 Fake St' in rv.data

if __name__ == '__main__':
    unittest.main()

@@ -1675,16 +1675,2664 @@
 v.data%0A%0A
+    @mock.patch('requests.get')%0A    def test_postcode_filter(self, get_mock):%0A        class MockResponse(object):%0A            status_code = 200%0A            def json(self):%0A                return %0A                %7B%0A                    %22titles%22: %5B%0A                        %7B%0A                            %22title_id%22: %22AB1234%22,%0A                            %22address%22: %22123 Fake St%22,%0A                            %22registered_owners%22: %5B%0A                                %7B%0A                                    %22name%22: %22Victor%22%0A                                %7D%0A                            %5D,%0A                            %22extent%22: %7B%0A                                %22geometry%22: %7B%0A                                    %22type%22: %22MultiPolygon%22,%0A                                    %22coordinates%22: %5B%0A                                        %5B%0A                                            %5B%0A                                                %5B%0A                                                    14708.755563011973,%0A                                                    6761018.225448865%0A                                                %5D%0A                                            %5D%0A                                        %5D%0A                                    %5D%0A                                %7D%0A                            %7D%0A                        %7D,%0A                        %7B%0A                            %22title_id%22: %22AB1235%22,%0A                            %22address%22: %22124 Fake St%22,%0A                            %22registered_owners%22: %5B%0A                                %7B%0A                                    %22name%22: %22Kiam%22%0A                                %7D%0A                            %5D,%0A                            %22extent%22: %7B%0A                                %22geometry%22: %7B%0A                                    %22type%22: %22MultiPolygon%22,%0A                                    %22coordinates%22: %5B%0A                                        %5B%0A                                            %5B%0A                                                %5B%0A                                                    14709.755563011973,%0A                                                    6761010.225448865%0A                                                %5D%0A                                            %5D%0A                                        %5D%0A                                    %5D%0A                                %7D%0A                            %7D%0A                        %7D%0A                    %5D%0A                %7D                    %0A        get_mock.return_value = MockResponse()%0A        rv = self.app.get('/properties?postcode=AB12 3CD')%0A        assert '123 Fake St' in rv.data%0A        assert '124 Fake St' in rv.data%0A%0A
 if __nam

add postcode search test case