'If you invite someone with a different domain from that of the realm
when `restricted_to_domain = False`, but `restricted_to_domain` later
changes to true, the invitation should succeed but the invitee\'s signup
attempt should fail.'

def test_invite_outside_domain_before_closing(self):

    zulip_realm = get_realm('zulip')
    zulip_realm.restricted_to_domain = False
    zulip_realm.save()
    self.login(self.example_email('hamlet'))
    external_address = 'foo@example.com'
    self.assert_json_success(self.invite(external_address, ['Denmark']))
    self.check_sent_emails([external_address])
    zulip_realm.restricted_to_domain = True
    zulip_realm.save()
    result = self.submit_reg_form_for_user('foo@example.com', 'password')
    self.assertEqual(result.status_code, 200)
    self.assert_in_response('only    allows    users    with    e-mail', result)
