コード例 #1
0
class Property(Base):
    formFieldPrefix = 'property_'
    fields = {
        'propertyKey': '',
        'partnerKey': '',
        'propName': '',
        'propInfo': PropInfo(),
        'address': Location(),
        'contactName': Name(),
        'contactInfo': Contact(),
        'rooms': [],
        'reviews': [],
        'rating': 0,
        'totalBooked': 0
    }

    def getKey(self):
        return self['propertyKey']

    def generatePropertyKey(self):
        import random
        # generate property key
        first4 = self['propName']
        first4 = first4.replace(' ', '')
        first4 = first4[0:4]
        first4 = first4.ljust(4, '_')
        self['propertyKey'] = first4.upper() + str(random.randint(1000, 9999))
        return self['propertyKey']
コード例 #2
0
ファイル: booking.py プロジェクト: gabrielmahia/somAI_MongoDB
class CustBooking(Base) :
    fields = {
        'customerKey'     : '',
        'customerName'    : Name(),
        'customerAddr'    : Location(),
        'customerContact' : Contact(),
        'custParty'       : []
    }
コード例 #3
0
 def setUp(self):
     self.testDict['name'] = Name(self.testName)
     self.testDict['address'] = Location(self.testLocation)
     self.testDict['contact'] = Contact(self.testContact)
     self.testDict['otherContact'] = OtherContact(self.testOtherContact)
     self.testDict['otherInfo'] = OtherInfo(self.testOtherInfo)
     self.testDict['login'] = LoginInfo(self.testLoginInfo)
     self.customerFromDict = Customer(self.testDict)
     self.customerDefaults = Customer()
     self.maxDiff = None
コード例 #4
0
class Customer(Base):
    fields = {
        'customerKey': '',
        'name': Name(),
        'address': Location(),
        'contact': Contact(),
        'otherContact': OtherContact(),
        'otherInfo': OtherInfo(),
        'login': LoginInfo()
    }

    def getKey(self):
        return self['customerKey']
コード例 #5
0
 def setUp(self):
     self.propertyDefaults = Property()
     self.testDict['propInfo'] = PropInfo(self.testPropInfo)
     self.testDict['address'] = Location(self.testLocation)
     self.testDict['contactName'] = Name(self.testName)
     self.testDict['contactInfo'] = Contact(self.testContact)
     self.testDict['rooms'] = [
         RoomType(self.testRoomType1),
         RoomType(self.testRoomType2)
     ]
     self.testDict['reviews'] = [Review(self.testReview)]
     self.propertyFromDict = Property(self.testDict)
     self.maxDiff = None
コード例 #6
0
 def setUp(self):
     custBooking = {
         'customerKey':
         '00000000',
         'customerName':
         Name(self.testCustName),
         'customerAddr':
         Location(self.testCustLocation),
         'customerContact':
         Contact(self.testCustContact),
         'custParty': [
             CustParty({
                 'name': Name(self.testCustPartyName1),
                 'other': OtherInfo(self.testOtherInfo1)
             }),
             CustParty({
                 'name': Name(self.testCustPartyName2),
                 'other': OtherInfo(self.testOtherInfo2)
             })
         ]
     }
     propBooking = {
         'propertyKey': 'ZZZZ9999',
         'propertyName': 'The Slate Resort',
         'propertyAddr': Location(self.testPropLocation),
         'propertyContact': Contact(self.testPropContact),
     }
     self.testDict = {
         'bookingKey': '20190501AAAA1111',
         'customer': custBooking,
         'property': propBooking,
         'bookingInfo': BookingInfo(self.testBookingInfo),
         'rooms': [RoomBooking(self.testRoomBooking)],
         'totalPrice': 999.99
     }
     self.bookingFromDict = Booking(self.testDict)
     self.bookingDefaults = Booking()
     self.maxDiff = None
コード例 #7
0
 def getPropertyFromForms(self):
     # get property form
     prop_form = self.forms['prop']
     # create data dictionary
     data = {
         'partnerKey': prop_form.cleaned_data.get('prop_partnerKey'),
         'propName': prop_form.cleaned_data.get('prop_propName'),
         'propInfo': PropInfo(self.getCleanDataByKey('info')),
         'address': Location(self.getCleanDataByKey('location')),
         'contactName': Name(self.getCleanDataByKey('name')),
         'contactInfo': Contact(self.getCleanDataByKey('contact')),
     }
     # create and return Property instance
     return Property(data)
