예제 #1
0
    def test_getAllOrganizationsJSON(self):
        ''' Get the JSON version of all organizations. '''
        jsonified = controllers.getAllOrganizationsJSON(self.db)

        data = json.loads(jsonified)
        for root,orgs in data.iteritems():
            self.assertEquals(root, 'Organizations')

            orgList = list()
            for org in orgs:
                newOrg = controllers.extractOrganizationFromDict(org)
                orgList.append(newOrg)

            allOrgs = controllers.getAllOrganizations(self.db)
            for first,second in zip(allOrgs,orgList):
                self.assertEqual(first.entityFK, second.entityFK);
                self.assertEqual(first.name, second.name)
                self.assertEqual(first.description, second.description)
                self.assertEqual(first.entity.pk, second.entity.pk)
                self.assertEqual(first.entity.type, second.entity.type)
                for a1,a2 in zip(first.entity.addresses, second.entity.addresses):
                    self.assertEqual(a1.entityFK, a2.entityFK)
                    self.assertEqual(a1.address1, a2.address1)
                    self.assertEqual(a1.address2, a2.address2)
                    self.assertEqual(a1.address3, a2.address3)
                    self.assertEqual(a1.city, a2.city)
                    self.assertEqual(a1.province, a2.province)
                    self.assertEqual(a1.country, a2.country)
                    self.assertEqual(a1.postalcode, a2.postalcode)
                    self.assertEqual(a1.isprimary, a2.isprimary)
                for c1,c2 in zip(first.entity.contacts, second.entity.contacts):
                    self.assertEqual(c1.entityFK, c2.entityFK)
                    self.assertEqual(c1.type, c2.type)
                    self.assertEqual(c1.value, c2.value)
                    self.assertEqual(c1.isprimary, c2.isprimary)
예제 #2
0
    def test_extractOrganizationFromDict(self):
        control = models.Organization.query.first()
        stringJSON = '{"org_entityfk":1,"org_name":"Ai-Kon","org_desc":"Ai-Kon Anime Convention","Entity":{"entity_pk":1,"entity_type":"1","addresses":[{"addr_entityfk":1,"address1":"123 Vroom Street","address2":"None","address3":"None","city":"Winnipeg","province":"Manitoba","country":"Canada","postalcode":"A1A1A1","isprimary":"True"}], "contacts":[{"contact_entityfk":1,"type":"2","value":"*****@*****.**","isprimary":"True"}]}}'
        data = json.loads(stringJSON)
        target = controllers.extractOrganizationFromDict(data)

        self.assertEqual(control.entityFK, target.entityFK);
        self.assertEqual(control.name, target.name)
        self.assertEqual(control.description, target.description)
        self.assertEqual(control.entity.pk, target.entity.pk)
        self.assertEqual(control.entity.type, target.entity.type)
        for a1,a2 in zip(control.entity.addresses, target.entity.addresses):
            self.assertEqual(a1.entityFK, a2.entityFK)
            self.assertEqual(a1.address1, a2.address1)
            self.assertEqual(a1.address2, a2.address2)
            self.assertEqual(a1.address3, a2.address3)
            self.assertEqual(a1.city, a2.city)
            self.assertEqual(a1.province, a2.province)
            self.assertEqual(a1.country, a2.country)
            self.assertEqual(a1.postalcode, a2.postalcode)
            self.assertEqual(a1.isprimary, a2.isprimary)
        for c1,c2 in zip(control.entity.contacts, target.entity.contacts):
            self.assertEqual(c1.entityFK, c2.entityFK)
            self.assertEqual(c1.type, c2.type)
            self.assertEqual(c1.value, c2.value)
            self.assertEqual(c1.isprimary, c2.isprimary)
예제 #3
0
    def test_getOrganizationByIDJSON(self):
        ''' Test getOrganizationByID method '''
        ''' Validate first organization entries '''
        jsonify = json.loads(controllers.getOrganizationByIDJSON(1))
        org = controllers.extractOrganizationFromDict(jsonify)
        self.assertIsNotNone(org)
        self.assertEqual(org.entityFK, 1)
        self.assertEquals(org.name, 'Ai-Kon')
        self.assertEquals(org.description, 'Ai-Kon Anime Convention')
        self.assertEquals(org.entity.type, models.TYPE_ORGANIZATION)
        self.assertEquals(org.entity.addresses[0].address1, '123 Vroom Street')
        self.assertEquals(org.entity.addresses[0].address2, None)
        self.assertEquals(org.entity.addresses[0].address3, None)
        self.assertEquals(org.entity.addresses[0].city, 'Winnipeg')
        self.assertEquals(org.entity.addresses[0].province, 'Manitoba')
        self.assertEquals(org.entity.addresses[0].country, 'Canada')
        self.assertEquals(org.entity.addresses[0].postalcode, 'A1A1A1')
        self.assertEquals(org.entity.addresses[0].isprimary, True)
        self.assertEquals(org.entity.contacts[0].type, models.TYPE_EMAIL)
        self.assertEquals(org.entity.contacts[0].value, '*****@*****.**')
        self.assertEquals(org.entity.contacts[0].isprimary, True)

        ''' Validate second organization entries '''
        jsonify = json.loads(controllers.getOrganizationByIDJSON(2))
        org = controllers.extractOrganizationFromDict(jsonify)
        self.assertIsNotNone(org)
        self.assertEquals(org.entityFK, 2) 
        self.assertEquals(org.name, 'University of Manitoba')
        self.assertEquals(org.description, 'The University of Manitoba, is a public university in the province of Manitoba, Canada. Located in Winnipeg, it is Manitoba\'s largest, most comprehensive, and only research-intensive post-secondary educational institution.')
        self.assertEquals(org.entity.type, models.TYPE_ORGANIZATION)
        self.assertEquals(org.entity.addresses[0].address1, '66 Chancellors Circle')
        self.assertEquals(org.entity.addresses[0].address2, None)
        self.assertEquals(org.entity.addresses[0].address3, None)
        self.assertEquals(org.entity.addresses[0].city, 'Winnipeg')
        self.assertEquals(org.entity.addresses[0].province, 'Manitoba')
        self.assertEquals(org.entity.addresses[0].country, 'Canada')
        self.assertEquals(org.entity.addresses[0].postalcode, 'R3T2N2')
        self.assertEquals(org.entity.addresses[0].isprimary, True)
        self.assertEquals(org.entity.contacts[0].type, models.TYPE_PHONE)
        self.assertEquals(org.entity.contacts[0].value, '18004321960')
        self.assertEquals(org.entity.contacts[0].isprimary, True)

        ''' Attempt an invalid organization '''
        org = controllers.getOrganizationByIDJSON(3)
        self.assertIsNone(org)