def test_exists_vote_when_user_vote_only_another_activity_should_return_false(
        user1, activity1, activity2):
    autofixture.create_one('vote.Vote', {
        'user_id': user1.id,
        'object_id': activity2.id
    })
    assert not filters.exists_vote(user1, activity1)
Example #2
0
 def setUp(self):
     self.title = "title"
     autofixture.create_one(Chart,
                            field_values={
                                'title': self.title,
                                'slug': self.title
                            })
Example #3
0
 def setUp(self):
     if self.fk_models:
         for fk_model in self.fk_models:
             autofixture.create_one(fk_model)
     self.example_generate = autofixture.create_one(self.str_model, field_values=self.example)
     self.client.login(username=self.admin.username, password='******')
     self.api_client.login(username=self.admin.username, password='******')
Example #4
0
def test_prefetch_through_gfk():
    photo = autofixture.create_one(Photo)
    like = Like.objects.create(content_object=photo)

    comment = Comment.objects.create(content_object=photo)
    user = autofixture.create_one(User)

    photo.people_on_photo.add(user)
    photo.save()

    connection.queries = []
    with verbose_cursor() as queries:
        objects = list(Like.deep
                       .prefetch_related('content_object__people_on_photo',
                                         'content_object__comments'))
        fields = ['people_on_photo', 'comments']
        fetched = []
        for o in objects:
            fetched.append(o)
            fetched.append(o.content_object)
            for f in fields:
                if hasattr(o.content_object, f):
                    fetched.extend(list(getattr(o.content_object, f).all()))
        expected_objects = sorted([like, photo, comment, user])
        actual_objects = sorted(fetched)

        assert expected_objects == actual_objects

        assert len(queries) == len([Like, Photo, Comment, User])
Example #5
0
 def setUp(self):
     if self.fk_models:
         for fk_model in self.fk_models:
             autofixture.create_one(fk_model)
     self.example_generate = autofixture.create_one(
         self.str_model, field_values=self.example)
     self.client.login(username=self.admin.username, password='******')
     self.api_client.login(username=self.admin.username, password='******')
Example #6
0
 def setUpClass(cls):
     cls.admin = autofixture.create_one(
         'auth.User', field_values={
             'is_superuser': True, 'is_staff': True})
     cls.user = autofixture.create_one(
         'auth.User', field_values={
             'is_superuser': False, 'is_staff': False})
     cls.event = autofixture.create_one('manager.Event')
Example #7
0
    def post_process_instance(self, instance, commit):
        create_one(Filter, overwrite_defaults=True, field_values={
            'analysis_framework': instance.analysis_framework,
            'widget_key': instance.key,
        })

        create_one(Exportable, overwrite_defaults=True, field_values={
            'analysis_framework': instance.analysis_framework,
            'widget_key': instance.key,
        })
Example #8
0
 def test_nest_level(self):
     u = autofixture.create_one('auth.User')
     c1 = autofixture.create_one('comments.Comment', field_values={
         'user': u
     })
     c2 = autofixture.create_one('comments.Comment', field_values={
         'parent': c1,
         'user': u
     })
     self.assertEqual(c1.nest_level, 0)
     self.assertEqual(c2.nest_level, 1)
Example #9
0
def attendee_from_event_user2(event_user2, event2):
    yield autofixture.create_one(
        'manager.Attendee', {
            'event_user': event_user2,
            'event': event2,
            'email_token': generate_ticket_code()
        })
Example #10
0
 def test_seen_before(self):
     report_item = autofixture.create_one(ReportItem,
                                          field_values={
                                              'one_hour_occurrences': 1,
                                              'report': self.report
                                          })
     self.assertTrue(report_item.is_seen_before())
Example #11
0
def test_single_seen():
    """If relation is single and if traversed more than once - it fails."""
    simple_model = autofixture.create_one(SimpleModel)
    autofixture.create(FKModel, 3, field_values={'fk': simple_model})

    queryset = FKModel.deep.prefetch_related('fk', 'fk__fks__fk')
    list(queryset)
