def test_retrieve_paginated_users(self):
        self.mock_user_list_full()
        self.mock_user_list_2_per_page_page1()
        self.mock_user_list_3_per_page_page2()
        self.mock_user_list_page1()
        self.mock_user_list_2_per_page()

        users_page = User.all()
        self.assertEqual(len(users_page), 10)
        for user in users_page:
            if isinstance(user, NaturalUser):
                self.assertIsNotNone(user.first_name)
            else:
                self.assertIsInstance(user, LegalUser)
                self.assertIsNotNone(user.name)

        users_page = User.all(page=1, per_page=2)
        self.assertEqual(len(users_page), 2)

        first_instance = users_page.data[0]

        users_page = User.all(page=2, per_page=3)
        self.assertEqual(len(users_page), 3)
        self.assertFalse(first_instance in users_page)

        # with self.assertRaises(APIError):
        #     users_page = User.all(random_key=1, another_random_key=2)

        users_page = User.all(page=1)
        self.assertEqual(len(users_page), 10)

        users_page = User.all(per_page=2)
        self.assertEqual(len(users_page), 2)
    def test_retrieve_paginated_users(self):
        self.mock_user_list_full()
        self.mock_user_list_2_per_page_page1()
        self.mock_user_list_3_per_page_page2()
        self.mock_user_list_page1()
        self.mock_user_list_2_per_page()

        users_page = User.all()
        self.assertEqual(len(users_page), 10)
        for user in users_page:
            if isinstance(user, NaturalUser):
                self.assertIsNotNone(user.first_name)
            else:
                self.assertIsInstance(user, LegalUser)
                self.assertIsNotNone(user.name)

        users_page = User.all(page=1, per_page=2)
        self.assertEqual(len(users_page), 2)

        first_instance = users_page.data[0]

        users_page = User.all(page=2, per_page=3)
        self.assertEqual(len(users_page), 3)
        self.assertFalse(first_instance in users_page)

        # with self.assertRaises(APIError):
        #     users_page = User.all(random_key=1, another_random_key=2)

        users_page = User.all(page=1)
        self.assertEqual(len(users_page), 10)

        users_page = User.all(per_page=2)
        self.assertEqual(len(users_page), 2)