コード例 #8
0
ファイル: user.py プロジェクト: gabrielmahia/somAI_MongoDB
class Partner(Base):
    fields = {
        'partnerKey': '',
        'businessName': '',
        'revenueSplit': 0.00,
        'acctBalance': 0.00,
        'name': Name(),
        'address': Location(),
        'contact': Contact(),
        'otherContact': OtherContact(),
        'otherInfo': OtherInfo(),
        'login': LoginInfo()
    }

    def getKey(self):
        return self['partnerKey']
コード例 #9
0
class Property(Base):
    fields = {
        'propertyKey': '',
        'partnerKey': '',
        'propName': '',
        'propInfo': PropInfo(),
        'address': Location(),
        'contactName': Name(),
        'contactInfo': Contact(),
        'rooms': [],
        'reviews': [],
        'rating': 0,
        'totalBooked': 0
    }

    def getKey(self):
        return self['propertyKey']
コード例 #10
0
 def assemble(self, doc):
     prop = Property(doc)
     if 'propInfo' in doc:
         prop['propInfo'] = PropInfo(doc['propInfo'])
     if 'address' in doc:
         prop['address'] = Location(doc['address'])
     if 'contactName' in doc:
         prop['contactName'] = Name(doc['contactName'])
     if 'contactInfo' in doc:
         prop['contactInfo'] = Contact(doc['contactInfo'])
     if 'rooms' in doc:
         prop['rooms'] = []
         for room in doc['rooms']:
             prop['rooms'].append(RoomType(room))
     if 'reviews' in doc:
         prop['reviews'] = []
         for review in doc['reviews']:
             prop['reviews'].append(Review(room))
     return prop
コード例 #11
0
class TestName(unittest.TestCase) :

    nameFromDict = None
    nameDefaults = None

    testDict = {
        'title'  : 'Mr',
        'first'  : 'Fred',
        'middle' : 'Folsom',
        'last'   : 'Flintstone',
        'suffix' : 'CM'
    }

    testJson = '''{
        "title"  : "Mr",
        "first"  : "Fred",
        "middle" : "Folsom",
        "last"   : "Flintstone",
        "suffix" : "CM"
    }'''

    def setUp(self) :
        self.nameFromDict = Name(self.testDict)
        self.nameDefaults = Name()

    def test_customer_from_dict(self) :
        expected = 'Flintstone'
        actual   = self.nameFromDict.get('last')
        self.assertEqual(expected, actual)

    def test_customer_from_dict_get_and_set(self) :
        self.nameFromDict.set('title', 'Caveman')
        expected = 'Caveman'
        actual   = self.nameFromDict.get('title')
        self.assertEqual(expected, actual)

    def test_customer_from_dict_to_json(self) :
        expected = json.loads(self.testJson)
        actual   = json.loads(self.nameFromDict.toJson())
        self.assertEqual(expected, actual)

    def test_customer_from_blank(self) :
        expected = ''
        actual   = self.nameDefaults.get('title')
        self.assertEqual(expected, actual)
コード例 #12
0
# sweetscomplete.entity.common.Common test

# tell python where to find module source code
import os, sys
sys.path.append(os.path.realpath("/repo/chapters/07/src"))

from booksomeplace.entity.base import Name

# Testing Name
params = {
    "title": 'Mr',
    "first": 'Fred',
    "middle": 'Folsom',
    "last": 'Flintstone',
    "suffix": 'CM'
}

# Create instance
name = Name(params)

# Output
import pprint
print("\nObject\n")
pprint.pprint(name)

