def test_go_right(self):

        partner = Partner('id', 'name')

        partner.delete()

        self.assertEqual(1, self.mockProcessRequest.call_count)
        self.assertEqual(partner.netki_client, self.mockProcessRequest.call_args[0][0])
        self.assertEqual('/v1/admin/partner/name', self.mockProcessRequest.call_args[0][1])
        self.assertEqual('DELETE', self.mockProcessRequest.call_args[0][2])
    def test_go_right(self):

        partner = Partner('id', 'name')

        partner.delete()

        self.assertEqual(1, self.mockProcessRequest.call_count)
        self.assertEqual(partner.netki_client,
                         self.mockProcessRequest.call_args[0][0])
        self.assertEqual('/v1/admin/partner/name',
                         self.mockProcessRequest.call_args[0][1])
        self.assertEqual('DELETE', self.mockProcessRequest.call_args[0][2])
Esempio n. 3
0
 def test_to_identification_json_incomplete(self):
     partner = Partner()
     partner.builder({
         'agency_name': '',
         'Addr1': 'PO Box 129',
         'City': '',
         'State': '',
         'Zip': ''
     })
     expected = {'Organization': None, 'Location': 'None, None, None'}
     for key in expected.keys():
         self.assertEqual(expected[key],
                          partner.to_identification_json()[key])
Esempio n. 4
0
    def parse_csv(self):
        """Convert a CSV file to a list of Partner objects
        Returns:
        An array of partner objects"""
        array_of_partners = []
        with open(CWD + '/analysis/assets/partners.csv') as csv_file:
            reader = csv.DictReader(csv_file)
            for row in reader:
                partner = Partner()
                partner.builder(row)
                array_of_partners.append(partner)

        return array_of_partners
Esempio n. 5
0
 def test_assert_fieldsself_city_missing(self):
     testDictionary = {
         'AgencyRef': '200191',
         'agency_name': 'EAGLES NEST MINISTRIES',
         'Addr1': 'PO Box 129',
         'Addr2': '26633 Zion Church Rd',
         'City': '',
         'State': 'DE',
         'Zip': '19968',
         'Phone': '302684-4983',
         'County': 'SUSSEX',
         'Group': 'FOOD CLOSET'
     }
     partner = Partner()
     partner.builder(testDictionary)
     self.assertEqual(partner.city(), None)
Esempio n. 6
0
 def test_to_identification_json(self):
     partner = Partner()
     partner.builder({
         'agency_name': 'EAGLES NEST MINISTRIES',
         'Addr1': 'PO Box 129',
         'City': 'Milton',
         'State': 'DE',
         'Zip': '19968'
     })
     expected = {
         'Organization': 'EAGLES NEST MINISTRIES',
         'Location': 'Milton, DE, 19968'
     }
     for key in expected.keys():
         self.assertEqual(expected[key],
                          partner.to_identification_json()[key])
    def create_partner(self, partner_name):
        """
        Sub-partner Operation

        Create a sub-partner.

        :param partner_name: Partner Name
        :return: Partner object
        """

        response = process_request(self, '/v1/admin/partner/' + partner_name, 'POST')

        partner = Partner(id=response.partner.id, name=response.partner.name)
        partner.set_netki_client(self)

        return partner
Esempio n. 8
0
 def test_to_user_json_incomplete(self):
     partner = Partner()
     partner.builder({
         'agency_name': '',
         'Addr1': 'PO Box 129',
         'City': 'Milton',
         'State': 'DE',
         'Zip': '19968'
     })
     expected = {
         'Name': None,
         'Type': 'Partner',
         'Password': '******',
         'Username': None
     }
     for key in expected.keys():
         self.assertEqual(expected[key], partner.to_user_json()[key])
Esempio n. 9
0
    def test_assert_parser(self):
        test_csv = {
            'AgencyRef': '200191',
            'agency_name': 'EAGLES NEST MINISTRIES',
            'Addr1': 'PO Box 129',
            'Addr2': '26633 Zion Church Rd',
            'City': 'Milton',
            'State': 'DE',
            'Zip': '19968',
            'Phone': '302684-4983',
            'County': 'SUSSEX',
            'Group': 'FOOD CLOSET'
        }
        partner = Partner()
        partner.builder(test_csv)

        self.assertEqual(partner.agency_name(), 'EAGLES NEST MINISTRIES')
    def get_partners(self):
        """
        Sub-partner Operation

        Get all partners (partner and sub-partners) associated with your account.

        :return: List containing Partner objects
        """

        response = process_request(self, '/v1/admin/partner', 'GET')

        partner_objects = list()
        for p in response.partners:
            partner = Partner(id=p.id, name=p.name)
            partner_objects.append(partner)

            partner.set_netki_client(self)

        return partner_objects
Esempio n. 11
0
def parse_json(json_in):
    country_result = []
    country_dict = dict()

    """
         Adds a country to the dictionary if it does not already exist
    """
    for p in json_in['partners']:
        employee = Partner(p)
        if employee.country not in country_dict:
            country_dict[employee.country] = dict()

        """
            Sets an employee under the subdictionary to hold the available dates
        """
        for available in employee.dates_available:
            if available not in country_dict[employee.country]:
                country_dict[employee.country][available] = set()
            country_dict[employee.country][available].add(employee)


        for country, dates in country_dict.items():
            sorted_dates = sorted(dates.keys())
            min_attendees = 0
            min_days = None
            max_attendees = set()

            """
                Parses all date formats to a readable form that can be used to compare. This is how to find two
                dates that are consecutive
            """
            for i in range(len(sorted_dates[:-1])):

                current_date = sorted_dates[i]
                current_tomorrow = sorted_dates[i+1]
                current_date_formatted = parse(current_date)
                current_tomorrow_formatted = parse(current_tomorrow)

                date_attendees = dates[current_date]
                tomorrow_attendees = dates[current_tomorrow]

                if current_tomorrow_formatted - current_date_formatted != datetime.timedelta(1):
                    continue
                attendees = date_attendees & tomorrow_attendees
                attend_total = len(attendees)

                """
                    Sets a new date if the total number of attendees for a given date is greater than the already
                    existing max date
                """
                if attend_total > min_attendees:
                    min_attendees = attend_total
                    min_days = current_date
                    max_attendees = attendees
            """
                Creates Country objects to hold the correct format able to be put into JSON
            """
            country = Country()
            country.name = country
            if min_attendees > 0:
                country.final_start_date = min_attendees
            for attendee in max_attendees:
                country.add(attendee)
            country_result.append(country)
            return country_result
    def test_init(self):
        partner = Partner('id', 'name')

        self.assertEqual('id', partner.id)
        self.assertEqual('name', partner.name)