def create(self, validated_data): address_data = validated_data.pop('address') user = User.objects.create(**validated_data) country = Country.objects.get(code=address_data['country']) user.address = Address.objects.create(country=country) user.set_password(validated_data['password']) user.save() Token.objects.create(user=user) # first_name, last_name = validated_data['name'].split(' ') birth_date = int( time.mktime( time.strptime(str(validated_data['birth_date']), '%Y-%m-%d'))) mangopay_user = NaturalUser(first_name=validated_data['name'], last_name=validated_data['surname'], birthday=birth_date, nationality=country.code, country_of_residence=country.code, person_type='NATURAL', email=validated_data['email']) mangopay_user.save() user.mangopay_user_id = mangopay_user.id user.save() wallet = Wallet(owners=[mangopay_user], description='Wallet for USD', currency='USD') wallet.save() currency = Currency.objects.get(code='USD') UserWallet.objects.create(user=user, currency=currency, mangopay_wallet_id=wallet.id) return user
def make_mangopay_account(FirstName): account = NaturalUser() account.FirstName = FirstName account.LastName = 'Foobar' account.CountryOfResidence = 'BE' account.Nationality = 'BE' account.Birthday = 0 account.Email = '*****@*****.**' account.save() return account.Id
def test_create_ubo_declaration(self): self.mock_legal_user() self.mock_declarative_user() self.mock_ubo_declaration() 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", "capacity": "DECLARATIVE" } user = NaturalUser(**params) user.save() params = {"user_id": "1169420", "declared_ubos": ["11694190"]} ubo_declaration = UboDeclaration(**params) ubo_declaration.save() self.assertTrue(isinstance(ubo_declaration, UboDeclaration)) self.assertTrue(ubo_declaration.id == "1169420") self.assertTrue(len(ubo_declaration.declared_ubos) == 1) ubo = ubo_declaration.declared_ubos[0] self.assertTrue(isinstance(ubo, DeclaredUbo)) self.assertTrue(ubo.user_id == '11694190') self.assertTrue(ubo.status == 'CREATED')
def create(self): if not self.birthday or self.birthday == 0: db = 1 else: db = _make_timestamp(self.birthday) mango_call = NaturalUser(FirstName=self.user.first_name, LastName=self.user.last_name, Email=self.user.email, Birthday=db, Nationality=self.nationality, CountryOfResidence=self.country_of_residence) mango_call.save() self.mid = mango_call.Id # Add more data from the return of the call self.save()
def make_mangopay_account(FirstName): account = NaturalUser() account.FirstName = FirstName account.LastName = 'Foobar' account.CountryOfResidence = 'BE' account.Nationality = 'BE' account.Birthday = 0 account.Email = '*****@*****.**' account.save() return account.Id
def create( self ): # check if not to pass in the user from the request in the view self.birthday = _date_from_timestamp(1) mango_call = NaturalUser(FirstName=self.user.first_name, LastName=self.user.last_name, Email=self.user.email, Birthday=1, Nationality=self.nationality, CountryOfResidence=self.country_of_residence) mango_call.save() self.usertype = 'NATURAL' self.mid = mango_call.get_pk() print(self.birthday) print(type(self.birthday)) self.save()
def update(self, instance, validated_data): mangopay_user = NaturalUser.get(instance.mangopay_user_id) print(">>>>>", mangopay_user.id) address_data = validated_data.pop('address') address = instance.address address.line1 = address_data.get('line1', address.line1) mangopay_user.address.address_line_1 = address_data.get( 'line1', address.line1) address.line2 = address_data.get('line2', address.line2) mangopay_user.address.address_line_2 = address_data.get( 'line2', address.line2) address.city = address_data.get('city', address.city) mangopay_user.address.city = address_data.get('city', address.city) address.state = address_data.get('state', address.state) mangopay_user.address.region = address_data.get('state', address.state) address.country = Country.objects.get( code=address_data.get('country', address.country)) mangopay_user.address.country = address_data.get( 'country', address.country) address.pin_code = address_data.get('pin_code', address.pin_code) mangopay_user.address.postal_code = address_data.get( 'pin_code', address.pin_code) address.save() mangopay_user.save() return instance
def post(self, request, format=None): try: currency = Currency.objects.get(code=request.data['currency']) receiver_user = User.objects.get(phone_no=request.data['mobile_number']) sender_wallet_obj = UserWallet.objects.get(user=request.user, currency=currency, status='A') sender_wallet = Wallet.get(sender_wallet_obj.mangopay_wallet_id) receiver_wallet_obj = UserWallet.objects.get(user=receiver_user, currency=currency, status='A') receiver_wallet = Wallet.get(receiver_wallet_obj.mangopay_wallet_id) author_user = NaturalUser.get(request.user.mangopay_user_id) transfer = Transfer(author=author_user, #sender debited_funds=Money(amount=request.data['amount'], currency=currency.code), fees=Money(amount=currency.fee, currency=currency.code), debited_wallet=sender_wallet, credited_wallet=receiver_wallet) transfer.save() logger.info("Money transfered successfully from {} user to {} user."\ .format(request.user.phone_no, receiver_user.phone_no)) return Response({ 'success': True, 'message': 'Money transfered successfully.', 'data':{ 'transaction_id':transfer.get_pk() } }) except Exception as e: logger.exception("{}, error occured while transfering money.".format(e)) return Response({ 'success': False, 'message': 'Error occured while transfering money.', 'data':{} })
def test_update_ubo_declaration(self): self.mock_legal_user() self.mock_declarative_user() self.mock_ubo_declaration() 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", "capacity": "DECLARATIVE" } user = NaturalUser(**params) user.save() params = { "user_id": "1169420", "declared_ubos": ["11694190"] } ubo_declaration = UboDeclaration(**params) ubo_declaration.save() updated_value = 'Updated Tag' self.register_mock({ "method": responses.PUT, "url": settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/ubodeclarations/1169420', "body": get_fixture('ubo_declaration') % ('"' + updated_value + '"'), "status": 200 }) ubo_declaration.tag = updated_value ubo_declaration.save() self.assertTrue(ubo_declaration.id == "1169420") self.assertTrue(ubo_declaration.tag == updated_value)
def _validated(self): mpu = NaturalUser.get(id=self.mid) # mpu need to do stuff here!!! # sdlkfjas ldkf ;slakdjfsd jfasd fs asd #lkashd fshdf kajs hdklasfh # klajsdf laksd flasdh flak sd return self.validation_status
def post(self, request, format=None): try: cash_request = CashRequest.objects.get(user_confirmation_code=request.data['confirmation_code']) teller = Teller.objects.get(user=request.user) if cash_request.teller == teller: teller_wallet_obj = UserWallet.objects.get(user=request.user, currency=cash_request.currency, status='A') teller_wallet = Wallet.get(teller_wallet_obj.mangopay_wallet_id) user_wallet_obj = UserWallet.objects.get(user=cash_request.user, currency=cash_request.currency, status='A') user_wallet = Wallet.get(user_wallet_obj.mangopay_wallet_id) if cash_request.request_type == 'A': transaction_amount = cash_request.amount - teller.fee author_user = NaturalUser.get(request.user.mangopay_user_id) transfer = Transfer(author=author_user, #sender debited_funds=Money(amount=transaction_amount, currency=cash_request.currency.code), fees=Money(amount=cash_request.currency.fee, currency=cash_request.currency.code), debited_wallet=teller_wallet, credited_wallet=user_wallet) else: transaction_amount = cash_request.amount + teller.fee + cash_request.currency.fee author_user = NaturalUser.get(cash_request.user.mangopay_user_id) transfer = Transfer(author=author_user, #sender debited_funds=Money(amount=transaction_amount, currency=cash_request.currency.code), fees=Money(amount=cash_request.currency.fee, currency=cash_request.currency.code), debited_wallet=user_wallet, credited_wallet=teller_wallet) transfer.save() cash_request.transaction_reference_number = transfer.get_pk() cash_request.save() logger.info("Cash_transaction completed successfully between {} user and {} teller for {} cashrequest."\ .format(request.user.phone_no, teller.user.phone_no, cash_request.id)) return Response({ 'success': True, 'message': 'Cash transaction successfully completed.', 'data':{ 'transaction_id':transfer.get_pk() } }) except Exception as e: logger.exception("{}, error occured while cash transaction.".format(e)) return Response({ 'success': False, 'message': 'Error occured while cash transaction.', 'data':{} })
def post(self, request, format=None): try: try: currency = Currency.objects.get(code=request.data['currency']) card_detail = UserCardDetails.objects.get(user=request.user, currency=currency, is_completed=True) except UserCardDetails.DoesNotExist: return Response({ 'success': True, 'message': 'Please complete card registration first for selected currency.', 'data': {} }) card_registration = CardRegistration.get( card_detail.mangopay_card_registration_id) user_wallet = UserWallet.objects.get(user=request.user, currency=currency, status='A') wallet = Wallet.get(user_wallet.mangopay_wallet_id) mangopay_user = NaturalUser.get(request.user.mangopay_user_id) direct_payin = DirectPayIn( author=mangopay_user, debited_funds=Money(amount=request.data['amount'], currency=currency.code), fees=Money(amount=currency.fee, currency=currency.code), credited_wallet_id=wallet.get_pk(), card_id=card_registration.CardId, secure_mode="DEFAULT", secure_mode_return_url="/") #take url from client direct_payin.save() logger.info("{} {} credited by {} user.".format( request.data['amount'], currency.code, request.user.phone_no)) return Response({ 'success': True, 'message': 'Money successfully credited.', 'data': { 'transaction_id': direct_payin.get_pk() } }) except Exception as e: logger.error( "{}, error occured while adding money by card.".format(e)) return Response({ 'success': False, 'message': 'Error occured while adding money by card.', 'data': {} })
def get_user(self): return NaturalUser( id=self.mangopay_id, first_name=self._first_name, last_name=self._last_name, address=Address( address_line_1=self.address), # TODO: add other address fields birthday=self._birthday_fmt(), nationality=self.nationality.code, country_of_residence=self.country_of_residence.code, occupation=self.occupation, income_range=self.income_range, proof_of_identity=None, proof_of_address=None, email=self.email, )
def post(self, request, format=None): try: try: card_detail = UserCardDetails.objects.get( user=request.user, currency__code=request.data['currency']) if card_detail.is_completed: return Response({ 'success': False, 'message': 'Card already registrated for given currency.', 'data': {} }) else: card_registration = CardRegistration.get( card_detail.mangopay_card_registration_id) except UserCardDetails.DoesNotExist: mangopay_user = NaturalUser.get(request.user.mangopay_user_id) currency = Currency.objects.get(code=request.data['currency']) card_registration = CardRegistration(user=mangopay_user, currency=currency.code) card_registration.save() UserCardDetails.objects.create(user=request.user, currency=currency, \ mangopay_card_registration_id=card_registration.id) logger.info("Card successfully pre-registered for {} currency by {} user.".format(request.data['currency'],\ request.user.phone_no)) return Response({ 'success': True, 'message': 'Pre card registration successful.', 'data': { "AccessKey": card_registration.AccessKey, "PreregistrationData": card_registration.PreregistrationData, "CardRegistrationURL": card_registration.CardRegistrationURL } }) except Exception as e: logger.exception( "{}, error occured while pre card registration.".format(e)) return Response({ 'success': False, 'message': 'Error occured while pre card registration.', 'data': {} })
def update(self, instance, validated_data): mangopay_user = NaturalUser.get(instance.mangopay_user_id) print(">>>>>", mangopay_user.id) instance.email = validated_data.get('email', instance.email) instance.name = validated_data.get('name', instance.name) instance.birth_date = validated_data.get('birth_date', instance.birth_date) # instance.photo = validated_data.get('photo', instance.photo) instance.save() mangopay_user.email = instance.email mangopay_user.birthday = int( time.mktime(time.strptime(str(instance.birth_date), '%Y-%m-%d'))) mangopay_user.first_name, mangopay_user.last_name = instance.name.split( ' ') print(instance.email, type(instance.email), int(time.mktime(time.strptime(str(instance.birth_date),'%Y-%m-%d'))),\ type(int(time.mktime(time.strptime(str(instance.birth_date),'%Y-%m-%d'))))) address_data = validated_data.pop('address') address = instance.address address.line1 = address_data.get('line1', address.line1) mangopay_user.address.address_line_1 = address_data.get( 'line1', address.line1) address.line2 = address_data.get('line2', address.line2) mangopay_user.address.address_line_2 = address_data.get( 'line2', address.line2) address.city = address_data.get('city', address.city) mangopay_user.address.city = address_data.get('city', address.city) address.state = address_data.get('state', address.state) mangopay_user.address.region = address_data.get('state', address.state) address.country = Country.objects.get( code=address_data.get('country', address.country)) mangopay_user.address.country = address_data.get( 'country', address.country) address.pin_code = address_data.get('pin_code', address.pin_code) mangopay_user.address.postal_code = address_data.get( 'pin_code', address.pin_code) address.save() mangopay_user.save() return instance
def post(self, request, format=None): try: try: currency = Currency.objects.get(code=request.data['currency']) UserWallet.objects.get(user=request.user, currency=currency, status='A') return Response({ 'success': False, 'message': 'Wallet Exist.', 'data': {} }) except UserWallet.DoesNotExist: mangopay_user = NaturalUser.get(request.user.mangopay_user_id) wallet = Wallet(owners=[mangopay_user], description="Bankey wallet", currency=currency.code) wallet.save() UserWallet.objects.create(user=request.user, currency=currency, mangopay_wallet_id=wallet.id) logger.info( "{} wallet created successfully for {} currency.".format( request.user.phone_no, currency.code)) return Response({ 'success': True, 'message': 'Successfully wallet created', 'data': {} }) except Exception as e: logger.error("{}, error occured while creating wallet.".format(e)) return Response({ 'success': False, 'message': 'Error occured while creating wallet.', 'data': {} })
handler = APIRequest(sandbox=True) client = Client('https://info802-ep-soap-server.azurewebsites.net/?wsdl') from flask import Flask app = Flask(__name__) natural_user = NaturalUser(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=1300186358, 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') @app.route("/") def hello(): result = client.service.say_hello('ok', 2) natural_user.save()
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)
def test_create_natural_user(self): self.mock_natural_user() self.register_mock({ "method": responses.PUT, "url": re.compile( r'' + settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/natural/\d+'), "body": { "FirstName": "Victor", "LastName": "Claver", "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": "1169419", "Tag": "custom tag", "CreationDate": 1383321421, "KYCLevel": "LIGHT" }, "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) self.assertIsNone(user.get_pk()) user.save() self.assertIsInstance(user, NaturalUser) for key, value in params.items(): self.assertEqual(getattr(user, key), value) self.assertIsNotNone(user.get_pk()) previous_pk = user.get_pk() user.last_name = 'Claver' user.save() self.assertEqual(previous_pk, user.get_pk()) self.assertEqual(user.last_name, 'Claver')
import mangopay from mangopay.resources import User, NaturalUser from mangopay.utils import Address mangopay.client_id = 'info802-ep' mangopay.apikey = 'MZ3zAhEH5nbYg8RPH6ekOZQdsAYqQJTvghh8fJkamzJtZnvEXu' from mangopay.api import APIRequest handler = APIRequest(sandbox=True) natural_user = NaturalUser( first_name='Victor', last_name='Hugo', birthday=1300186358, nationality='FR', country_of_residence='FR', email='*****@*****.**', ) natural_user.save() # save the new user print(natural_user.get_pk()) # retrieve the primary key
def get_docs_list(self): mpu = NaturalUser.get(self.mid) docs = mpu.documents.all() for d in docs: print(d) return docs
def test_create_natural_user(self): self.mock_natural_user() self.register_mock({ "method": responses.PUT, "url": re.compile( r'' + settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/natural/\d+'), "body": { "FirstName": "Victor", "LastName": "Claver", "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": "1169419", "Tag": "custom tag", "CreationDate": 1383321421, "KYCLevel": "LIGHT" }, "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) self.assertIsNone(user.get_pk()) user.save() self.assertIsInstance(user, NaturalUser) for key, value in params.items(): self.assertEqual(getattr(user, key), value) self.assertIsNotNone(user.get_pk()) previous_pk = user.get_pk() user.last_name = 'Claver' user.save() self.assertEqual(previous_pk, user.get_pk()) self.assertEqual(user.last_name, 'Claver')
def test_retrieve_natural_user(self): self.mock_natural_user() self.register_mock([ { 'method': responses.GET, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/natural/1169419', '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, "ProofOfIdentity": None, "ProofOfAddress": None, "PersonType": "NATURAL", "Email": "*****@*****.**", "Id": "1169419", "Tag": "custom tag", "CreationDate": 1383321421, "KYCLevel": "LIGHT" }, 'status': 200 }, { 'method': responses.GET, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/natural/1169420', 'body': {"errors": []}, 'status': 404 }]) 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.assertRaises(NaturalUser.DoesNotExist, NaturalUser.get, int(user.get_pk()) + 1) self.assertIsNotNone(user.get_pk()) user = NaturalUser.get(user.get_pk()) self.assertIsNotNone(user.get_pk()) for key, value in params.items(): self.assertEqual(getattr(user, key), value)
def test_retrieve_natural_user(self): self.mock_natural_user() self.register_mock([ { 'method': responses.GET, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/natural/1169419', '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, "ProofOfIdentity": None, "ProofOfAddress": None, "PersonType": "NATURAL", "Email": "*****@*****.**", "Id": "1169419", "Tag": "custom tag", "CreationDate": 1383321421, "KYCLevel": "LIGHT" }, 'status': 200 }, { 'method': responses.GET, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/natural/1169420', 'body': {"errors": []}, 'status': 404 }]) 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.assertRaises(NaturalUser.DoesNotExist, NaturalUser.get, int(user.get_pk()) + 1) self.assertIsNotNone(user.get_pk()) user = NaturalUser.get(user.get_pk()) self.assertIsNotNone(user.get_pk()) for key, value in params.items(): self.assertEqual(getattr(user, key), value)
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)