Пример #1
0
    def test_000_validate_factory_create(self):
        """Validate single fake object created"""

        if not self.schema:
            self.skipTest('Failed to fetch json schema.')

        factory = V2ProfileFactory()
        output = factory.create()

        try:
            validate(output, self.schema)
        except:
            self.fail('Validation failed!')
Пример #2
0
    def test_001_validate_factory_create_batch(self):
        """Validate multiple fake objects created"""

        if not self.schema:
            self.skipTest('Failed to fetch json schema.')

        factory = V2ProfileFactory()
        output = factory.create_batch(10)

        for obj in output:
            try:
                validate(obj, self.schema)
            except:
                self.fail('Validation failed!')
Пример #3
0
def populate_fake_data(count):
    """Populate elasticsearch with fake data."""

    es = Elasticsearch([settings.ES_URL])

    factory = V2ProfileFactory()
    objects = factory.create_batch(count)

    for obj in objects:

        es.index(index=settings.ES_DINOPARK_INDEX,
                 doc_type='dinopark_profile_v2',
                 id=obj['user_id']['value'],
                 body=obj)
Пример #4
0
def add_new_employee():
    factory = V2ProfileFactory()
    new_emp = factory.create()
    people = People()
    people.first_name = json.dumps(new_emp['first_name']['value'], sort_keys=True, indent=4).replace('"', '')
    people.last_name = json.dumps(new_emp['last_name']['value'], sort_keys=True, indent=4).replace('"', '')
    people.email = json.dumps(new_emp['primary_email']['value']).replace('"', '')
    people.city = json.dumps(new_emp['access_information']['hris']['values']['LocationCity']).replace('"', '')
    people.state = json.dumps(new_emp['access_information']['hris']['values']['LocationState']).replace('"', '')
    people.country = json.dumps(new_emp['access_information']['hris']['values']['LocationCountryISO2']).replace('"', '')
    people.timezone = json.dumps(new_emp['timezone']['value']).replace('"', '')
    people.emp_id = json.dumps(new_emp['access_information']['hris']['values']['EmployeeID'], sort_keys=True, indent=4)
    employee_id = json.dumps(new_emp['access_information']['hris']['values']['EmployeeID'], sort_keys=True, indent=4)
    people.slack_handle = find_slack_handle(json.dumps(new_emp['usernames']['values']))
    people.start_date = datetime.datetime.strptime(json.dumps(new_emp['created']['value']).replace('"', ''), '%Y-%m-%dT%H:%M:%S').isoformat()
    people.phone = json.dumps(new_emp['phone_numbers']['values'])
    people.manager_id = json.dumps(new_emp['access_information']['hris']['values']['WorkersManagersEmployeeID'])
    people.title = json.dumps(new_emp['access_information']['hris']['values']['businessTitle']).replace('"', '')
    people.picture = json.dumps(new_emp['picture']['value']).replace('"', '')
    people.last_updated = datetime.datetime.strptime(json.dumps(new_emp['last_modified']['value']).replace('"', ''),
                                     '%Y-%m-%dT%H:%M:%S')
    print(json.dumps(new_emp['first_name']['value'], sort_keys=True, indent=4).replace('"', ''))
    print(json.dumps(new_emp['phone_numbers']['values']))
    # print(json.dumps(new_emp, indent=4))

    people.admin_opt_out = False
    people.user_opt_out = False
    people.manager_opt_out = False

    people.save()
    print('employee id = {}'.format(employee_id))
    newly_added_user = People.objects(emp_id=employee_id)
    print('newly added user = {}'.format(newly_added_user[0].first_name))
    new_person = {}
    for p in newly_added_user:
        new_person['first_name'] = p.first_name
        new_person['last_name'] = p.last_name
        print('{} {} {} {} {} {}'.format(p.first_name, p.last_name, p.emp_id, p.start_date, p.manager_id, p.picture))
        add_messages_to_send(p)
    return 'You added {}'.format(new_person)
 def test_001_factory_create_batch(self, mock_create):
     """Test create batch factory."""
     mock_create.return_value = {'foo': 'bar'}
     factory = V2ProfileFactory()
     output = [{'foo': 'bar'}, {'foo': 'bar'}]
     assert factory.create_batch(2) == output
 def test_000_factory_create(self, mock_create):
     """Test create factory."""
     mock_create.return_value = {'foo': 'bar'}
     factory = V2ProfileFactory()
     assert factory.create() == {'foo': 'bar'}