def create_entries(factory): author = UserFactory() entries = [] date1 = datetime.datetime(2012, 8, 12, 11, 0, 0) delta = datetime.timedelta(hours=4) date2 = datetime.datetime(2012, 10, 12, 11, 1, 0) if settings.USE_TZ: date1 = pytz.timezone(settings.TIME_ZONE).localize(date1, is_dst=None) date2 = pytz.timezone(settings.TIME_ZONE).localize(date2, is_dst=None) entries.append( factory.create( pk=1, author=author, title='Entry 1', published_on=date1, last_changed=date1 + delta, slug='entry-1', language='en', )) entries.append( factory.create( pk=2, author=author, title='Eintrag 1', published_on=date2, last_changed=date2 + delta, slug='eintrag-1', language='en', )) return entries
def create_entries(factory): author = UserFactory() entries = [] date1 = datetime.datetime(2012, 8, 12, 11, 0, 0) delta = datetime.timedelta(hours=4) date2 = datetime.datetime(2012, 10, 12, 11, 1, 0) if settings.USE_TZ: date1 = pytz.timezone(settings.TIME_ZONE).localize(date1, is_dst=None) date2 = pytz.timezone(settings.TIME_ZONE).localize(date2, is_dst=None) entries.append(factory.create( pk=1, author=author, title='Entry 1', published_on=date1, last_changed=date1+delta, slug='entry-1', language='en', )) entries.append(factory.create( pk=2, author=author, title='Eintrag 1', published_on=date2, last_changed=date2+delta, slug='eintrag-1', language='en', )) return entries
def pause_in_progress_with_ongoing_pomodoro(task_instance): pomodoro_in_progress = factory.create(klass=DateFrameFactory, task=task_instance, end=None, frame_type=0) pause_in_progress = factory.create(klass=DateFrameFactory, task=task_instance, end=None, frame_type=2) return pause_in_progress, pomodoro_in_progress
def pomodoro_in_progress_with_breaks_and_pauses(task_instance): pomodoro_date_frame = factory.create(klass=DateFrameFactory, task=task_instance, end=None, frame_type=0) factory.create(klass=InnerDateFrameFactory, task=task_instance, frame_type=1, start=get_time_delta({'minutes': 2}), end=get_time_delta({'minutes': 4})) factory.create(klass=InnerDateFrameFactory, task=task_instance, frame_type=1, start=get_time_delta({'minutes': 5}), end=get_time_delta({'minutes': 7})) factory.create(klass=InnerDateFrameFactory, task=task_instance, frame_type=2, start=get_time_delta({'minutes': 10}), end=get_time_delta({'minutes': 12})) factory.create(klass=InnerDateFrameFactory, task=task_instance, frame_type=2, start=get_time_delta({'minutes': 15}), end=get_time_delta({'minutes': 19})) return pomodoro_date_frame
def date_frame_in_progress_for_yesterday(task_instance): date_frame_instance = factory.create(klass=DateFrameFactory, task=task_instance, start=get_time_delta({'days': 1}, ahead=False), end=None) return date_frame_instance
def duplicate_task_instance_in_second_project(task_instance, second_project_instance, priority_instance, project_instance): return factory.create(klass=TaskFactory, priority=priority_instance, project=second_project_instance, name=task_instance.name)
def completed_repeatable_task_instance(task_model, priority_instance, project_instance): return factory.create(klass=TaskFactory, priority=priority_instance, project=project_instance, due_date=timezone.now(), repeat_duration=timedelta(days=random.randint(1, 5)), status=task_model.status_completed)
def test_view_one_resource(self): new_resource = create(ResourceFactory) url = f'/api/v1/resources/{new_resource.guid}/' response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['title'], new_resource.title) self.assertEqual(response.data['description'], new_resource.description)
def create_chinese_entries(factory): entries = create_entries(factory) author = entries[0].author factory.create(pk=3, author=author, title='Entry 2 chinese traditional', language='zh-hans', translation_of=entries[0], published_on=datetime.datetime(2012, 10, 12, 12, 0, 0), last_changed=datetime.datetime(2012, 10, 12, 16, 0, 0), slug='entry-2-cn') factory.create(pk=4, author=author, title='Entry 2 chinese simplified', language='zh-hant', translation_of=entries[0], published_on=datetime.datetime(2012, 10, 12, 12, 0, 0), last_changed=datetime.datetime(2012, 10, 12, 16, 0, 0), slug='entry-2-tw')
def seed(self, source, file_location, who): db = self._get_db(who) programs = self._parse_source_args(source) for program in programs: seederClass = factory.create(program) seeder = seederClass(db, file_location=file_location) seeder.seed()
def create_entries(factory): author = UserFactory() entries = [] entries.append(factory.create( pk=1, author=author, title=u'Entry 1', published_on=datetime.datetime(2012,8,12, 11,0,0), last_changed=datetime.datetime(2012,8,12, 15,0,0), slug='entry-1' )) entries.append(factory.create( pk=2, author=author, title=u'Eintrag 1', published_on=datetime.datetime(2012,10,12, 11,0,0), last_changed=datetime.datetime(2012,10,12, 15,0,0), slug='eintrag-1' )) return entries
def obsolete_date_frames(task_instance): obsolete_pomodoro = factory.create(klass=DateFrameFactory, task=task_instance, start=get_time_delta({'days': 8}, ahead=False), frame_type=0, end=None) obsolete_break = factory.create(klass=DateFrameFactory, task=task_instance, start=get_time_delta({'days': 8}, ahead=False), frame_type=1, end=None) obsolete_pause = factory.create(klass=DateFrameFactory, task=task_instance, start=get_time_delta({'days': 8}, ahead=False), frame_type=2, end=None) return obsolete_pomodoro, obsolete_break, obsolete_pause
def create_entries(factory): author = UserFactory() entries = [] entries.append(factory.create( pk=1, author=author, title=u'Entry 1', published_on=datetime.datetime(2012, 8, 12, 11, 0, 0), last_changed=datetime.datetime(2012, 8, 12, 15, 0, 0), slug='entry-1' )) entries.append(factory.create( pk=2, author=author, title=u'Eintrag 1', published_on=datetime.datetime(2012, 10, 12, 11, 0, 0), last_changed=datetime.datetime(2012, 10, 12, 15, 0, 0), slug='eintrag-1' )) return entries
def _generate_many_to_many_list(factory): """Helper function to help generate a list of related objects.""" # Generate a list of elements with an emphasis on 0- and # 1-length lists length = random.randint(0, 2) if length == 2: length = random.randint(2, 30) lst = [factory.create() for i in range(length)] return lst
def update(self, source, who): db = self._get_db(who) programs = self._parse_source_args(source) for program in programs: seederClass = factory.create(program) seeder = seederClass(db) seeder.update() self._update_params_table(who)
def test_delete_one_resource(self): records = create_batch(ResourceFactory, 10) new_resource = create(ResourceFactory) url = f'/api/v1/resources/{new_resource.guid}/' response = self.client.delete(url) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) subsequent_response = self.client.get(url) self.assertEqual(subsequent_response.status_code, status.HTTP_404_NOT_FOUND) count_check = self.client.get('/api/v1/resources/') self.assertEqual(count_check.data['count'], 10)
def create_chinese_entries(factory): entries = create_entries(factory) author = entries[0].author factory.create( pk=3, author=author, title='Entry 2 chinese traditional', language='zh-cn', translation_of=entries[0], published_on=datetime.datetime(2012, 10, 12, 12, 0, 0), last_changed=datetime.datetime(2012, 10, 12, 16, 0, 0), slug='entry-2-cn' ) factory.create( pk=4, author=author, title='Entry 2 chinese simplified', language='zh-tw', translation_of=entries[0], published_on=datetime.datetime(2012, 10, 12, 12, 0, 0), last_changed=datetime.datetime(2012, 10, 12, 16, 0, 0), slug='entry-2-tw' )
def get_points(self, query, count=10, scope='*'): # type: (str, int, str) -> osisoftpy.structures.TypedList[Point] """ :param query: :param count: :param scope: :return: """ payload = {'q': query, 'count': count, 'scope': scope} log.debug( 'Executing Query against PI Web WebAPI Indexed Search with ' 'the following parameters: Query: "%s", Count: "%s". Payload: %s', query, count, payload) r = self.session.get(self.url + '/search/query', params=payload) if r.status_code != requests.codes.ok: r.raise_for_status() else: data = r.json() log.debug('HTTP %s - Instantiating %s PI points', r.status_code, get_count(data.get('Items', None))) factory = Factory(Point) items = list(map(lambda x: create(factory, x), data.get('Items', None))) points = TypedList(Point) for point in items: points.append(point) log.debug('PI Point retrieval success! %s PI ' 'point(s) were ' 'found and instantiated.', get_count(points)) if len(data['Errors']) != 0: for error in data['Errors']: try: log.warning('The PI Web WebAPI returned the ' 'following error while instantiating ' 'PI points. ' 'ErrorCode: {0}, Source: {1}, ' 'Message {2}'.format( error['ErrorCode'], error['Source'], error['Message'])) except Exception as e: log.error('Exception encounted while ' 'instantiating ' 'PI points!', exc_info=True) return points
def test_patch_one_resource(self): new_resource = create(ResourceFactory) url = f'/api/v1/resources/{new_resource.guid}/' data = { "description": "A _diabolically irresponsible_ talk in which I celebrate modern Python coding by **abandoning all backwards compatibility** THE END", "author": "David Beazley", "tags": ["test tags", "testing", "python"] } response = self.client.patch(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['description'], data['description']) self.assertEqual(response.data['author'], data['author']) self.assertEqual( sorted(item['name'] for item in response.data['tags']), sorted(data['tags']))
def test_search_resources(self): create(ResourceFactory, title="Elm Crash-Course (Reactivate London)") create(ResourceFactory, title="elm Documentation") create( ResourceFactory, description= "The best place to start is the official guide. It will give you a solid foundation for creating applications with Elm. Once you have worked through that, the next place to look for documentation is on the packages you are using." ) create( ResourceFactory, description= "Elm is a programming language targeted at the front end (runs in a browser, not on Node) that offers a different take on building dynamic web applications." ) url = '/api/v1/resources/?search=Elm' response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['count'], 4) self.assertContains(response, "Elm Crash-Course (Reactivate London)") self.assertContains(response, "or creating applications with Elm. ")
def test_trackedmodel_get_description_create_url(factory): """Verify get_url() returns something for creating descriptions.""" instance = factory.create() url = instance.get_url("description-create") assert url
def getattr(self, path): print 'UFS GETATTR C_F_S' return factory.create(FuseStat, os.stat(self._get_real_path(path)))
def generate_mode(options): data = open_read_yaml(options.path[0]) print pretty_xml(factory.create(parser.parse(data))) return 0
def sub_task_instance(task_instance): return factory.create(klass=SubTaskFactory, task=task_instance)
def date_frame_in_progress(task_instance): return factory.create(klass=DateFrameFactory, task=task_instance, end=None)
def create_object(self): factory = self.get_factory_class() return factory.create()
def test_create(self): obj = factory.create(FakeDjangoModel, foo='bar') self.assertEqual(obj.id, 1) self.assertEqual(obj.foo, 'bar')
def test_create(self): obj = factory.create(FakeModel, foo='bar') self.assertEqual(obj.id, 2) self.assertEqual(obj.foo, 'bar')
def test_delete_one_resource(self): new_resource = create(ResourceFactory) url = f'/api/v1/resources/{new_resource.guid}/' response = self.client.delete(url) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
def test_patch_one_resource(self): new_resource = create(ResourceFactory) url = f'/api/v1/resources/{new_resource.guid}/' response = self.client.patch(url, {}, format='json') self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
def date_frame_for_random_task(task_instance_for_random_project): return factory.create(klass=DateFrameFactory, task=task_instance_for_random_project)
def test_create_custom_base(self): obj = factory.create(FakeModel, foo='bar', FACTORY_CLASS=factory.DjangoModelFactory) self.assertEqual(obj.id, 2) self.assertEqual(obj.foo, 'bar')
def test_trackedmodel_get_create_url(factory): instance = factory.create() url = instance.get_url("create") assert url
def getattr(self, path): debug('UFS GETATTR C_F_S') return factory.create(FuseStat, os.stat(self._get_real_path(path)))
import factory fun = factory.create("operation.add") print(fun.__name__) print(fun(1, 2)) fun = factory.create("operation.minus") print(fun.__name__) print(fun(1, 2)) fun = factory.create("operation.multify")
def date_frame_instance(task_instance): return factory.create(klass=DateFrameFactory, task=task_instance)
def task_instance_for_random_project(project_instance_for_random_user): return factory.create(klass=TaskFactory, project=project_instance_for_random_user)
def sub_task_for_random_task(task_instance_for_random_project): return factory.create(klass=SubTaskFactory, task=task_instance_for_random_project)
def coolstuff(self): create({"arg1": "coool", "arg2": "stuff"})
def pause_in_progress(task_instance): return factory.create(klass=DateFrameFactory, task=task_instance, end=None, frame_type=2)