def test_user_exists(self): # add test user to the database user = User(username=USER) user.save() res = auth.ISPyBBackend().get_user(user.id) self.assertEqual(user.id, res.id)
def test_invalid_creds(self): backend = auth.ISPyBBackend() auth_mock = Mock(return_value=None) with patch("fragview.auth.ispyb._ispyb_authenticate", auth_mock): user_obj = backend.authenticate(None, "usrn", "passd") self.assertIsNone(user_obj) auth_mock.assert_called_once_with(settings.ISPYB_AUTH_HOST, settings.ISPYB_AUTH_SITE, "usrn", "passd")
def setup_client(self, user_proposals: List[str] = []): """ setup test HTTP client which is logged in with a user 'dummy' that have access to PROP1 and PROP2 proposals """ self.user = auth.ISPyBBackend()._get_user_obj("dummy") self.client = test.Client() self.client.force_login(user=self.user) session = self.client.session session["proposals"] = user_proposals session.save()
def test_user_does_not_exists(self): NONEXIST_ID = -1 self.assertFalse(User.objects.filter(id=NONEXIST_ID)) res = auth.ISPyBBackend().get_user(NONEXIST_ID) self.assertIsNone(res)
def setUp(self): self.backend = auth.ISPyBBackend() self.auth_mock = Mock(return_value=TOKEN) self.request_mock = Mock() self.request_mock.session = dict()