print("\nJSON\n")
print(name.toJson())
コード例 #13
0
class TestCustomer(unittest.TestCase):

    customerFromDict = None
    customerDefaults = None

    testDict = {
        'customerKey': '00000000',
        'name': Name(),
        'address': Location(),
        'contact': Contact(),
        'otherContact': OtherContact(),
        'otherInfo': OtherInfo(),
        'login': LoginInfo(),
        'totalBooked': 100,
        'discount': 0.05
    }

    testLocation = {
        'streetAddress': '123 Main Street',
        'buildingName': '',
        'floor': '',
        'roomAptCondoFlat': '',
        'city': 'Bedrock',
        'stateProvince': 'ZZ',
        'locality': 'Unknown',
        'country': 'None',
        'postalCode': '00000',
        'latitude': '+111.111',
        'longitude': '-111.111'
    }

    testName = {
        'title': 'Mr',
        'first': 'Fred',
        'middle': 'Folsom',
        'last': 'Flintstone',
        'suffix': 'CM'
    }

    testContact = {
        'email': '*****@*****.**',
        'phone': '+0-000-000-0000',
        'socMedia': {
            'google': '*****@*****.**'
        }
    }

    testOtherContact = {
        'emails': ['*****@*****.**', '*****@*****.**'],
        'phoneNumbers': [{
            'home': '000-000-0000'
        }, {
            'work': '111-111-1111'
        }],
        'socMedias': [{
            'google': '*****@*****.**'
        }, {
            'skype': 'fflintstone'
        }]
    }

    testOtherInfo = {'gender': 'M', 'dateOfBirth': '0000-01-01'}

    testLoginInfo = {
        'username': '******',
        'oauth2': '*****@*****.**',
        'password': '******'
    }

    testJson = '''{
        "customerKey"  : "00000000",
        "address"     : {
            "streetAddress"    : "123 Main Street",
            "buildingName"     : "",
            "floor"            : "",
            "roomAptCondoFlat" : "",
            "city"             : "Bedrock",
            "stateProvince"    : "ZZ",
            "locality"         : "Unknown",
            "country"          : "None",
            "postalCode"       : "00000",
            "latitude"         : "+111.111",
            "longitude"        : "-111.111"
        },
        "name" : {
            "title"  : "Mr",
            "first"  : "Fred",
            "middle" : "Folsom",
            "last"   : "Flintstone",
            "suffix" : "CM"
        },
        "contact" : {
            "email"    : "*****@*****.**",
            "phone"    : "+0-000-000-0000",
            "socMedia" : {"google" : "*****@*****.**"}
        },
        "otherContact" : {
            "emails"       : ["*****@*****.**", "*****@*****.**"],
            "phoneNumbers" : [{"home" : "000-000-0000"}, {"work" : "111-111-1111"}],
            "socMedias"    : [{"google" : "*****@*****.**"}, {"skype" : "fflintstone"}]
        },
        "otherInfo" : {
            "gender"      : "M",
            "dateOfBirth" : "0000-01-01"
        },
        "login" : {
            "username" : "fred",
            "oauth2"   : "*****@*****.**",
            "password" : "abcdefghijklmnopqrstuvwxyz"
        },
        "totalBooked"  : 100,
        "discount"     : 0.05
    }'''

    def setUp(self):
        self.testDict['name'] = Name(self.testName)
        self.testDict['address'] = Location(self.testLocation)
        self.testDict['contact'] = Contact(self.testContact)
        self.testDict['otherContact'] = OtherContact(self.testOtherContact)
        self.testDict['otherInfo'] = OtherInfo(self.testOtherInfo)
        self.testDict['login'] = LoginInfo(self.testLoginInfo)
        self.customerFromDict = Customer(self.testDict)
        self.customerDefaults = Customer()
        self.maxDiff = None

    def test_customer_key(self):
        expected = '00000000'
        actual = self.customerFromDict.getKey()
        self.assertEqual(expected, actual)

    def test_customer_from_dict(self):
        expected = 'Flintstone'
        name = self.customerFromDict.get('name')
        actual = name.get('last')
        self.assertEqual(expected, actual)

    def test_customer_from_blank(self):
        expected = True
        actual = isinstance(self.customerDefaults.get('address'), Location)
        self.assertEqual(expected, actual)

    def test_customer_from_dict_to_json(self):
        expected = json.loads(self.testJson)
        actual = json.loads(self.customerFromDict.toJson())
        self.assertEqual(expected, actual)
コード例 #14
0
 def setUp(self) :
     self.nameFromDict = Name(self.testDict)
     self.nameDefaults = Name()
