def test_download_cn(self):
        import_fakedata()
        with self.app.test_client() as c:
            response = c.get('/download?cn=34,TO', follow_redirects=True)
            data = response.get_data().decode('utf-8')

            shouldbe = (
                "#DEVICE_TYPE,DEVICE_ID,AIRCRAFT_MODEL,REGISTRATION,CN,TRACKED,IDENTIFIED\n"
                "'O','ABCDEF','Rhönlärche Ил-32','D-OTTO','TO','Y','Y'\n"
                "'F','DD1234','ASK-13','D-1234','34','Y','Y'\n")

            self.assertEqual(data, shouldbe)
    def test_download_from_id(self):
        import_fakedata()
        with self.app.test_client() as c:
            response = c.get('/download?from_id=DD1234', follow_redirects=True)
            data = response.get_data().decode('utf-8')

            shouldbe = (
                "#DEVICE_TYPE,DEVICE_ID,AIRCRAFT_MODEL,REGISTRATION,CN,TRACKED,IDENTIFIED\n"
                "'F','DD1234','ASK-13','D-1234','34','Y','Y'\n"
                "'F','DD4711','ASH-25','D-4711','11','Y','Y'\n")

            self.assertEqual(data, shouldbe)
    def test_download(self):
        import_fakedata()
        with self.app.test_client() as c:
            response = c.get('/download', follow_redirects=True)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.charset, 'utf-8')
            self.assertEqual(response.mimetype, 'text/plain')
            data = response.get_data().decode('utf-8')

            shouldbe = (
                "#DEVICE_TYPE,DEVICE_ID,AIRCRAFT_MODEL,REGISTRATION,CN,TRACKED,IDENTIFIED\n"
                "'O','ABCDEF','Rhönlärche Ил-32','D-OTTO','TO','Y','Y'\n"
                "'F','DD1234','ASK-13','D-1234','34','Y','Y'\n"
                "'F','DD4711','ASH-25','D-4711','11','Y','Y'\n")

            self.assertEqual(data, shouldbe)
    def test_download_j_t(self):
        import_fakedata()
        with self.app.test_client() as c:
            response = c.get('/download?j=1&t=1', follow_redirects=True)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.charset, 'utf-8')
            self.assertEqual(response.mimetype, 'application/json')
            self.assertTrue(response.is_json)
            data = response.get_data()
            json_data = json.loads(data)

            shouldbe = {
                "devices": [
                    {
                        "aircraft_model": "Rhönlärche Ил-32",
                        "cn": "TO",
                        "device_id": "ABCDEF",
                        "device_type": "O",
                        "identified": "Y",
                        "registration": "D-OTTO",
                        "tracked": "Y",
                        "aircraft_type": "1"
                    },
                    {
                        "aircraft_model": "ASK-13",
                        "cn": "34",
                        "device_id": "DD1234",
                        "device_type": "F",
                        "identified": "Y",
                        "registration": "D-1234",
                        "tracked": "Y",
                        "aircraft_type": "1"
                    },
                    {
                        "aircraft_model": "ASH-25",
                        "cn": "11",
                        "device_id": "DD4711",
                        "device_type": "F",
                        "identified": "Y",
                        "registration": "D-4711",
                        "tracked": "Y",
                        "aircraft_type": "1"
                    },
                ]
            }

            self.assertEqual(json_data, shouldbe)
    def test_download_fln(self):
        import_fakedata()
        with self.app.test_client() as c:
            response = c.get('/download/download-fln.php',
                             follow_redirects=True)
            data = response.get_data().decode('utf-8')
            decoded_data = '\n'.join(
                codecs.decode(line, "hex").decode('utf-8')
                for line in data.split('\n')[1:])

            shouldbe = (
                "ABCDEF                                          Rh?nl?rche ?-32      D-OTTO TO        \n"
                "DD1234                                          ASK-13               D-1234 34        \n"
                "DD4711                                          ASH-25               D-4711 11        "
            )

            self.assertEqual(decoded_data, shouldbe)
Example #6
0
    def fakedata():
        """Fills db with fake data for debugging purposes."""
        from app.filldata import import_fakedata

        import_fakedata()