예제 #1
0
    def test_import_taplist_io_data(self):
        """Test parsing the JSON data"""
        timestamp = now()
        responses.add(
            responses.GET,
            TaplistDotIOParser.URL.format(
                self.venue_cfg.taplist_io_display_id, ),
            json=self.json_data,
            status=200,
        )
        self.assertFalse(Tap.objects.exists())
        self.assertEqual(Venue.objects.count(), 1)
        self.assertFalse(Beer.objects.exists())
        self.assertFalse(Manufacturer.objects.exists())
        mfg = ManufacturerFactory(name="InnerSpace", )
        ManufacturerAlternateName.objects.bulk_create(
            ManufacturerAlternateName(
                manufacturer=mfg,
                name=name,
            ) for name in [
                "Isb",
                "InnerSpace Brewing  Company",
                "InnerSpace Brewing co",
            ])
        for dummy in range(2):
            # running twice to make sure we're not double-creating
            args = []
            opts = {}
            call_command("parsetaplistio", *args, **opts)

            self.assertEqual(Beer.objects.count(), 10,
                             list(Beer.objects.all()))
            self.assertEqual(Manufacturer.objects.count(), 1)
            self.assertEqual(Tap.objects.count(), 13)
            taps = (Tap.objects.filter(
                venue=self.venue,
                tap_number__in=[1, 2, 10],
            ).select_related(
                "beer__style",
                "beer__manufacturer",
            ).order_by("tap_number"))
            tap = taps[0]
            self.assertEqual(tap.beer.name, "SkyFarmer Farmhouse Ale")
            self.assertEqual(tap.beer.manufacturer.name, mfg.name)
            self.assertEqual(tap.beer.style.name, "Farmhouse Ale")
            self.assertEqual(tap.time_updated, self.timestamp)
            # location nulled out in test data
            tap = taps[1]
            self.assertIsNone(tap.beer_id)
            self.assertEqual(tap.time_updated, self.timestamp)
            tap = taps[2]
            self.assertEqual(tap.beer.manufacturer.name, mfg.name)
            self.assertEqual(tap.beer.name, "Denver Destroyer")
            # NOTE: Yes, really.
            self.assertEqual(tap.beer.style.name, "An elusive IPA")
            self.assertEqual(tap.time_updated, self.timestamp)
        self.venue.refresh_from_db()
        self.assertIsNotNone(self.venue.tap_list_last_check_time)
        self.assertGreater(self.venue.tap_list_last_check_time, timestamp)
        self.assertIsNotNone(self.venue.tap_list_last_update_time)
예제 #2
0
 def test_guess_manufacturer_back_forty(self):
     mfg = ManufacturerFactory(name="Back Forty")
     ManufacturerAlternateName.objects.bulk_create(
         ManufacturerAlternateName(name=name, manufacturer=mfg)
         for name in ["Back Forty", "Back Forty Beer Co"])
     parser = StemAndSteinParser()
     guessed = parser.guess_beer("Back Forty Truck Stop Honey Brown")
     self.assertEqual(guessed.manufacturer, mfg)