コード例 #15
0
def updateContact(request):

    # retrieve form and property services
    formSvc = FormService()
    message = ''
    config = Config()
    partSvc = PartnerService(config)
    propSvc = PropertyService(config)

    # number of validation checks to be performed
    check = 4

    # if this is a POST request process the form data
    if request.method == 'POST':

        # hydrate subforms from post data
        formSvc.hydrateFormsFromPost(request.POST)
        name_form = formSvc.getForm('name')
        contact_form = formSvc.getForm('contact')

        # validate partner key
        if 'prop_partnerKey' in request.POST:
            partKey = request.POST['prop_partnerKey']
            part = partSvc.fetchByKey(partKey)
            if part:
                check -= 1
            else:
                message += '<br>Unable to confirm this partner.'
        else:
            message += '<br>You need to choose a partner.'

        # validate property key
        if 'prop_propertyKey' in request.POST:
            propKey = request.POST['prop_propertyKey']
            prop = propSvc.fetchByKey(propKey)
            if prop:
                check -= 1
            else:
                message += '<br>Unable to confirm this property.'
        else:
            message += '<br>You need to choose a property.'

        # validate form data
        if name_form.is_valid(): check -= 1
        if contact_form.is_valid(): check -= 1

        # proceed if all validation checks are successful
        if check == 0:
            # extract name and contact information from subforms
            prop.set('contactName', Name(formSvc.getCleanDataByKey('name')))
            prop.set('contactInfo',
                     Contact(formSvc.getCleanDataByKey('contact')))
            # use PropertyService to update Property
            if propSvc.edit(prop):
                message += '<br>Property contact information updated successfully!'
                return HttpResponseRedirect('/property/list/' + prop.getKey())
            else:
                message += '<br>Unable to update form data.'
        else:
            message += '<br>Unable to validate this form.'

    # build master form
    context = {
        'message':
        message,
        'choose_part_form':
        ChoosePartnerForm(),
        'name_form_html':
        render_to_string('property_name.html',
                         {'form': formSvc.getForm('name')}),
        'contact_form_html':
        render_to_string('property_contact.html',
                         {'form': formSvc.getForm('contact')})
    }
    prop_master = render_to_string('property_update_contact.html', context)
    # embed form in layout
    page = render_to_string('layout.html', {'contents': prop_master})
    return HttpResponse(page)
コード例 #16
0
# sweetscomplete.entity.common.Common test

# tell python where to find module source code
import os, sys
sys.path.append(os.path.realpath("src"))

from booksomeplace.entity.base import Name

# Testing Name
params = {
    "title": 'Mr',
    "first": 'Fred',
    "middle": 'Folsom',
    "last": 'Flintstone',
    "suffix": 'CM'
}

# Create instance
name = Name(params)

# Output
import pprint
print("\nObject\n")
pprint.pprint(name)

print("\nJSON\n")
print(name.toJson())

