|
| 1 | +import unittest |
| 2 | +from scrapy.http import TextResponse |
| 3 | +import json |
| 4 | + |
| 5 | +from jedeschule.spiders.brandenburg import BrandenburgSpider |
| 6 | + |
| 7 | + |
| 8 | +class TestBrandenburgSpider(unittest.TestCase): |
| 9 | + |
| 10 | + def test_parse(self): |
| 11 | + json_text = json.dumps({ |
| 12 | + "type": "FeatureCollection", |
| 13 | + "name": "Schul_Standorte", |
| 14 | + "features": [ |
| 15 | + { |
| 16 | + "type": "Feature", |
| 17 | + "properties": { |
| 18 | + "schul_nr": "100020", |
| 19 | + "schulname": "Grundschule Forst Mitte", |
| 20 | + "strasse_hausnr": "Max-Fritz-Hammer-Straße 15", |
| 21 | + "plz": "03149", |
| 22 | + "ort": "Forst (Lausitz)", |
| 23 | + "telefonnummer": "(03562) 7163", |
| 24 | + "faxnummer": "(03562) 691288", |
| 25 | + "dienst_email": "[email protected]", |
| 26 | + "homepage": "http://www.grundschule-forst-mitte.de", |
| 27 | + "schulamtname": "Staatliches Schulamt Cottbus", |
| 28 | + "kreis": "Spree-Neiße", |
| 29 | + "schulform_kurzbez": "G", |
| 30 | + "schulform": "Grundschule", |
| 31 | + "traeger": "Gemeinde", |
| 32 | + "schultraeger_grp": "o", |
| 33 | + "schueler": "288 (Stand: 2022)", |
| 34 | + "besonderheiten_sl": "(763),(561),(132),(201)", |
| 35 | + "besonderheiten": [ |
| 36 | + "Einstiegsphase Startchancen", |
| 37 | + "Schule mit Nutzung Schul-Cloud Brandenburg", |
| 38 | + "verlässliche Halbtagsschule und Hort", |
| 39 | + "FLEX - Optimierung des Schulanfangs" |
| 40 | + ], |
| 41 | + "studienseminar": "2", |
| 42 | + "fremdsprachen": ["Englisch"], |
| 43 | + "fremdsprachen_sl": "(EN)", |
| 44 | + "fremdsprachen_timestmp": "(Schuljahr: 2020/2021)" |
| 45 | + }, |
| 46 | + "geometry": { |
| 47 | + "type": "Point", |
| 48 | + "coordinates": [14.651148207215728, 51.74023651973522] |
| 49 | + } |
| 50 | + } |
| 51 | + ] |
| 52 | + }) |
| 53 | + |
| 54 | + spider = BrandenburgSpider() |
| 55 | + response = TextResponse( |
| 56 | + url="http://test_webserver.com", |
| 57 | + body=json_text.encode("utf-8"), |
| 58 | + encoding="utf-8", |
| 59 | + ) |
| 60 | + |
| 61 | + results = list(spider.parse(response)) |
| 62 | + |
| 63 | + self.assertEqual(len(results), 1) |
| 64 | + school = results[0] |
| 65 | + |
| 66 | + self.assertAlmostEqual(school["lat"], 51.74023651973522) |
| 67 | + self.assertAlmostEqual(school["lon"], 14.651148207215728) |
| 68 | + |
| 69 | + self.assertEqual(school["schul_nr"], "100020") |
| 70 | + self.assertEqual(school["schulname"], "Grundschule Forst Mitte") |
| 71 | + self.assertEqual(school["plz"], "03149") |
| 72 | + self.assertEqual(school["ort"], "Forst (Lausitz)") |
| 73 | + self. assertEqual( school[ "dienst_email"], "[email protected]") |
| 74 | + self.assertEqual(school["schulform"], "Grundschule") |
| 75 | + self.assertEqual(school["traeger"], "Gemeinde") |
| 76 | + |
| 77 | + |
| 78 | +if __name__ == '__main__': |
| 79 | + unittest.main() |
0 commit comments