Example #1
0
    def test_import_config_image_failure(self):
        # Arrange
        mock_response = MagicMock()

        mock_response.json.side_effect = ValueError
        
        # Act
        with patch('app.models.requests.get', return_value=mock_response):
            result = Mailbox.import_config_image('http://example.com')

        # Assert
        self.assertIn('Ooops!', result)
Example #2
0
    def test_import_config_image(self):
        # Arrange
        # Start off with an existing Mailbox
        mailbox = Mailbox('+15555555555', carrier='Foo Wireless', call_forwarding_set=True)
        db.session.add(mailbox)
        db.session.commit()

        mock_response = MagicMock()
        mock_response.json.return_value = [{'type': 'qrcode', 'symbol': [{'data': '{"id": 1, "feelings_on_qr_codes": "love", "phone_number": "+15555555555", "name": "Jane Foo", "email": "*****@*****.**", "call_forwarding_set": false, "carrier": "Foo Wireless"}', 'error': None, 'seq': 0}]}]

        # Act
        with patch('app.models.requests.get', return_value=mock_response):
            result = Mailbox.import_config_image('http://example.com')

        # Assert
        self.assertEqual(Mailbox.query.count(), 1)

        imported_mailbox = Mailbox.query.one()
        self.assertEqual(mailbox.phone_number, '+15555555555')
        self.assertFalse(mailbox.call_forwarding_set)

        self.assertIn('Now I remember *everything* about you', result)