Example #12
0
 def test_overwrite_attributes(self):
     autofixture.register(SimpleModel, SimpleAutoFixture)
     for obj in autofixture.create(SimpleModel,
                                   10,
                                   field_values={'name': 'bar'}):
         self.assertEqual(obj.name, 'bar')
     obj = autofixture.create_one(SimpleModel, field_values={'name': 'bar'})
     self.assertEqual(obj.name, 'bar')
Example #13
0
def admin():
    yield autofixture.create_one(
        'auth.User', {
            'username': ADMIN_USERNAME,
            'password': ADMIN_PASSWORD,
            'is_superuser': True,
            'is_staff': True
        })
Example #14
0
def user2():
    yield autofixture.create_one(
        'auth.User', {
            'username': USER_USERNAME_2,
            'password': USER_PASSWORD_2,
            'is_superuser': False,
            'is_staff': False
        })
Example #15
0
 def test_overwrite_attributes(self):
     autofixture.register(SimpleModel, SimpleAutoFixture)
     for obj in autofixture.create(
             SimpleModel, 10, field_values={'name': 'bar'}):
         self.assertEqual(obj.name, 'bar')
     obj = autofixture.create_one(
         SimpleModel, field_values={'name': 'bar'})
     self.assertEqual(obj.name, 'bar')
Example #16
0
    def test_encryption_with_private_key(self):
        os.environ['PRIVATE_ENCRYPT_KEY'] = self.encrypt_private_key
        created_user = create_one(AnonymousUser, commit=False)
        created_user.save()
        EncryptedUserData(name=self.user_name).save()

        self.assertEqual((EncryptedUserData.objects.first()).name,
                         self.user_name)
Example #17
0
    def handle(self, *args, **kwargs):
        p = Profiler()

        print('Creating users')
        users = autofixture.create('auth.User', 20, overwrite_defaults=True)
        user = users[0]
        p.authorise_with(user)

        print('Creating regions')
        autofixture.create('geo.Region',
                           5,
                           field_values={
                               'created_by': user,
                           })

        print('Creating projects')
        Project.objects.all().delete()
        autofixture.create_one('project.Project',
                               field_values={
                                   'created_by': user,
                               })
        project = Project.objects.first()
        if not ProjectMembership.objects.filter(project=project, member=user)\
                .exists():
            ProjectMembership.objects.create(project=project,
                                             member=user,
                                             role='admin')

        print('Creating leads')
        # create_many_leads(1000, user, project)
        autofixture.create('lead.Lead',
                           100,
                           field_values={
                               'created_by': user,
                           })

        print('Starting profiling')
        p.profile_get('/api/v1/leads/?'
                      'status=pending&'
                      'published_on__lt=2016-01-10&'
                      'assignee={0}&'
                      'search=lorem&'
                      'limit=100&'
                      ''.format(users[2].id))

        p.__del__()
Example #18
0
    def create_entry_with_data_series(self):
        sheet = autofixture.create_one(Sheet, generate_fk=True)
        series = [  # create some dummy values
            {
                'value': 'male', 'processed_value': 'male',
                'invalid': False, 'empty': False
            },
            {
                'value': 'female', 'processed_value': 'female',
                'invalid': False, 'empty': False
            },
            {
                'value': 'female', 'processed_value': 'female',
                'invalid': False, 'empty': False
            },
        ]
        cache_series = [
            {'value': 'male', 'count': 1},
            {'value': 'female', 'count': 2},
        ]
        health_stats = {
            'invalid': 10,
            'total': 20,
            'empty': 10,
        }

        field = autofixture.create_one(
            Field,
            field_values={
                'sheet': sheet,
                'title': 'Abrakadabra',
                'type': Field.STRING,
                'data': series,
                'cache': {
                    'status': Field.CACHE_SUCCESS,
                    'series': cache_series,
                    'health_stats': health_stats,
                    'images': [],
                },
            }
        )

        entry = self.create_entry(
            tabular_field=field, entry_type=Entry.TagType.DATA_SERIES
        )
        return entry, field
    def test_password_setting(self):
        user = autofixture.create_one(User, password='******')
        self.assertTrue(user.username)
        self.assertTrue(is_password_usable(user.password))
        self.assertTrue(user.check_password('known'))

        loaded_user = User.objects.get()
        self.assertEqual(loaded_user.password, user.password)
        self.assertTrue(loaded_user.check_password('known'))
    def test_password_setting(self):
        user = autofixture.create_one(User, password='******')
        self.assertTrue(user.username)
        self.assertTrue(is_password_usable(user.password))
        self.assertTrue(user.check_password('known'))

        loaded_user = User.objects.get()
        self.assertEqual(loaded_user.password, user.password)
        self.assertTrue(loaded_user.check_password('known'))
