def get_mock_data(self, optional=True): mock_data = super().get_mock_data() mock_data.update({ 'short_name': '[Shot name]', 'location': '[Project location]', 'project_name': '[Client Name]', 'timezone_name': 'Europe/Madrid', 'timezone_utc': '+1.00', 'start_at': '2017-08-03T10:00:00.000000', 'public_url': '/{}'.format(faker.uri_path()), 'total_questions': faker.pyint(), 'your_answers': faker.pyint(), 'rating': 4, 'disable_notification_url': '/{}'.format(faker.uri_path()), }) return mock_data
class VideoFactory(factory.DictFactory): type = settings.RESOURCE_CH_TYPE_VIDEO_VIMEO status = settings.RESOURCE_PROVIDER_STATUS_AVAILABLE name = factory.Sequence(lambda x: faker.word() + str(faker.pyint())) description = factory.Sequence(lambda x: faker.text()) link = factory.Sequence( lambda x: 'https://vimeo.com/' + str(faker.pyint())) url = factory.Sequence(lambda x: faker.url()) sections = [settings.RESOURCE_CH_SECTION_SPRINT_AUTOMATED] thumbnail = factory.Sequence(lambda x: faker.url()) duration = factory.Sequence(lambda x: faker.random_digit()) modified = factory.Sequence(lambda x: faker.date_time_this_year( before_now=True, tzinfo=pytz.timezone('utc')).isoformat()) pictures = { "sizes": [{ "link": "https://i.vimeocdn.com/video/686815740_100x75.jpg?r=pad", }, { "link": "https://i.vimeocdn.com/video/686815740_200x150.jpg?r=pad", }, { "link": "https://i.vimeocdn.com/video/686815740_295x166.jpg?r=pad", }] }
def get_mock_data(self, optional=True): mock_data = { 'name': '[Name]', 'disable_notification_url': None, 'roles': [{ 'total': faker.pyint(), 'name': '[Role Name]', 'opportunities': [{ 'title': '[Title]', 'entity': 'Client Name', 'description': '[Description]', 'url': '/{}'.format(faker.uri_path()), 'deadline': '14 november 2019' } for _ in range(3)] } for _ in range(2)], 'total': faker.pyint(), 'other_total': faker.pyint(), 'public_url': '/{}'.format(faker.uri_path()), } return mock_data
class FakeOpportunityFactory(factory.django.DjangoModelFactory): title = factory.LazyAttribute(lambda x: faker.text(max_nb_chars=20)) description = factory.LazyAttribute(lambda x: faker.text()) location = factory.LazyAttribute( lambda x: '{}, {}'.format(faker.city(), faker.country())) exo_role = factory.LazyAttribute(lambda o: ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_COACH)) certification_required = factory.LazyAttribute( lambda o: CertificationRole.objects.get( code=settings.EXO_ROLE_CODE_CERTIFICATION_SPRINT_COACH)) start_date = factory.fuzzy.FuzzyDate(datetime.date.today()) deadline_date = factory.fuzzy.FuzzyDate(datetime.date.today()) duration_unity = factory.fuzzy.FuzzyChoice( dict(settings.OPPORTUNITIES_DURATION_UNITY_CHOICES).keys(), ) duration_value = faker.random_digit_not_null() entity = factory.LazyAttribute(lambda x: faker.company()) keywords = [] languages = [] budget = factory.LazyAttribute(lambda x: faker.pyint()) budget_currency = settings.OPPORTUNITIES_CH_CURRENCY_DOLLAR virtual_budget = factory.LazyAttribute(lambda x: faker.pyint()) virtual_budget_currency = settings.OPPORTUNITIES_CH_CURRENCY_EXOS class Meta: model = Opportunity @classmethod def _create(cls, model_class, *args, **kwargs): """Override the default ``_create`` with our custom call.""" manager = cls._get_manager(model_class) if not kwargs.get('user_from'): raise Exception('User is required') # The default would use ``manager.create(*args, **kwargs)`` budgets = [] if kwargs.get('budget'): budgets.append({ 'budget': kwargs.get('budget'), 'currency': kwargs.get('budget_currency') }) if kwargs.get('virtual_budget'): budgets.append({ 'budget': kwargs.get('virtual_budget').__str__(), 'currency': kwargs.get('virtual_budget_currency') }) kwargs['budgets'] = budgets return manager.create_opportunity(*args, **kwargs)
def email(obj): name = '' if not obj.get_full_name(): name = 'anonymous' else: name = obj.get_full_name().replace(' ', '.').lower() return '{}.{}@example.com'.format(name, faker.pyint())
def get_data(self): return { 'name': faker.word(), 'index': faker.pyint(), 'start': timezone.now().strftime('%Y-%m-%d'), 'end': (timedelta(days=2) + timezone.now()).strftime('%Y-%m-%d'), }
def get_mock_data(self, optional=True): mock_data = { 'name': '[Name]', 'disable_notification_url': None, 'roles': [{ 'total': faker.pyint(), 'name': '[Role Name]', } for _ in range(4)], 'total': faker.pyint(), 'public_url': '/{}'.format(faker.uri_path()), } return mock_data
def test_edit_project(self, mock_request, mock_email): # PREPARE DATA self.project.refresh_from_db() self.init_mock(mock_request) coach_role = self.project.project_roles.get( code=settings.EXO_ROLE_CODE_SPRINT_COACH) user = self.get_user() request_mock_account.add_mock(user, is_consultant=False, is_superuser=False) models.UserProjectRole.objects.create(project_role=coach_role, user=user) self.project.set_status(self.project.created_by, settings.PROJECT_CH_STATUS_WAITING) mock_email.reset_mock() url = reverse('api:project-detail', kwargs={'pk': self.project.pk}) # DO ACTION self.setup_credentials(self.super_user) data = { 'name': faker.word(), 'customer': faker.company(), 'location': '{}, {}'.format(faker.city(), faker.country()), 'place_id': faker.pyint(), 'start': (self.project.start + timedelta(days=5)).strftime('%Y-%m-%d'), } response = self.client.put(url, data=data) # ASSERTS self.assertTrue(status.is_success(response.status_code)) self.assertTrue(mock_email.called) self.assertEqual(mock_email.call_count, 2)
def get_data(self): return { 'order': faker.pyint(), 'level': settings.PROJECT_CH_ROLE_LEVEL_ADMIN, 'default': True, 'role': 'Advisor', 'code': settings.EXO_ROLE_CODE_FASTRACK_TEAM_LEADER, 'exoRole': settings.EXO_ROLE_CODE_FASTRACK_TEAM_LEADER }
def get_mock_data(self, optional=True): mock_data = { 'name': '[Name]', 'disable_notification_url': None, 'conversations': [ { 'total': faker.pyint(), 'title': random.choice([ 'messages from [User Name]', 'messages related to opportunity [opportunity name]', 'messages related to the project [project name]']), 'user_from_full_name': '[User Name]', 'message': faker.text(), 'url': '/{}'.format(faker.uri_path()), } for _ in range(5) ], 'total': faker.pyint(), 'public_url': '/{}'.format(faker.uri_path()), } return mock_data
class FakeResourceFactory(django.DjangoModelFactory): class Meta: model = Resource status = settings.RESOURCE_CH_STATUS_DRAFT type = settings.RESOURCE_CH_TYPE_VIDEO_VIMEO name = factory.Sequence(lambda x: faker.word()) description = factory.Sequence(lambda x: faker.text()) link = factory.Sequence(lambda x: 'https://vimeo.com/' + str(faker.pyint())) url = factory.Sequence(lambda x: faker.url()) thumbnail = factory.Sequence(lambda x: faker.uri()) duration = factory.Sequence(lambda x: faker.random_digit()) sections = [settings.RESOURCE_CH_SECTION_SPRINT_AUTOMATED] projects = '' extra_data = ''
def test_edit_service_sprint_from_django_form(self, mock): # PREPARE DATA sprint = FakeSprintAutomatedFactory() new_date = '2013-01-01 10:00:00' sprint_form = SprintSimpleForm(instance=sprint) data = sprint_form.initial data['start'] = new_date data['agenda'] = '' data['location'] = faker.city() data['timezone'] = faker.timezone() data['place_id'] = faker.pyint() url = reverse('project:project:dashboard', kwargs={'project_id': sprint.id}) self.client.login(username=self.super_user.username, password='******') # DO ACTION response = self.client.post(url, data=data, format='json') # ASSERTS self.assertTrue(status.is_success(response.status_code))
class VideoUploadFactory(factory.DictFactory): url = factory.Sequence(lambda x: faker.url()) name = factory.Sequence(lambda x: faker.word() + str(faker.pyint())) description = factory.Sequence(lambda x: faker.text()) sections = [settings.RESOURCE_CH_SECTION_SPRINT_AUTOMATED] tags = []
def email(obj): name = faker.name() name = name.replace(' ', '').lower() return '{}.{}@example.com'.format(name, faker.pyint())
class TagFactory(factory.DictFactory): name = factory.Sequence(lambda x: faker.word() + str(faker.pyint())) tag = factory.Sequence(lambda x: faker.word()) canonical = factory.Sequence(lambda x: faker.word())
class CategoryFactory(factory.DictFactory): name = factory.Sequence(lambda x: faker.word() + str(faker.pyint())) subcategories = SubCategory.create_batch(size=4)