print("\ndir()\n")
name.getVars()
コード例 #17
0
class TestProperty(unittest.TestCase):

    propertyFromDict = None
    propertyDefaults = None

    testDict = {
        'propertyKey': 'AAAA1111',
        'partnerKey': 'BBBB2222',
        'propName': 'Test',
        'propInfo': PropInfo(),
        'address': Location(),
        'contactName': Name(),
        'contactInfo': Contact(),
        'rooms': [],
        'reviews': [],
        'rating': 3,
        'totalBooked': 100
    }

    testPropInfo = {
        'type': 'hotel',
        'chain': 'Accor',
        'photos': ['image1.jpg', 'image2.jpg'],
        'facilities': ['free parking', 'wifi'],
        'description':
        'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
        'currency': 'GBP',
        'taxFee': 0.11
    }

    testLocation = {
        'streetAddress': '123 Main Street',
        'buildingName': 'The Gravel Building',
        'floor': '22',
        'roomAptCondoFlat': '',
        'city': 'Bedrock',
        'stateProvince': 'ZZ',
        'locality': 'Unknown',
        'country': 'None',
        'postalCode': '00000',
        'latitude': '+111.111',
        'longitude': '-111.111'
    }

    testName = {
        'title': 'Mr',
        'first': 'Fred',
        'middle': 'Folsom',
        'last': 'Flintstone',
        'suffix': 'CM'
    }

    testContact = {
        'email': '*****@*****.**',
        'phone': '+0-000-000-0000',
        'socMedia': {
            'google': '*****@*****.**'
        }
    }

    testRoomType1 = {
        'roomTypeKey': 'aa11',
        'type': 'Pool Side',
        'view': 'Pool',
        'description':
        'Cupcake ipsum dolor. Sit amet marshmallow topping cheesecake muffin. Halvah croissant candy canes bonbon candy. Apple pie jelly beans topping carrot cake danish tart cake cheesecake.',
        'beds': ['single', 'single'],
        'numAvailable': 22,
        'numBooked': 11,
        'price': 44.44
    }

    testRoomType2 = {
        'roomTypeKey': 'bb22',
        'type': 'Standard',
        'view': 'City',
        'description':
        'Lorem ipsum dolor sit amet consectetur adipiscing elit, urna consequat felis vehicula class ultricies mollis dictumst, aenean non a in donec nulla.',
        'beds': ['king'],
        'numAvailable': 12,
        'numBooked': 6,
        'price': 33.33
    }

    testReview = {
        'customerKey':
        'AAAABBBB0000',
        'staff':
        1,
        'cleanliness':
        2,
        'facilities':
        3,
        'comfort':
        4,
        'goodStuff':
        "All of the words in Lorem Ipsum have flirted with me - consciously or unconsciously. That's to be expected. Be careful, or I will spill the beans on your placeholder text. I’m the best thing that ever happened to placeholder text. Look at that text! Would anyone use that? Can you imagine that, the text of your next webpage?!",
        'badStuff':
        'Despite the constant negative ipsum covfefe. Lorem Ispum is a choke artist. It chokes!'
    }

    testJson = '''{
        "propertyKey" : "AAAA1111",
        "partnerKey"  : "BBBB2222",
        "propName"    : "Test",
        "propInfo"    : {
            "type"        : "hotel",
            "chain"       : "Accor",
            "photos"      : ["image1.jpg","image2.jpg"],
            "facilities"  : ["free parking","wifi"],
            "description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
            "currency"    : "GBP",
            "taxFee"      : 0.11
        },
        "address"     : {
            "streetAddress"    : "123 Main Street",
            "buildingName"     : "The Gravel Building",
            "floor"            : "22",
            "roomAptCondoFlat" : "",
            "city"             : "Bedrock",
            "stateProvince"    : "ZZ",
            "locality"         : "Unknown",
            "country"          : "None",
            "postalCode"       : "00000",
            "latitude"         : "+111.111",
            "longitude"        : "-111.111"
        },
        "contactName" : {
            "title"  : "Mr",
            "first"  : "Fred",
            "middle" : "Folsom",
            "last"   : "Flintstone",
            "suffix" : "CM"
        },
        "contactInfo" : {
            "email"    : "*****@*****.**",
            "phone"    : "+0-000-000-0000",
            "socMedia" : {"google" : "*****@*****.**"}
        },
        "rooms"       : [
            {
                "roomTypeKey"  : "aa11",
                "type"         : "Pool Side",
                "view"         : "Pool",
                "description"  : "Cupcake ipsum dolor. Sit amet marshmallow topping cheesecake muffin. Halvah croissant candy canes bonbon candy. Apple pie jelly beans topping carrot cake danish tart cake cheesecake.",
                "beds"         : ["single","single"],
                "numAvailable" : 22,
                "numBooked"    : 11,
                "price"        : 44.44
            },
            {
                "roomTypeKey"  : "bb22",
                "type"         : "Standard",
                "view"         : "City",
                "description"  : "Lorem ipsum dolor sit amet consectetur adipiscing elit, urna consequat felis vehicula class ultricies mollis dictumst, aenean non a in donec nulla.",
                "beds"         : ["king"],
                "numAvailable" : 12,
                "numBooked"    : 6,
                "price"        : 33.33
            }
        ],
        "reviews"     : [
            {
                "customerKey" : "AAAABBBB0000",
                "staff"       : 1,
                "cleanliness" : 2,
                "facilities"  : 3,
                "comfort"     : 4,
                "goodStuff"   : "All of the words in Lorem Ipsum have flirted with me - consciously or unconsciously. That's to be expected. Be careful, or I will spill the beans on your placeholder text. I’m the best thing that ever happened to placeholder text. Look at that text! Would anyone use that? Can you imagine that, the text of your next webpage?!",
                "badStuff"    : "Despite the constant negative ipsum covfefe. Lorem Ispum is a choke artist. It chokes!"
            }
        ],
        "rating" : 3,
        "totalBooked" : 100
    }'''

    def setUp(self):
        self.propertyDefaults = Property()
        self.testDict['propInfo'] = PropInfo(self.testPropInfo)
        self.testDict['address'] = Location(self.testLocation)
        self.testDict['contactName'] = Name(self.testName)
        self.testDict['contactInfo'] = Contact(self.testContact)
        self.testDict['rooms'] = [
            RoomType(self.testRoomType1),
            RoomType(self.testRoomType2)
        ]
        self.testDict['reviews'] = [Review(self.testReview)]
        self.propertyFromDict = Property(self.testDict)
        self.maxDiff = None

    def test_property_key(self):
        expected = 'AAAA1111'
        actual = self.propertyFromDict.getKey()
        self.assertEqual(expected, actual)

    def test_property_from_dict(self):
        expected = 'Flintstone'
        name = self.propertyFromDict.get('contactName')
        actual = name.get('last')
        self.assertEqual(expected, actual)

    def test_property_from_dict_book_room(self):
        roomList = self.propertyFromDict.get('rooms')
        # test booking room type 1
        expected = 21
        actual = roomList[0].bookOneRoom()
        self.assertEqual(expected, actual)
        # test booking room type 2
        expected = 11
        actual = roomList[1].bookOneRoom()
        self.assertEqual(expected, actual)

    def test_property_from_blank(self):
        expected = True
        actual = isinstance(self.propertyDefaults.get('propInfo'), PropInfo)
        self.assertEqual(expected, actual)

    def test_property_from_dict_to_json(self):
        expected = json.loads(self.testJson)
        actual = json.loads(self.propertyFromDict.toJson())
        self.assertEqual(expected, actual)