Example #21
0
 def setUpClass(cls):
     if cls is ApiTest:
         raise unittest.SkipTest("Skip ApiTest tests, it's a base test class")
     cls.client = Client()
     cls.api_client = APIClient()
     cls.admin = autofixture.create_one('auth.User', field_values={
         'is_active': True, 'is_superuser': True, 'is_staff': True})
     cls.admin.set_password('secret')
     cls.admin.save()
Example #22
0
 def test_not_seen_before(self):
     report_item = autofixture.create_one(ReportItem,
                                          field_values={
                                              'one_hour_occurrences': 0,
                                              'two_hour_occurrences': 0,
                                              'four_hour_occurrences': 0,
                                              'eight_hour_occurrences': 0,
                                              'sixteen_hour_occurrences': 0,
                                              'report': self.report
                                          })
     self.assertFalse(report_item.is_seen_before())
Example #23
0
File: tests.py Project: edavis/srl
 def test_category_to_outline(self):
     category = autofixture.create_one(Category, field_values={
         "owner": self.owner,
         "name": "category",
     })
     feeds = autofixture.create(Feed, 10, field_values={
         "owner": self.owner,
         "category": category,
     })
     category_element = etree.Element("outline", text=category.name)
     for feed in Feed.objects.all():
         category_element.append(feed.to_outline())
     self.elements_equal(category.to_outline(), category_element)
Example #24
0
 def setUpClass(cls):
     if cls is ApiTest:
         raise unittest.SkipTest(
             "Skip ApiTest tests, it's a base test class")
     cls.client = Client()
     cls.api_client = APIClient()
     cls.admin = autofixture.create_one('auth.User',
                                        field_values={
                                            'is_active': True,
                                            'is_superuser': True,
                                            'is_staff': True
                                        })
     cls.admin.set_password('secret')
     cls.admin.save()
Example #25
0
 def genetate_event_user(self):
     self.event_user = autofixture.create_one(
         'manager.EventUser', {'user': self.user, 'event': self.event})
Example #26
0
def installer2(event_user2):
    yield autofixture.create_one('manager.Installer', {'event_user': event_user2})
Example #27
0
def reviewer2(event_user2):
    yield autofixture.create_one('manager.Reviewer', {'event_user': event_user2})
Example #28
0
def get_event_date(datestring):
    date = datetime.strptime(datestring, "%d/%m/%Y")
    return autofixture.create_one('manager.EventDate', {'date': date.date()})
Example #29
0
 def test_create(self):
     autofixture.register(SimpleModel, SimpleAutoFixture)
     for obj in autofixture.create(SimpleModel, 10):
         self.assertEqual(obj.name, 'foo')
     obj = autofixture.create_one(SimpleModel)
     self.assertEqual(obj.name, 'foo')
Example #30
0
 def genetateEventUser(self):
     self.event_user = autofixture.create_one('manager.EventUser', {'user': self.user, 'event': self.event})
Example #31
0
def user2():
    yield autofixture.create_one('auth.User', {'is_superuser': False, 'is_staff': False})
Example #32
0
def event_user2(user2, event2):
    yield autofixture.create_one('manager.EventUser', {'user': user2, 'event': event2})
Example #33
0
def attendee_without_user2(event2):
    yield autofixture.create_one('manager.Attendee', {'event_user': None, 'event': event2})
Example #34
0
    "Beck",
    "Discovery",
    "Cherub",
    "Kanye West",
]

artist_images = [
    {"url": "https://i.scdn.co/image/237daa4588d473c1f1b18b6b3dfefc5598bf32c5", "width": 999, "height": 666},
    {"url": "https://i.scdn.co/image/e953b712c06d9cdd73f3f4c9a138d487165e8192", "width": 640, "height": 427},
    {"url": "https://i.scdn.co/image/a071c3c7c399ed7fdc0eb9d295cccf03346f5914", "width": 200, "height": 133},
    {"url": "https://i.scdn.co/image/f538200c33781098d164790a58867b7c7e77ba62", "width": 64, "height": 43},
]


