def test_fetch_apn_with_invalid_county(self):
        self.subject.create(county='sanfrancisco',
                            block_number='0253A',
                            lot_number='086',
                            address='My special address')

        invalid_apn_identifier = APNIdentifier(county='la',
                                               block_number='0253A',
                                               lot_number='086')
        apn = None

        def success(incoming_apn):
            nonlocal apn
            apn = incoming_apn

        exception = None
        apn_identifier = None

        def failure(incoming_exception,
                    incoming_apn_identifier):
            nonlocal exception
            nonlocal apn_identifier
            exception = incoming_exception
            apn_identifier = incoming_apn_identifier

        self.subject.fetch_apn(apn_identifier=invalid_apn_identifier,
                               success=success,
                               failure=failure)

        self.assertIsNone(apn)
        self.assertEqual(exception, ValueError)
        assert_apn_identifiers_equal(apn_identifier, invalid_apn_identifier, self)
 def test_present_apn_with_invalid_identifier_notifies_observer(self):
     self.repository.create(county='sanfrancisco',
                            block_number='asdf',
                            lot_number='zxcv',
                            address='my special address')
     invalid_apn_identifier = APNIdentifier(county='la',
                                            block_number='asdf',
                                            lot_number='zxcv')
     observer = FakeObserver()
     self.subject.execute(apn_identifier=invalid_apn_identifier,
                          observer=observer)
     self.assertEqual(observer.exception, ValueError)
     self.assertIsNotNone(observer.context)
     assert_apn_identifiers_equal(observer.presented_apn_identifier, invalid_apn_identifier, self)
 def test_present_apn_with_valid_identifier_notifies_observer(self):
     self.repository.create(county='sanfrancisco',
                            block_number='asdf',
                            lot_number='zxcv',
                            address='my special address')
     valid_apn_identifier = APNIdentifier(county='sanfrancisco',
                                          block_number='asdf',
                                          lot_number='zxcv')
     observer = FakeObserver()
     self.subject.execute(apn_identifier=valid_apn_identifier,
                          observer=observer)
     expected_apn = APN(county='sanfrancisco',
                        block_number='asdf',
                        lot_number='zxcv',
                        address='my special address')
     assert_apns_equal(observer.presented_apn, expected_apn, self)
     assert_apn_identifiers_equal(observer.presented_apn_identifier, valid_apn_identifier, self)