コード例 #18
0
ファイル: booking.py プロジェクト: gabrielmahia/somAI_MongoDB
class CustParty(Base) :
    fields = {
        'name'  : Name(),
        'other' : OtherInfo()
    }
コード例 #19
0
class TestBooking(unittest.TestCase):

    bookingFromDict = None
    bookingDefaults = None

    testDict = {
        'bookingKey': '20190501AAAA1111',
        'customer': CustBooking(),
        'property': PropBooking(),
        'bookingInfo': BookingInfo(),
        'rooms': [],
        'totalPrice': 999.99
    }

    testCustBooking = {
        'customerKey': '00000000',
        'customerName': Name(),
        'customerAddr': Location(),
        'customerContact': Contact(),
        'custParty': []
    }

    testCustName = {
        'title': 'Ms',
        'first': 'Wilma',
        'middle': 'Slaghoople',
        'last': 'Flintstone',
        'suffix': ''
    }

    testCustLocation = {
        'streetAddress': '345 Cave Stone Road',
        'buildingName': '',
        'floor': '',
        'roomAptCondoFlat': '',
        'city': 'Bedrock',
        'stateProvince': 'ZZ',
        'locality': 'Unknown',
        'country': 'None',
        'postalCode': '00000',
        'latitude': '+111.1111',
        'longitude': '-111.1111'
    }

    testCustContact = {
        'email': '*****@*****.**',
        'phone': '+0-000-000-0000',
        'socMedia': {
            'google': '*****@*****.**'
        }
    }

    testCustParty: [{
        'name': Name(),
        'other': OtherInfo()
    }, {
        'name': Name(),
        'other': OtherInfo()
    }]

    testCustPartyName1 = {
        'title': 'Mr',
        'first': 'Frederick',
        'middle': 'Joseph',
        'last': 'Flintstone',
        'suffix': 'Caveman'
    }

    testCustPartyName2 = {
        'title': 'Baby',
        'first': 'Bam',
        'middle': 'Bam',
        'last': 'Flintstone',
        'suffix': ''
    }

    testOtherInfo1 = {'gender': 'M', 'dateOfBirth': '0000-00-00'}

    testOtherInfo2 = {'gender': 'M', 'dateOfBirth': '0030-01-01'}

    testPropBooking = {
        'propertyKey': 'ZZZZ9999',
        'propertyName': 'The Slate Resort',
        'propertyAddr': Location(),
        'propertyContact': Contact()
    }

    testPropLocation = {
        'streetAddress': '140 Boulder Avenue',
        'buildingName': 'The Slate Resort',
        'floor': '',
        'roomAptCondoFlat': '',
        'city': 'Granite Town',
        'stateProvince': 'XX',
        'locality': 'Unknown',
        'country': 'None',
        'postalCode': '00001',
        'latitude': '+222.2222',
        'longitude': '-222.2222'
    }

    testPropContact = {
        'email': '*****@*****.**',
        'phone': '+0-000-000-0000',
        'socMedia': {
            'google': '*****@*****.**'
        }
    }

    testBookingInfo = {
        'arrivalDate': '0040-03-15',
        'departureDate': '0040-04-01',
        'checkoutTime': '12:00',
        'refundableUntil': '0040-03-28',
        'reservationStatus': 'pending',
        'paymentStatus': 'pending'
    }

    testRoomBooking = {
        'roomType': 'poolside',
        'roomTypeKey': '0001',
        'price': 99.99,
        'qty': 1
    }

    testJson = '''{
        "bookingKey" : "20190501AAAA1111",
        "customer"   : {
            "customerKey"    : "00000000",
            "customerName"   : {
                "title"  : "Ms",
                "first"  : "Wilma",
                "middle" : "Slaghoople",
                "last"   : "Flintstone",
                "suffix" : ""
            },
            "customerAddr"    : {
                "streetAddress"    : "345 Cave Stone Road",
                "buildingName"     : "",
                "floor"            : "",
                "roomAptCondoFlat" : "",
                "city"             : "Bedrock",
                "stateProvince"    : "ZZ",
                "locality"         : "Unknown",
                "country"          : "None",
                "postalCode"       : "00000",
                "latitude"         : "+111.1111",
                "longitude"        : "-111.1111"
            },
            "customerContact" : {
                "email"    : "*****@*****.**",
                "phone"    : "+0-000-000-0000",
                "socMedia" : {"google" : "*****@*****.**"}
            },
            "custParty"       : [
                {
                    "name"  : {
                        "title"  : "Mr",
                        "first"  : "Frederick",
                        "middle" : "Joseph",
                        "last"   : "Flintstone",
                        "suffix" : "Caveman"
                    },
                    "other" : {
                        "gender"      : "M",
                        "dateOfBirth" : "0000-00-00"
                    }
                },
                {
                    "name" : {
                            "title"  : "Baby",
                            "first"  : "Bam",
                            "middle" : "Bam",
                            "last"   : "Flintstone",
                            "suffix" : ""
                    },
                    "other" : {
                        "gender"      : "M",
                        "dateOfBirth" : "0030-01-01"
                    }
                }
            ]
        },
        "property" : {
            "propertyKey"  : "ZZZZ9999",
            "propertyName" : "The Slate Resort",
            "propertyAddr" : {
                "streetAddress"    : "140 Boulder Avenue",
                "buildingName"     : "The Slate Resort",
                "floor"            : "",
                "roomAptCondoFlat" : "",
                "city"             : "Granite Town",
                "stateProvince"    : "XX",
                "locality"         : "Unknown",
                "country"          : "None",
                "postalCode"       : "00001",
                "latitude"         : "+222.2222",
                "longitude"        : "-222.2222"
            },
            "propertyContact" : {
                "email"    : "*****@*****.**",
                "phone"    : "+0-000-000-0000",
                "socMedia" : {"google" : "*****@*****.**"}
            }
        },
        "bookingInfo"  : {
            "arrivalDate"       : "0040-03-15",
            "departureDate"     : "0040-04-01",
            "checkoutTime"      : "12:00",
            "refundableUntil"   : "0040-03-28",
            "reservationStatus" : "pending",
            "paymentStatus"     : "pending"
        },
        "rooms" : [
            {
                "roomType"    : "poolside",
                "roomTypeKey" : "0001",
                "price"       : 99.99,
                "qty"         : 1
            }
        ],
        "totalPrice" : 999.99
    }'''

    def setUp(self):
        custBooking = {
            'customerKey':
            '00000000',
            'customerName':
            Name(self.testCustName),
            'customerAddr':
            Location(self.testCustLocation),
            'customerContact':
            Contact(self.testCustContact),
            'custParty': [
                CustParty({
                    'name': Name(self.testCustPartyName1),
                    'other': OtherInfo(self.testOtherInfo1)
                }),
                CustParty({
                    'name': Name(self.testCustPartyName2),
                    'other': OtherInfo(self.testOtherInfo2)
                })
            ]
        }
        propBooking = {
            'propertyKey': 'ZZZZ9999',
            'propertyName': 'The Slate Resort',
            'propertyAddr': Location(self.testPropLocation),
            'propertyContact': Contact(self.testPropContact),
        }
        self.testDict = {
            'bookingKey': '20190501AAAA1111',
            'customer': custBooking,
            'property': propBooking,
            'bookingInfo': BookingInfo(self.testBookingInfo),
            'rooms': [RoomBooking(self.testRoomBooking)],
            'totalPrice': 999.99
        }
        self.bookingFromDict = Booking(self.testDict)
        self.bookingDefaults = Booking()
        self.maxDiff = None

    def test_booking_key(self):
        expected = '20190501AAAA1111'
        actual = self.bookingFromDict.getKey()
        self.assertEqual(expected, actual)

    def test_booking_from_dict(self):
        expected = 'Flintstone'
        custBook = self.bookingFromDict.get('customer')
        custName = custBook.get('customerName')
        actual = custName.get('last')
        self.assertEqual(expected, actual)

    def test_booking_from_blank(self):
        expected = True
        actual = isinstance(self.bookingDefaults.get('property'), PropBooking)
        self.assertEqual(expected, actual)

    def test_booking_from_dict_to_json(self):
        expected = json.loads(self.testJson)
        actual = json.loads(self.bookingFromDict.toJson())
        self.assertEqual(expected, actual)