for user in users:
    autofixture.create_one("users.User", field_values=user)

for venue in venues:
    autofixture.create_one("venues.Venue", field_values=venue)

for concert in concerts:
    autofixture.create_one("concerts.Concert", field_values=concert)

for genre in genres:
    autofixture.create_one("artists.Genre", field_values={"name": genre})

for artist in artists:
    res = autofixture.create_one(
        "artists.Artist",
        field_values={"name": artist, "spotify_id": autofixture.generators.ChoicesGenerator(values=spotify_ids)},
    )
Example #35
0
def attendee_from_event_user1(event_user1, event1):
    yield autofixture.create_one('manager.Attendee', {'event_user': event_user1, 'event': event1})
Example #36
0
    def handle(self, *attrs, **options):

        # for assigning Groups -
        #   0:No group
        #   1:StudentGroup
        #   2:FacultyGroup
        logger.debug(
            "Creating a Faculty Superuser with username: admin and password %s"
            % admin_md5)
        admin = autofixture.create_one('auth.User',
                                       field_values={
                                           'username': '******',
                                           'password': admin_md5,
                                           'groups': ['2'],
                                           'is_superuser': True,
                                       })

        adminDetail = autofixture.create_one('profiles.FacultyDetail',
                                             field_values={'user': admin})

        logger.debug("Creating 10 Notices")
        autofixture.create('notices.Notice',
                           count=10,
                           follow_fk=True,
                           field_values={'faculty': adminDetail})

        logger.debug(
            "Creating Student type User with username 'student' and password %s"
            % student_md5)
        student = autofixture.create_one('auth.User',
                                         field_values={
                                             'username': '******',
                                             'password': student_md5,
                                             'groups': ['1'],
                                             'is_superuser': True,
                                         })

        autofixture.create_one('profiles.StudentDetail',
                               field_values={'user': student})

        logger.debug("Creating 10 random Faculty Accounts")
        for _ in xrange(0, 10):
            test_faculty = autofixture.create_one('auth.User',
                                                  field_values={
                                                      'password': default_md5,
                                                      'groups': ['2']
                                                  })
            autofixture.create_one('profiles.FacultyDetail',
                                   field_values={'user': test_faculty})

        logger.debug("Creating 10 random Notices")
        autofixture.create('notices.Notice', count=10, follow_fk=True)

        logger.debug("Creating 10 random Student Accounts")
        for _ in range(0, 10):
            test_student = autofixture.create_one('auth.User',
                                                  field_values={
                                                      'password': default_md5,
                                                      'groups': ['1']
                                                  })
            autofixture.create_one('profiles.StudentDetail',
                                   field_values={'user': test_student})
Example #37
0
def collaborator1(event_user1):
    yield autofixture.create_one('manager.Collaborator', {'event_user': event_user1})
Example #38
0
def admin():
    yield autofixture.create_one('auth.User', {'is_superuser': True, 'is_staff': True})
Example #39
0
def organizer2(event_user2):
    yield autofixture.create_one('manager.Organizer', {'event_user': event_user2})
 def test_basic(self):
     user = autofixture.create_one(User)
     self.assertTrue(user.username)
     self.assertTrue(len(user.username) <= 30)
     self.assertFalse(is_password_usable(user.password))
Example #41
0
def room2(event2):
    yield autofixture.create_one('manager.Room', {'event': event2})
Example #42
0
 def setUpClass(cls):
     cls.admin = autofixture.create_one('auth.User', field_values={'is_superuser': True, 'is_staff': True})
     cls.user = autofixture.create_one('auth.User', field_values={'is_superuser': False, 'is_staff': False})
     cls.event = autofixture.create_one('manager.Event')
Example #43
0
def installation2(attendee_from_event_user2, installer2):
    yield autofixture.create_one('manager.Installation', {
        'attendee': attendee_from_event_user2,
        'installer': installer2.event_user
    })
Example #44
0
 def generateUserWithRol(self, model):
     self.user_with_rol = autofixture.create_one('manager.'+str(model.__name__), {'eventUser': self.event_user})
