def test_duplicate_registration(self): """Notify user of attempted duplicate registration.""" user = EmailUserFactory(password='******') provider_type = ProviderTypeFactory() self.load_page_and_set_language() menu = self.wait_for_element('menu') registration = menu.find_elements_by_link_text('Provider Registration')[0] registration.click() form = self.wait_for_element('provider-form') self.assertHashLocation('/register') data = { 'name': 'Joe Provider', 'phone_number': '12-345678', 'description': 'Test provider', 'focal_point_name': 'John Doe', 'focal_point_phone_number': '87-654321', 'address': '1313 Mockingbird Lane, Beirut, Lebanon', 'email': user.email, 'password1': 'foobar', 'password2': 'foobar', 'number_of_monthly_beneficiaries': '37', 'type': provider_type.name, } self.submit_form(form, data, button_class='form-btn-submit') error = self.wait_for_element('label[for="id_email"] .error', match=By.CSS_SELECTOR) self.assertIn('email already exists', error.text)
def test_register(self): """Register for a new site account.""" provider_type = ProviderTypeFactory() self.load_page_and_set_language() menu = self.wait_for_element('menu') registration = menu.find_elements_by_link_text('Provider Registration')[0] registration.click() form = self.wait_for_element('provider-form') self.assertHashLocation('/register') data = { 'name': 'Joe Provider', 'phone_number': '12-345678', 'description': 'Test provider', 'focal_point_name': 'John Doe', 'focal_point_phone_number': '87-654321', 'address': '1313 Mockingbird Lane, Beirut, Lebanon', 'email': '*****@*****.**', 'password1': 'foobar', 'password2': 'foobar', 'number_of_monthly_beneficiaries': '37', 'type': provider_type.name, } self.submit_form(form, data, button_class='form-btn-submit') self.wait_for_page_title_contains('Submitted Successfully', timeout=2 * DEFAULT_TIMEOUT) self.assertHashLocation('/register/confirm')
def test_staff_add_providers(self): # Remember, only one provider per user self.user.is_staff = True self.user.save() type1 = ProviderTypeFactory() provider1 = ProviderFactory.build(type=type1, user=self.user) # Doesn't save user2 = EmailUserFactory() type2 = ProviderTypeFactory() provider2 = ProviderFactory.build(type=type2, user=user2) # Doesn't save book = get_export_workbook([provider1, provider2]) rsp = self.import_book(book) self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8')) self.assertTrue( Provider.objects.filter(name_en=provider1.name_en).exists()) self.assertTrue( Provider.objects.filter(name_en=provider2.name_en).exists())
def test_provider_add_provider(self): type = ProviderTypeFactory() provider = ProviderFactory.build(type=type, user=self.user) # Doesn't save self.assertFalse(provider.id) book = get_export_workbook([provider]) rsp = self.import_book(book) # self.fail(rsp.content.decode('utf-8')) self.assertContains(rsp, "Non-staff users may not create new providers", status_code=BAD_REQUEST)
def test_staff_add_provider(self): type = ProviderTypeFactory() self.user.is_staff = True self.user.save() provider = ProviderFactory.build(type=type, user=self.user) # Doesn't save self.assertFalse(provider.id) book = get_export_workbook([provider]) rsp = self.import_book(book) self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8')) self.assertTrue( Provider.objects.filter(name_en=provider.name_en).exists())
def test_staff_add_bad_provider(self): type = ProviderTypeFactory() self.user.is_staff = True self.user.save() provider = ProviderFactory.build( type=type, user=self.user, number_of_monthly_beneficiaries=-1) # Doesn't save self.assertFalse(provider.id) book = get_export_workbook([provider]) rsp = self.import_book(book) self.assertContains( rsp, "Row 2: number_of_monthly_beneficiaries: Ensure this value is " "greater than or equal to 0.", status_code=BAD_REQUEST)
def test_staff_change_providers(self): # Staff can change multiple providers self.user.is_staff = True self.user.save() provider1 = ProviderFactory() provider2 = ProviderFactory() # Tweak some data provider1.name_en = 'Jim-Bob' provider1.name_ar = 'Ahmed-Bob' provider1.name_fr = 'Pierre-Bob' provider2.number_of_monthly_beneficiaries = 1024 provider2.type = ProviderTypeFactory() book = get_export_workbook([provider1, provider2]) rsp = self.import_book(book) self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8')) new_provider1 = Provider.objects.get(id=provider1.id) self.assertEqual(provider1.name_en, new_provider1.name_en) self.assertEqual(provider1.name_ar, new_provider1.name_ar) self.assertEqual(provider1.name_fr, new_provider1.name_fr) new_provider2 = Provider.objects.get(id=provider2.id) self.assertEqual(provider2.number_of_monthly_beneficiaries, new_provider2.number_of_monthly_beneficiaries)
def test_staff_change_providers(self): # Staff can change multiple providers self.user.is_staff = True self.user.save() provider1 = ProviderFactory() provider2 = ProviderFactory() name_fields = generate_translated_fields('name', False) # Tweak some data for field in name_fields: setattr(provider1, field, random_string(10)) provider2.number_of_monthly_beneficiaries = 1024 provider2.type = ProviderTypeFactory() book = get_export_workbook([provider1, provider2]) rsp = self.import_book(book) self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8')) new_provider1 = Provider.objects.get(id=provider1.id) for field in name_fields: self.assertEqual(getattr(provider1, field), getattr(new_provider1, field)) new_provider2 = Provider.objects.get(id=provider2.id) self.assertEqual(provider2.number_of_monthly_beneficiaries, new_provider2.number_of_monthly_beneficiaries)