def setUp(self):
     request = Mock()
     request.method = "POST"
     request.POST = {"livetranslation-popup-0-msgid": "the-msgid", "livetranslation-popup-0-en": "the-msgstr"}
     with patch("livetranslation.views.save_translations") as save:
         self.response = get_translations(request)
     self.save_translations = save
Example #2
0
 def test_trap_duplicate_skipped_on_standalone(self, trap_duplicate_mock):
     self.create_switch("webapps-unique-by-domain")
     request = Mock()
     request.method = "POST"
     request.POST = {"manifest": ""}
     request.return_value = collections.namedtuple("FakeResponse", "status_code content")
     standalone_hosted_upload(request)
     assert not trap_duplicate_mock.called
    def test_payment_already_paid(self):
        payment = mommy.make(getpaid.models.Payment, id=90, amount=119000, paid_on=now())

        request = Mock()
        request.POST = {"TBK_MONTO": "11900000"}
        request.body = self.QUOTED_REQUEST_BODY

        self.assertFalse(PaymentProcessor.validate(payment, request))
Example #4
0
    def test_developer_add_GET(self):
        request = Mock()
        request.POST = None
        response = developer_add(request)

        self.assertEqual(200, response.status_code)
        pattern = '<form action="%s" method="post">' % reverse(developer_add)
        self.assertIsNotNone(re.search(pattern, response.content))
    def test_from_django_request(self):
        from dce_lti_py.contrib.django import DjangoToolProvider

        secret = generate_token()
        mock_req = Mock()
        mock_req.POST = {"oauth_consumer_key": "foo"}
        mock_req.META = {"CONTENT_TYPE": "bar"}
        mock_req.build_absolute_uri.return_value = "http://example.edu/foo/bar"
        tp = DjangoToolProvider.from_django_request(secret, mock_req)
        self.assertEqual(tp.consumer_key, "foo")
        self.assertEqual(tp.launch_headers["CONTENT_TYPE"], "bar")
        self.assertEqual(tp.launch_url, "http://example.edu/foo/bar")
Example #6
0
    def computed_signature(self):
        """
        Compute the signature on the fly
        """
        from mock import Mock
        from systempay.facade import Facade
        from django.http import QueryDict

        request = Mock()
        request.POST = QueryDict(self.raw_request)
        facade = Facade()
        form = facade.get_return_form_populated_with_request(request)
        return facade.gateway.compute_signature(form)
 def test_post_authenticated(self, verify_mock, get_audience_mock):
     user = UserFactory.create()
     Verify = BrowserIDVerify()
     request_mock = Mock()
     request_mock.user.is_authenticated.return_value = True
     request_mock.user = user
     request_mock.POST = {"assertion": "assertion"}
     Verify.request = request_mock
     get_audience_mock.return_value = "audience"
     verify_mock.return_value = Mock(email="foo@example.com")
     Verify.post()
     verify_mock.assert_called_with("assertion", "audience")
     get_audience_mock.assert_called_with(request_mock)
     eq_(user.email, "foo@example.com")
Example #8
0
    def test_developer_password_GET(self, get_by_login):
        request = Mock()
        request.POST = None

        developer_instance = Mock()
        developer_instance.login = "realsugar"
        get_by_login.return_value = developer_instance

        response = developer_password(request, "realsugar")
        self.assertEqual(200, response.status_code)
        pattern = '<form action="%s" method="post">' % reverse(developer_password, args=["realsugar"])
        self.assertIsNotNone(re.search(pattern, response.content))

        get_by_login.assert_called_once_with("realsugar")
Example #9
0
 def test_post_valid_email_exists(self, verify_mock, get_audience_mock, login_failure_mock):
     UserFactory.create(email="foo@example.com")
     user = UserFactory.create(email="la@example.com")
     Verify = BrowserIDVerify()
     request_mock = Mock()
     request_mock.user.is_authenticated.return_value = True
     request_mock.user = user
     request_mock.POST = {"assertion": "assertion"}
     Verify.request = request_mock
     verify_mock.return_value = Mock(email="foo@example.com")
     get_audience_mock.return_value = "audience"
     Verify.post()
     verify_mock.assert_called_with("assertion", "audience")
     get_audience_mock.assert_called_with(request_mock)
     login_failure_mock.assert_called_with()
     ok_(Verify.add_email)
Example #10
0
    def test_enable_device(self):
        response = iptables_download({})
        response_dict = json.loads(response._get_content()[5:])

        expected_blocked = [
            {u"ip_address": u"192.168.10.4", u"mac_address": u"58:94:6B:A4:D7:BC"},
            {u"ip_address": u"192.168.11.125", u"mac_address": u"8C:58:77:02:8E:5D"},
        ]
        self.assertEqual(expected_blocked, response_dict["blocked"])

        request = Mock()
        request.POST = {"mac_address": "58:94:6b:a4:da:bc", "duration": 30}
        request.method = "POST"
        response = enable_device(request)
        response_dict = json.loads(response._get_content()[5:])
        self.assertEqual(response_dict["success"], True)
        self.assertEqual(response_dict["message"], "Saved")