Exemple #3
0
def sync_with_mangopay(db):
    """We can get out of sync with MangoPay if record_exchange_result wasn't
    completed. This is where we fix that.
    """
    check_db(db)

    exchanges = db.all("""
        SELECT *, (e.timestamp < current_timestamp - interval '1 day') AS is_old
          FROM exchanges e
         WHERE e.status = 'pre'
    """)
    for e in exchanges:
        p = Participant.from_id(e.participant)
        transactions = [
            x for x in User(id=p.mangopay_user_id).transactions.all(
                Sort='CreationDate:DESC',
                Type=('PAYIN' if e.amount > 0 else 'PAYOUT'))
            if x.Tag == str(e.id)
        ]
        assert len(transactions) < 2
        if transactions:
            t = transactions[0]
            error = repr_error(t)
            status = t.Status.lower()
            assert (not error) ^ (status == 'failed')
            record_exchange_result(db, e.id, t.Id, status, error, p)
        elif e.is_old:
            # The exchange didn't happen, mark it as failed
            record_exchange_result(db, e.id, '', 'failed', 'interrupted', p)

    transfers = db.all("""
        SELECT *, (t.timestamp < current_timestamp - interval '1 day') AS is_old
          FROM transfers t
         WHERE t.status = 'pre'
    """)
    for t in transfers:
        tipper = Participant.from_id(t.tipper)
        transactions = [
            x for x in User(id=tipper.mangopay_user_id).transactions.all(
                Sort='CreationDate:DESC', Type='TRANSFER')
            if x.Tag == str(t.id)
        ]
        assert len(transactions) < 2
        if transactions:
            record_transfer_result(db, t.id, transactions[0])
        elif t.is_old:
            # The transfer didn't happen, mark it as failed
            _record_transfer_result(db, t.id, 'failed', 'interrupted')

    check_db(db)
    def test_retrieve_all_users(self):
        self.register_mock({
            'method': responses.GET,
            'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users',
            'body': [
                {
                    "PersonType": "NATURAL",
                    "Email": "*****@*****.**",
                    "Id": "1167495",
                    "Tag": None,
                    "CreationDate": 1382605938,
                    "KYCLevel": "LIGHT",
                    "FirstName": "Victor"
                },
                {
                    "PersonType": "LEGAL",
                    "Email": None,
                    "Id": "1167502",
                    "Tag": None,
                    "CreationDate": 1382607639,
                    "KYCLevel": "LIGHT"
                },
                {
                    "PersonType": "NATURAL",
                    "Email": None,
                    "Id": "1167774",
                    "Tag": "",
                    "CreationDate": 1382627263,
                    "KYCLevel": "REGULAR"
                },
                {
                    "PersonType": "NATURAL",
                    "Email": None,
                    "Id": "1168856",
                    "Tag": None,
                    "CreationDate": 1383143870,
                    "KYCLevel": "LIGHT"
                }
            ],
            'status': 200
        })

        users = User.all()
        self.assertIsInstance(users, list)

        self.assertIsInstance(users[0], NaturalUser)
        self.assertEqual(users[0].email, '*****@*****.**')
        self.assertIsNotNone(users[0].first_name)
    def test_retrieve_all_users(self):
        self.register_mock({
            'method': responses.GET,
            'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users',
            'body': [
                {
                    "PersonType": "NATURAL",
                    "Email": "*****@*****.**",
                    "Id": "1167495",
                    "Tag": None,
                    "CreationDate": 1382605938,
                    "KYCLevel": "LIGHT",
                    "FirstName": "Victor"
                },
                {
                    "PersonType": "LEGAL",
                    "Email": None,
                    "Id": "1167502",
                    "Tag": None,
                    "CreationDate": 1382607639,
                    "KYCLevel": "LIGHT"
                },
                {
                    "PersonType": "NATURAL",
                    "Email": None,
                    "Id": "1167774",
                    "Tag": "",
                    "CreationDate": 1382627263,
                    "KYCLevel": "REGULAR"
                },
                {
                    "PersonType": "NATURAL",
                    "Email": None,
                    "Id": "1168856",
                    "Tag": None,
                    "CreationDate": 1383143870,
                    "KYCLevel": "LIGHT"
                }
            ],
            'status': 200
        })

        users = User.all()
        self.assertIsInstance(users.data, list)

        self.assertIsInstance(users[0], NaturalUser)
        self.assertEqual(users[0].email, '*****@*****.**')
        self.assertIsNotNone(users[0].first_name)
    def test_StandardUseToken(self):
        User.all()
        token = BaseTestLive.get_oauth_manager().get_token()
        User.all()

        self.assertEqual(token, BaseTestLive.get_oauth_manager().get_token())
    def test_retrieve_specific_legal_user(self):
        self.mock_legal_user()

        self.register_mock({
            'method':
            responses.GET,
            'url':
            re.compile(r'' + settings.MANGOPAY_API_SANDBOX_URL +
                       settings.MANGOPAY_CLIENT_ID + '/users/\d+'),
            'body': {
                "Name": "MangoPay",
                "LegalPersonType": "BUSINESS",
                "HeadquartersAddress": {
                    "AddressLine1": "AddressLine1",
                    "AddressLine2": "AddressLine2",
                    "City": "City",
                    "Region": "Region",
                    "PostalCode": "11222",
                    "Country": "FR"
                },
                "LegalRepresentativeFirstName": "Mango",
                "LegalRepresentativeLastName": "Pay",
                "LegalRepresentativeEmail": "*****@*****.**",
                "LegalRepresentativeBirthday": today_timestamp,
                "LegalRepresentativeNationality": "FR",
                "LegalRepresentativeCountryOfResidence": "FR",
                "ProofOfRegistration": None,
                "ShareholderDeclaration": None,
                "LegalRepresentativeAddress": None,
                "Statute": None,
                "PersonType": "LEGAL",
                "Email": "*****@*****.**",
                "Id": "1169420",
                "Tag": "custom tag",
                "CreationDate": 1383322502,
                "KYCLevel": "LIGHT",
                "UserCategory": "OWNER"
            },
            'status':
            200
        })

        params = {
            "name":
            "MangoPay",
            "legal_person_type":
            "BUSINESS",
            "headquarters_address":
            Address(address_line_1='AddressLine1',
                    address_line_2='AddressLine2',
                    city='City',
                    region='Region',
                    postal_code='11222',
                    country='FR'),
            "legal_representative_first_name":
            "Mango",
            "legal_representative_last_name":
            "Pay",
            "legal_representative_email":
            "*****@*****.**",
            "legal_representative_birthday":
            today,
            "legal_representative_nationality":
            "FR",
            "legal_representative_country_of_residence":
            "FR",
            "proof_of_registration":
            None,
            "shareholder_declaration":
            None,
            "legal_representative_address":
            None,
            "statute":
            None,
            "person_type":
            "LEGAL",
            "email":
            "*****@*****.**",
            "tag":
            "custom tag",
            "user_category":
            "OWNER"
            # "creation_date": datetime.now()
        }
        user = LegalUser(**params)

        self.assertIsNone(user.get_pk())
        user.save()
        self.assertIsInstance(user, LegalUser)

        for key, value in params.items():
            self.assertEqual(getattr(user, key), value)

        retrieved_user = User.get(user.id)

        for key, value in params.items():
            self.assertEqual(getattr(retrieved_user, key), value)

        self.assertIsInstance(retrieved_user, User)
    def test_retrieve_specific_natural_user(self):
        self.mock_natural_user()

        self.register_mock({
            'method':
            responses.GET,
            'url':
            re.compile(r'' + settings.MANGOPAY_API_SANDBOX_URL +
                       settings.MANGOPAY_CLIENT_ID + '/users/\d+'),
            'body': {
                "FirstName": "Victor",
                "LastName": "Hugo",
                "Address": {
                    "AddressLine1": "AddressLine1",
                    "AddressLine2": "AddressLine2",
                    "City": "City",
                    "Region": "Region",
                    "PostalCode": "11222",
                    "Country": "FR"
                },
                "Birthday": today_timestamp,
                "Nationality": "FR",
                "CountryOfResidence": "FR",
                "Occupation": "Writer",
                "IncomeRange": 6,
                "PersonType": "NATURAL",
                "Email": "*****@*****.**",
                "Id": "1167495",
                "CreationDate": 1382605938,
                "KYCLevel": "LIGHT",
                "Tag": "custom tag",
                "UserCategory": "OWNER"
            },
            'status':
            200
        })

        params = {
            "first_name":
            "Victor",
            "last_name":
            "Hugo",
            "address":
            Address(address_line_1='AddressLine1',
                    address_line_2='AddressLine2',
                    city='City',
                    region='Region',
                    postal_code='11222',
                    country='FR'),
            "birthday":
            today,
            "nationality":
            "FR",
            "country_of_residence":
            "FR",
            "occupation":
            "Writer",
            "income_range":
            6,
            "proof_of_identity":
            None,
            "proof_of_address":
            None,
            "person_type":
            "NATURAL",
            "email":
            "*****@*****.**",
            "tag":
            "custom tag",
            "user_category":
            "OWNER"
        }
        user = NaturalUser(**params)
        user.save()
        self.assertIsNotNone(user.get_pk())

        retrieved_user = User.get(user.get_pk())

        self.assertIsNotNone(retrieved_user.get_pk())

        for key, value in params.items():
            self.assertEqual(getattr(retrieved_user, key), value)

        self.assertIsInstance(retrieved_user, User)
