def __init__(self, user: CouchUser, *args, **kwargs): super(InitiateAddSMSBackendForm, self).__init__(*args, **kwargs) from corehq.messaging.smsbackends.telerivet.models import SQLTelerivetBackend backend_classes = get_sms_backend_classes() backend_choices = [] for api_id, klass in backend_classes.items(): if is_superuser_or_contractor( user) or api_id == SQLTelerivetBackend.get_api_id(): friendly_name = klass.get_generic_name() backend_choices.append((api_id, friendly_name)) backend_choices = sorted(backend_choices, key=lambda backend: backend[1]) self.fields['hq_api_id'].choices = backend_choices self.helper = HQFormHelper() self.helper.layout = crispy.Layout( hqcrispy.B3MultiField( _("Create Another Gateway"), InlineField('action'), Div(InlineField('hq_api_id', css_class="ko-select2"), css_class='col-sm-6 col-md-6 col-lg-4'), Div(StrictButton(mark_safe( '<i class="fa fa-plus"></i> Add Another Gateway'), css_class='btn-primary', type='submit', style="margin-left:5px;"), css_class='col-sm-3 col-md-2 col-lg-2'), ), )
def test_normal_user(): user = CouchUser(username="******") assert_false(is_superuser_or_contractor(user))
def test_superuser(): user = CouchUser(username="******", is_superuser=True) assert_true(is_superuser_or_contractor(user))
def test_contractor(): user = CouchUser(username="******") with flag_enabled('IS_CONTRACTOR'): assert_true(is_superuser_or_contractor(user))