Example #45
0
def get_event_date(datestring):
    date = datetime.strptime(datestring, "%d/%m/%Y")
    return autofixture.create_one('manager.EventDate', {'date': date.date()})
Example #46
0
def event2():
    yield autofixture.create_one('manager.Event')
Example #47
0
def event_tag_2():
    yield autofixture.create_one('manager.EventTag', {
        'name': EVENT_TAG_NAME_2,
        'slug': EVENT_TAG_SLUG_2
    })
Example #48
0
def activity2(event2):
    yield autofixture.create_one('manager.Activity', {'event': event2}, generate_fk=True)
Example #49
0
def event1(event_tag_1):
    yield autofixture.create_one('manager.Event', {
        'name': EVENT_NAME_1,
        'slug': EVENT_SLUG_1,
        'tags': [event_tag_1]
    })
 def test_basic(self):
     user = autofixture.create_one(User)
     self.assertTrue(user.username)
     self.assertTrue(len(user.username) <= 30)
     self.assertFalse(is_password_usable(user.password))
Example #51
0
def event2(event_tag_2):
    yield autofixture.create_one('manager.Event', {
        'name': EVENT_NAME_2,
        'slug': EVENT_SLUG_2,
        'tags': [event_tag_2]
    })
Example #52
0
def event_user1(user1, event1):
    yield autofixture.create_one('manager.EventUser', {'user': user1, 'event': event1})
Example #53
0
def event_user1(user1, event1):
    yield autofixture.create_one('manager.EventUser', {
        'user': user1,
        'event': event1
    },
                                 generate_fk=True)
Example #54
0
 def generate_user_with_rol(self, model):
     self.user_with_rol = autofixture.create_one(
         'manager.' + str(model.__name__), {'event_user': self.event_user})
Example #55
0
def attendee_from_event_user2(event_user2, event2):
    yield autofixture.create_one('manager.Attendee', {'event_user': event_user2, 'event': event2})
Example #56
0
    def handle(self, *attrs, **options):

        # for assigning Groups -
        #   0:No group
        #   1:StudentGroup
        #   2:FacultyGroup
        logger.debug("Creating a Faculty Superuser with username: admin and password %s" % admin_md5)
        admin = autofixture.create_one('auth.User',
                                       field_values={'username': '******',
                                                     'password': admin_md5,
                                                     'groups': ['2'],
                                                     'is_superuser': True,
                                                     })

        adminDetail = autofixture.create_one('profiles.FacultyDetail',
                                             field_values={
                                                 'user': admin
                                             })

        logger.debug("Creating 10 Notices")
        autofixture.create('notices.Notice',
                           count=10,
                           follow_fk=True,
                           field_values={
                               'faculty': adminDetail
                           })

        logger.debug("Creating Student type User with username 'student' and password %s" % student_md5)
        student = autofixture.create_one('auth.User',
                                         field_values={
                                             'username': '******',
                                             'password': student_md5,
                                             'groups': ['1'],
                                             'is_superuser': True,
                                         })

        autofixture.create_one('profiles.StudentDetail', field_values={'user': student})

        logger.debug("Creating 10 random Faculty Accounts")
        for _ in xrange(0, 10):
            test_faculty = autofixture.create_one('auth.User',
                                                  field_values={
                                                      'password': default_md5,
                                                      'groups': ['2']
                                                  })
            autofixture.create_one('profiles.FacultyDetail', field_values={'user': test_faculty})

        logger.debug("Creating 10 random Notices")
        autofixture.create('notices.Notice', count=10, follow_fk=True)

        logger.debug("Creating 10 random Student Accounts")
        for _ in range(0, 10):
            test_student = autofixture.create_one('auth.User',
                                                  field_values={
                                                      'password': default_md5,
                                                      'groups': ['1']
                                                  })
            autofixture.create_one('profiles.StudentDetail', field_values={'user': test_student})
Example #57
0
    def test_commit_kwarg(self):
        instances = autofixture.create(BasicModel, 3, commit=False)
        self.assertEqual([i.pk for i in instances], [None] * 3)

        instance = autofixture.create_one(BasicModel, commit=False)
        self.assertEqual(instance.pk, None)