Exemple #9
0
    def test_StandardUseToken(self):
        User.all()
        token = BaseTestLive.get_oauth_manager().get_token()
        User.all()

        self.assertEqual(token, BaseTestLive.get_oauth_manager().get_token())
    def test_retrieve_specific_legal_user(self):
        self.mock_legal_user()

        self.register_mock({
            'method': responses.GET,
            'url': re.compile(r'' + settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/\d+'),
            'body': {
                "Name": "MangoPay",
                "LegalPersonType": "BUSINESS",
                "HeadquartersAddress": {
                    "AddressLine1": "AddressLine1",
                    "AddressLine2": "AddressLine2",
                    "City": "City",
                    "Region": "Region",
                    "PostalCode": "11222",
                    "Country": "FR"
                },
                "LegalRepresentativeFirstName": "Mango",
                "LegalRepresentativeLastName": "Pay",
                "LegalRepresentativeEmail": "*****@*****.**",
                "LegalRepresentativeBirthday": today_timestamp,
                "LegalRepresentativeNationality": "FR",
                "LegalRepresentativeCountryOfResidence": "FR",
                "ProofOfRegistration": None,
                "ShareholderDeclaration": None,
                "LegalRepresentativeAddress": None,
                "Statute": None,
                "PersonType": "LEGAL",
                "Email": "*****@*****.**",
                "Id": "1169420",
                "Tag": "custom tag",
                "CreationDate": 1383322502,
                "KYCLevel": "LIGHT"
            },
            'status': 200
        })

        params = {
            "name": "MangoPay",
            "legal_person_type": "BUSINESS",
            "headquarters_address": Address(address_line_1='AddressLine1', address_line_2='AddressLine2',
                                            city='City', region='Region',
                                            postal_code='11222', country='FR'),
            "legal_representative_first_name": "Mango",
            "legal_representative_last_name": "Pay",
            "legal_representative_email": "*****@*****.**",
            "legal_representative_birthday": today,
            "legal_representative_nationality": "FR",
            "legal_representative_country_of_residence": "FR",
            "proof_of_registration": None,
            "shareholder_declaration": None,
            "legal_representative_address": None,
            "statute": None,
            "person_type": "LEGAL",
            "email": "*****@*****.**",
            "tag": "custom tag",
            # "creation_date": datetime.now()
        }
        user = LegalUser(**params)

        self.assertIsNone(user.get_pk())
        user.save()
        self.assertIsInstance(user, LegalUser)

        for key, value in params.items():
            self.assertEqual(getattr(user, key), value)

        retrieved_user = User.get(user.id)

        for key, value in params.items():
            self.assertEqual(getattr(retrieved_user, key), value)

        self.assertIsInstance(retrieved_user, User)
    def test_retrieve_specific_natural_user(self):
        self.mock_natural_user()

        self.register_mock({
            'method': responses.GET,
            'url': re.compile(r'' + settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/\d+'),
            'body': {
                "FirstName": "Victor",
                "LastName": "Hugo",
                "Address": {
                    "AddressLine1": "AddressLine1",
                    "AddressLine2": "AddressLine2",
                    "City": "City",
                    "Region": "Region",
                    "PostalCode": "11222",
                    "Country": "FR"
                },
                "Birthday": today_timestamp,
                "Nationality": "FR",
                "CountryOfResidence": "FR",
                "Occupation": "Writer",
                "IncomeRange": 6,
                "PersonType": "NATURAL",
                "Email": "*****@*****.**",
                "Id": "1167495",
                "CreationDate": 1382605938,
                "KYCLevel": "LIGHT",
                "Tag": "custom tag"
            },
            'status': 200
        })

        params = {
            "first_name": "Victor",
            "last_name": "Hugo",
            "address": Address(address_line_1='AddressLine1', address_line_2='AddressLine2',
                               city='City', region='Region',
                               postal_code='11222', country='FR'),
            "birthday": today,
            "nationality": "FR",
            "country_of_residence": "FR",
            "occupation": "Writer",
            "income_range": 6,
            "proof_of_identity": None,
            "proof_of_address": None,
            "person_type": "NATURAL",
            "email": "*****@*****.**",
            "tag": "custom tag",
        }
        user = NaturalUser(**params)
        user.save()
        self.assertIsNotNone(user.get_pk())

        retrieved_user = User.get(user.get_pk())

        self.assertIsNotNone(retrieved_user.get_pk())

        for key, value in params.items():
            self.assertEqual(getattr(retrieved_user, key), value)

        self.assertIsInstance(retrieved_user, User)
Exemple #12
0
 def get_wallets(self):
     user = User.get(self.mid)
     return [user.wallets]