Example #11
0
 def test_post_authenticated(self, verify_mock, get_audience_mock):
     user = UserFactory.create()
     Verify = BrowserIDVerify()
     request_mock = Mock()
     request_mock.user.is_authenticated.return_value = True
     request_mock.user = user
     request_mock.POST = {"assertion": "assertion"}
     Verify.request = request_mock
     get_audience_mock.return_value = "audience"
     verify_mock.return_value = Mock(email="foo@example.com")
     Verify.post()
     verify_mock.assert_called_with("assertion", "audience")
     get_audience_mock.assert_called_with(request_mock)
     emails = ExternalAccount.objects.filter(
         type=ExternalAccount.TYPE_EMAIL, identifier="foo@example.com", user=user.userprofile
     )
     ok_(emails.exists())
Example #12
0
File: utils.py Project: somnam/xo
    def test_StoneUpdate_DeleteNotExistingStone_Passes(self):

        # Mock request
        request = Mock()
        request.user = User.objects.get(pk=1)
        request.POST = {"row": 0, "col": 2, "action": "del"}

        # Get game board
        game_id = 1
        board = Board.objects.get(pk=game_id)

        # Store count of placed stones
        latest_stones_count = board.get_placed_stones().count()

        # Remove stone from board
        go.utils.stone_update(request, game_id)

        # Compare stones count
        self.assertEqual(board.get_placed_stones().count(), latest_stones_count)
Example #13
0
File: utils.py Project: somnam/xo
    def test_StoneUpdate_AddValidStone_AddsStone(self):

        # Mock request
        request = Mock()
        request.user = User.objects.get(pk=1)
        request.POST = {"row": 0, "col": 2}

        # Get game board
        game_id = 1
        board = Board.objects.get(pk=game_id)

        # Store count of placed stones
        latest_stones_count = board.get_placed_stones().count()

        # Add new stone to board
        go.utils.stone_update(request, game_id)

        # Compare stones count
        self.assertEqual(board.get_placed_stones().count(), (latest_stones_count + 1))
Example #14
0
    def test_configure_extension_saving(self):
        """Testing configure_extension with saving settings"""

        class TestSettingsForm(SettingsForm):
            mykey = forms.CharField(max_length=100)

        self.extension.is_configurable = True
        self.spy_on(self.manager.get_enabled_extension, call_fake=lambda *args: self.extension)

        request = Mock()
        request.path = "/config"
        request.method = "POST"
        request.META = {"CSRF_COOKIE": "abc123"}
        request.POST = {"mykey": "myvalue"}
        request.FILES = {}

        configure_extension(request, TestExtensionWithRegistration, TestSettingsForm, self.manager)

        self.assertEqual(self.extension.settings.get("mykey"), "myvalue")
    def create_mock_request(self):
        request = Mock()
        request.POST = QueryDict(
            "vads_validation_mode=0&vads_cust_cell_phone=&vads_threeds_error_code=&\
vads_auth_number=171970&vads_site_id=99878789&vads_cust_id=&vads_ctx_mode=TEST&vads_language=fr&\
vads_payment_config=SINGLE&vads_ship_to_name=&vads_threeds_cavv=Q2F2dkNhdnZDYXZ2Q2F2dkNhdnY%3D&vads_extra_result=&\
vads_version=V2&vads_cust_country=&vads_cust_city=&vads_auth_mode=FULL&vads_trans_id=550758&vads_contrib=&\
vads_threeds_xid=dkNBQURpbHluUHMzbHdqSnRsSnc%3D&vads_card_country=FR&vads_cust_phone=&vads_order_info=&\
vads_cust_address=&vads_ship_to_phone_num=&vads_currency=978&vads_page_action=PAYMENT&vads_cust_name=&\
vads_sequence_number=1&vads_order_info2=&vads_order_info3=&\
vads_payment_certificate=f59522596f05f1b18e878f586ea31b4809832969&vads_threeds_enrolled=Y&\
vads_trans_date=20121122151746&vads_url_check_src=PAY&vads_warranty_result=YES&vads_auth_result=00&\
vads_payment_src=EC&vads_threeds_exit_status=10&vads_cust_zip=&vads_card_brand=CB&vads_pays_ip=FR&\
vads_capture_delay=0&vads_ship_to_street=&vads_ship_to_state=&vads_cust_email=&vads_contract_used=5830136&\
vads_action_mode=INTERACTIVE&vads_ship_to_street2=&vads_user_info=&vads_threeds_status=Y&vads_amount=1904&\
vads_order_id=100368&vads_ship_to_zip=&vads_ship_to_country=&vads_threeds_eci=05&vads_cust_state=&\
vads_threeds_sign_valid=1&vads_expiry_year=2013&vads_effective_amount=1904&vads_expiry_month=6&\
vads_threeds_cavvAlgorithm=2&vads_result=00&vads_operation_type=DEBIT&vads_cust_title=&\
signature=33f7eb8ca557cf862c72261da4e602f9c903afc2&vads_trans_status=AUTHORISED&\
vads_theme_config=&vads_ship_to_city=&vads_hash=rcI8uquHGoTJ69krXVkmBDSydSIoFJs2ZE8S26Xt4DQ-&\
vads_card_number=497010XXXXXX0000"
        )
        return request