コード例 #20
0
class TestPartner(unittest.TestCase):

    partnerFromDict = None
    partnerDefaults = None

    testDict = {
        'partnerKey': '00000000',
        'businessName': 'Granite Town Quarrel and Gravel Company',
        'revenueSplit': 0.90,
        'acctBalance': 9999.99,
        'name': Name(),
        'address': Location(),
        'contact': Contact(),
        'otherContact': OtherContact(),
        'otherInfo': OtherInfo(),
        'login': LoginInfo()
    }

    testLocation = {
        'streetAddress': '140 Boulder Avenue',
        'buildingName': 'The Granite Building',
        'floor': '22',
        'roomAptCondoFlat': '',
        'city': 'Granite Town',
        'stateProvince': 'ZZ',
        'locality': 'Unknown',
        'country': 'None',
        'postalCode': '00000',
        'latitude': '+111.111',
        'longitude': '-111.111'
    }

    testName = {
        'title': 'Mr',
        'first': 'Rockhead',
        'middle': 'Sylvester',
        'last': 'Slate',
        'suffix': 'Boss'
    }

    testContact = {
        'email': '*****@*****.**',
        'phone': '+0-000-000-0000',
        'socMedia': {
            'google': '*****@*****.**'
        }
    }

    testOtherContact = {
        'emails': ['*****@*****.**', '*****@*****.**'],
        'phoneNumbers': [{
            'home': '000-000-0000'
        }, {
            'work': '111-111-1111'
        }],
        'socMedias': [{
            'google': '*****@*****.**'
        }, {
            'skype': 'fslate'
        }]
    }

    testOtherInfo = {'gender': 'M', 'dateOfBirth': '0000-01-01'}

    testLoginInfo = {
        'username': '******',
        'oauth2': '*****@*****.**',
        'password': '******'
    }

    testJson = '''{
        "partnerKey"   : "00000000",
        "businessName" : "Granite Town Quarrel and Gravel Company",
        "revenueSplit" : 0.90,
        "acctBalance"  : 9999.99,
        "address"      : {
            "streetAddress"    : "140 Boulder Avenue",
            "buildingName"     : "The Granite Building",
            "floor"            : "22",
            "roomAptCondoFlat" : "",
            "city"             : "Granite Town",
            "stateProvince"    : "ZZ",
            "locality"         : "Unknown",
            "country"          : "None",
            "postalCode"       : "00000",
            "latitude"         : "+111.111",
            "longitude"        : "-111.111"
        },
        "name" : {
            "title"  : "Mr",
            "first"  : "Rockhead",
            "middle" : "Sylvester",
            "last"   : "Slate",
            "suffix" : "Boss"
        },
        "contact" : {
            "email"    : "*****@*****.**",
            "phone"    : "+0-000-000-0000",
            "socMedia" : {"google" : "*****@*****.**"}
        },
        "otherContact" : {
            "emails"       : ["*****@*****.**", "*****@*****.**"],
            "phoneNumbers" : [{"home" : "000-000-0000"}, {"work" : "111-111-1111"}],
            "socMedias"    : [{"google" : "*****@*****.**"}, {"skype" : "fslate"}]
        },
        "otherInfo" : {
            "gender"      : "M",
            "dateOfBirth" : "0000-01-01"
        },
        "login" : {
            "username" : "rockhead",
            "oauth2"   : "*****@*****.**",
            "password" : "abcdefghijklmnopqrstuvwxyz"
        }
    }'''

    def setUp(self):
        self.testDict['name'] = Name(self.testName)
        self.testDict['address'] = Location(self.testLocation)
        self.testDict['contact'] = Contact(self.testContact)
        self.testDict['otherContact'] = OtherContact(self.testOtherContact)
        self.testDict['otherInfo'] = OtherInfo(self.testOtherInfo)
        self.testDict['login'] = LoginInfo(self.testLoginInfo)
        self.partnerFromDict = Partner(self.testDict)
        self.partnerDefaults = Partner()
        self.maxDiff = None

    def test_partner_key(self):
        expected = '00000000'
        actual = self.partnerFromDict.getKey()
        self.assertEqual(expected, actual)

    def test_partner_from_dict(self):
        expected = 'Slate'
        name = self.partnerFromDict.get('name')
        actual = name.get('last')
        self.assertEqual(expected, actual)

    def test_partner_from_blank(self):
        expected = True
        actual = isinstance(self.partnerDefaults.get('address'), Location)
        self.assertEqual(expected, actual)

    def test_partner_from_dict_to_json(self):
        expected = json.loads(self.testJson)
        actual = json.loads(self.partnerFromDict.toJson())
        self.assertEqual(expected, actual)