예제 #1
0
 def test_Credentials_check_activated_already_loaded(self):
     """Test Credentials.check_activated() already loaded."""
     c = Credentials.get_current()
     c.activation = Activation("some_email", True)
     with patch("streamlit.credentials._exit") as p:
         c._check_activated(auto_resolve=False)
         p.assert_not_called()
예제 #2
0
 def test_Credentials_check_activated_false(self):
     """Test Credentials.check_activated() not activated."""
     c = Credentials.get_current()
     c.activation = Activation("some_email", False)
     with patch("streamlit.credentials._exit") as p:
         c._check_activated(auto_resolve=False)
         p.assert_called_once_with("Activation email not valid.")
예제 #3
0
 def test_Credentials_check_activated_false(self):
     """Test Credentials.check_activated() not activated."""
     c = Credentials.get_current()
     c.activation = Activation('some_email', 'some_code', False)
     with patch('streamlit.credentials._exit') as p:
         c.check_activated()
         p.assert_called_once_with('Activation code/email not valid.')
예제 #4
0
 def test_Credentials_check_activated_already_loaded(self):
     """Test Credentials.check_activated() already loaded."""
     c = Credentials.get_current()
     c.activation = Activation('some_email', 'some_code', True)
     with patch('streamlit.credentials._exit') as p:
         c.check_activated()
         p.assert_not_called()
예제 #5
0
    def test_Credentials_save(self):
        """Test Credentials.save()."""
        c = Credentials.get_current()
        c.activation = Activation("some_email", True)
        truth = textwrap.dedent(
            """
            [general]
            email = "some_email"
        """
        ).lstrip()

        truth2 = textwrap.dedent(
            """
            [general]
            email = "some_email"
        """
        ).lstrip()

        m = mock_open()
        with patch("streamlit.credentials.open", m, create=True) as m:
            c.save()
            if sys.version_info >= (3, 0):
                m.return_value.write.assert_called_once_with(truth)
            else:
                m.return_value.write.assert_called_once_with(truth2)
예제 #6
0
 def test_Credentials_check_activated_error(self):
     """Test Credentials.check_activated() has an error."""
     c = Credentials.get_current()
     c.activation = Activation("some_email", True)
     with patch.object(c, "load", side_effect=Exception(
             "Some error")), patch("streamlit.credentials._exit") as p:
         c._check_activated(auto_resolve=False)
         p.assert_called_once_with("Some error")
예제 #7
0
 def test_Credentials_load_twice(self):
     """Test Credentials.load() called twice."""
     c = Credentials.get_current()
     c.activation = Activation("some_email", True)
     with patch("streamlit.credentials.LOGGER") as p:
         c.load()
         p.error.assert_called_once_with(
             "Credentials already loaded. Not rereading file.")
예제 #8
0
 def test_Credentials_check_activated_error(self):
     """Test Credentials.check_activated() has an error."""
     c = Credentials.get_current()
     c.activation = Activation('some_email', 'some_code', True)
     with patch.object(c, 'load', side_effect=Exception(
             'Some error')), patch('streamlit.credentials._exit') as p:
         c.check_activated()
         p.assert_called_once_with('Some error')
예제 #9
0
 def test_Credentials_activate_already_activated(self):
     """Test Credentials.activate() already activated."""
     c = Credentials.get_current()
     c.activation = Activation("some_email", True)
     with patch("streamlit.credentials.LOGGER") as p:
         with pytest.raises(SystemExit):
             c.activate()
         self.assertEqual(p.error.call_count, 2)
         self.assertEqual(p.error.call_args_list[1], call("Already activated"))
예제 #10
0
 def test_Credentials_activate_already_activated_not_valid(self):
     """Test Credentials.activate() already activated but not valid."""
     c = Credentials.get_current()
     c.activation = Activation("some_email", False)
     with patch("streamlit.credentials.LOGGER") as p:
         with pytest.raises(SystemExit):
             c.activate()
         self.assertEqual(p.error.call_count, 2)
         self.assertEqual(
             str(p.error.call_args_list[1])[0:27],
             "call('Activation not valid.")
예제 #11
0
    def test_Credentials_save(self):
        """Test Credentials.save()."""
        c = Credentials.get_current()
        c.activation = Activation("some_email", True)
        truth = textwrap.dedent("""
            [general]
            email = "some_email"
        """).lstrip()

        streamlit_root_path = os.path.join("/mock/home/folder",
                                           util.CONFIG_FOLDER_NAME)

        with patch("streamlit.credentials.open", mock_open(),
                   create=True) as open, patch(
                       "streamlit.credentials.os.makedirs") as make_dirs:

            c.save()

            make_dirs.assert_called_once_with(streamlit_root_path)
            open.return_value.write.assert_called_once_with(truth)