def test_provider_change_password(self): # Providers can change their password provider = ProviderFactory(user=self.user) book = get_export_workbook([provider], cell_overwrite_ok=True) password_column = PROVIDER_HEADINGS.index('password') set_cell_value(book, 0, 1, password_column, 'new_password') rsp = self.import_book(book) self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8')) user = authenticate(email=provider.user.email, password='******') self.assertEqual(user, self.user)
def test_provider_change_anothers_password(self): # Providers cannot change another provider's password provider = ProviderFactory() book = get_export_workbook([provider], cell_overwrite_ok=True) password_column = PROVIDER_HEADINGS.index('password') set_cell_value(book, 0, 1, password_column, 'new_password') rsp = self.import_book(book) self.assertEqual(BAD_REQUEST, rsp.status_code, msg=rsp.content.decode('utf-8')) user = authenticate(email=provider.user.email, password='******') self.assertIsNone(user)
def test_staff_change_provider_password(self): # Staff can change anyone's password self.user.is_staff = True self.user.save() provider = ProviderFactory() book = get_export_workbook([provider], cell_overwrite_ok=True) password_column = PROVIDER_HEADINGS.index('password') set_cell_value(book, 0, 1, password_column, 'new_password') rsp = self.import_book(book) self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8')) user = authenticate(email=provider.user.email, password='******') self.assertEqual(user, provider.user)