Exemplo n.º 1
0
    def setUp(self):
        self.client = Client()
        self.user = self.client.login_as()
        self.avatar = any_model(Avatar, owner=self.user, today=0, hours_spent=0, health=50)
        self.company = any_model(Company, owner=self.avatar)

        self.company_url = reverse("company_index", kwargs={"avatar_pk": self.avatar.pk, "company_pk": self.company.pk})
 def test_short_generic_fk_creation(self):
     content_object = any_model(RelatedContentModel)
     related_object = any_model(ModelWithGenericRelation,
                                content_object=content_object)
     self.assertEqual(related_object.content_object, content_object)
     self.assertEqual(related_object.content_type, ContentType.objects.get_for_model(RelatedContentModel))
     self.assertEqual(related_object.object_id, content_object.id)
Exemplo n.º 3
0
    def test_fk_referencing_self(self):
        self_referencing = any_model(SelfReferencingModel)
        self.assertTrue(self_referencing.parent is None)

        root = any_model(SelfReferencingModel)
        child = any_model(SelfReferencingModel, parent=root)
        self.assertEqual(type(child.parent), SelfReferencingModel)
Exemplo n.º 4
0
def users_in_database(step):
    for user_dict in step.hashes:
        user = any_model(User, is_active=True, **user_dict)
        user.set_password('123')
        user.save()

        any_model(Profile, avatar=None, user=user)
Exemplo n.º 5
0
    def setUp(self):
        """
        Test's init sequence.

        - saves test data directly into model needed for tests
            Creates random timesheet
        """
        # Every test needs a client.
        self.client = Client()
        self.client, self.response = client_login(self.client, callback=reverse('tms_timesheets'))
        self.datetime = datetime.datetime.now
        self.user = new_test_user()
        self.job_model = any_model(Job, is_active=True)
        try:
            self.employee = any_model(Employee, user = self.user)
        except:
            #employee with this user already exists
            self.employee = Employee.objects.get(user=self.user)
        self.timesheet1 = any_model(Timesheet,
                                    employee=self.employee,
                                    is_submitted=False,
                                    is_billed=False,
                                    comment='Django_tests comment for timesheet model1')
        self.expense1 = any_model(Expense,
                                    comment='Django_tests comment for expense model1')
Exemplo n.º 6
0
 def setUp(self):
     self.client = APIClient()
     self.user = any_model(User, name='testuser', password='******')
     kwargs = {
         'info': {},
         'type': 'country',
     }
     [any_model(Address, id=i, **kwargs) for i in range(0, 10)]
Exemplo n.º 7
0
    def test_work_with_enough_company_money_succeed(self):
        CompanyWorker.objects.create(worker=self.avatar, company=self.company, salary_per_hour=1)
        any_model(InventoryItem, owner=self.avatar, quantity=10, item_type=INVENTORY_TYPE.DUBLONS)

        initial_health = self.avatar.health
        self.client.post(self.company_url, {"action": "work"})
        new_health = Avatar.objects.get(pk=self.avatar.pk).health
        self.assertTrue(initial_health > new_health)
Exemplo n.º 8
0
 def setUp(self):
     """
     Setting up model instances. Using factory (django_any) instead of fixtures (couse fixtures are evil)
     """
     self.currency1 = any_model(Currency)    
     self.currency2 = any_model(Currency)
     self.account1 = any_model(Account, amount=25, currency=self.currency1)
     self.account2 = any_model(Account, amount=0, currency=self.currency1)
     self.account3 = any_model(Account, amount=1000)
Exemplo n.º 9
0
 def test_short_generic_fk_creation(self):
     content_object = any_model(RelatedContentModel)
     related_object = any_model(ModelWithGenericRelation,
                                content_object=content_object)
     self.assertEqual(related_object.content_object, content_object)
     self.assertEqual(
         related_object.content_type,
         ContentType.objects.get_for_model(RelatedContentModel))
     self.assertEqual(related_object.object_id, content_object.id)
Exemplo n.º 10
0
 def setUp(self):
     """
     Initialization. Creating model instances for tests
     """
     self.root_room1 = any_model(Room, parent=None,
         title="root room 1 title", description = "root room 1 description")
     self.root_room2 = any_model(Room, parent=None, title="root room 2 title")
     self.child_room_1_1 = any_model(Room, parent=self.root_room1, title="child room 1 1 title")
     self.child_room_2_1 = any_model(Room, parent=self.root_room2, title="child room 2 1 title")
Exemplo n.º 11
0
    def test_qobject_multiple_objects_returned(self):
        """If Q() lookup return multiple objects, we select
        random one.

        """
        # Create additional related instance
        any_model(QObjectRelated, flag=False)

        result = any_model(RelatedToQObject, related=Q(flag=False))
        self.assertIn(result.related, list(QObjectRelated.objects.all()))
Exemplo n.º 12
0
    def test_search_form_manager(self):
        u = any_model(User)

        s1 = any_model(SearchForm, owner=u, public=False, name='A')
        s2 = any_model(SearchForm, owner=u, public=True, name='B')

        res = SearchForm.objects.get_for_user(AnonymousUser())
        self.assertEquals(list(res), [s2])

        res = SearchForm.objects.get_for_user(u)
        self.assertEquals(list(res), [s1, s2])
Exemplo n.º 13
0
 def setUp(self):
     self.client = Client()
     self.user = self.client.login_as()
     self.avatar = any_model(
         Avatar, owner=self.user,
         today=0, hours_spent=0,
         health=50)
     self.market = any_model(
         Market, buy_item_type=INVENTORY_TYPE.DUBLONS,
         sell_item_type=INVENTORY_TYPE.BANANAS)
     
     self.market_url = reverse('market_index', kwargs={'avatar_pk':self.avatar.pk, 'market_pk':self.market.pk})
Exemplo n.º 14
0
    def setUp(self):

        self.user1 = any_model(User, is_active=True, username=self.USER_NAME1)
        self.user2 = any_model(User, is_active=True, username=self.USER_NAME2)

        self.user1.set_password(self.USER_PASS1)
        self.user2.set_password(self.USER_PASS2)

        self.user1.save()
        self.user2.save()

        self.album_public = any_model(Album, id=1, access=Album.ACCESS_PUBLIC, kind=Album.KIND_CUSTOM)
        self.album_private1 = any_model(Album, id=2, access=Album.ACCESS_PRIVATE, kind=Album.KIND_CUSTOM, user=self.user1)
        self.album_private2 = any_model(Album, id=3, access=Album.ACCESS_PRIVATE, kind=Album.KIND_CUSTOM, user=self.user2)
Exemplo n.º 15
0
    def test_fk_relation_autocreate(self):
        result = any_model(BaseModel)

        self.assertEqual(type(result), BaseModel)

        self.assertEqual(type(result.related), RelatedModel)
        self.assertTrue(result.related.name is not None)
Exemplo n.º 16
0
    def test_oneto_one_autocreate(self):
        result = any_model(ModelWithOneToOneField)
        self.assertEqual(type(result), ModelWithOneToOneField)
        self.assertTrue(result.name is not None)

        self.assertEqual(type(result.related), OneToOneRelated)
        self.assertTrue(result.related.name is not None)
Exemplo n.º 17
0
def any_user(password=None, permissions=[], groups=[], **kwargs):
    """
    Shortcut for creating Users

    Permissions could be a list of permission names

    If not specified, creates active, non superuser 
    and non staff user
    """

    is_active = kwargs.pop('is_active', True)
    is_superuser = kwargs.pop('is_superuser', False)
    is_staff = kwargs.pop('is_staff', False)

    user = any_model(User,
                     is_active=is_active,
                     is_superuser=is_superuser,
                     is_staff=is_staff,
                     **kwargs)

    for group_name in groups:
        group = Group.objects.get(name=group_name)
        user.groups.add(group)

    for permission_name in permissions:
        app_label, codename = permission_name.split('.')
        permission = Permission.objects.get(content_type__app_label=app_label,
                                            codename=codename)
        user.user_permissions.add(permission)

    if password:
        user.set_password(password)

    user.save()
    return user
Exemplo n.º 18
0
 def _create_account(self):
     acc = any_model(
         Account,
         user__is_active=True,
         user__password=make_password('qwerty'),
     )
     return acc
Exemplo n.º 19
0
    def test_fk_relation_autocreate(self):
        result = any_model(BaseModel)

        self.assertEqual(type(result), BaseModel)

        self.assertEqual(type(result.related), RelatedModel)
        self.assertTrue(result.related.name is not None)
    def test_oneto_one_autocreate(self):
        result = any_model(ModelWithOneToOneField)
        self.assertEqual(type(result), ModelWithOneToOneField)
        self.assertTrue(result.name is not None)

        self.assertEqual(type(result.related), OneToOneRelated)
        self.assertTrue(result.related.name is not None)
Exemplo n.º 21
0
def any_user(password=None, permissions=[], groups=[], **kwargs):
    """
    Shortcut for creating Users

    Permissions could be a list of permission names

    If not specified, creates active, non superuser 
    and non staff user
    """

    is_active = kwargs.pop('is_active', True)
    is_superuser = kwargs.pop('is_superuser', False)
    is_staff = kwargs.pop('is_staff', False)

    user = any_model(User, is_active = is_active, is_superuser = is_superuser,
                     is_staff = is_staff, **kwargs)

    for group_name in groups :
        group = Group.objects.get(name=group_name)
        user.groups.add(group)

    for permission_name in permissions:
        app_label, codename = permission_name.split('.')
        permission = Permission.objects.get(
            content_type__app_label=app_label,
            codename=codename)
        user.user_permissions.add(permission)

    if password:
        user.set_password(password)
    
    user.save()
    return user
Exemplo n.º 22
0
    def setUp(self):

        self.client.session.clear()

        self.user1 = any_model(User, is_active=True, username=self.USER_NAME1)
        self.user1.set_password(self.USER_PASS1)
        self.user1.save()
Exemplo n.º 23
0
    def setUp(self):
        self.user = any_model(User, is_active=True)
        self.user.set_password('test')
        self.user.save()

        result_login = self.client.login(username=self.user.username, password='******')
        self.assertTrue(result_login)
Exemplo n.º 24
0
    def test_Root(self):
        """
        Tests that 1 + 1 always equalsss 2.
        """
        #print self
        #print dir(self)
        #print self.__class__.__doc__
        #print dir(self.test_Root.__str__)
        #print self.__call__.__doc__
        #print dir(self.test_Root.__func__)
        print self.test_Root.__doc__
        print self.test_Root.__format__
        print dir(self.test_Root)

        #print self.test_Root.__name__

        user = any_model(Root)


        self.assertEqual(1 + 1, 2)


# test all pages
# when debug off 404
# only get one result for a page
#




# ============================================================================ #
# EOF                                                                          #
# ============================================================================ #
Exemplo n.º 25
0
    def test_detail(self):
        album = any_model(Album, user__is_active=True)
        photo = Photo.objects.create(user=album.user, album=album)
        response = self.client.get(reverse('photos-photo', args=[album.id, photo.id]))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context['photo'], photo)
Exemplo n.º 26
0
    def test_process_partial_bids_success(self):
        bid1 = any_model(Bid, direction=Bid.TYPE.SELL, market=self.market, quantity=5, rate=2)
        any_model(InventoryItem, owner=bid1.owner, quantity=bid1.quantity, item_type=self.market.sell_item_type)

        bid2 = any_model(Bid, direction=Bid.TYPE.SELL, market=self.market, quantity=5, rate=2)
        any_model(InventoryItem, owner=bid2.owner, quantity=bid2.quantity, item_type=self.market.sell_item_type)

        bid3 = any_model(Bid, direction=Bid.TYPE.BUY, market=self.market, quantity=10, rate=2)
        any_model(InventoryItem, owner=bid3.owner, quantity=bid3.quantity*bid3.rate, item_type=self.market.buy_item_type)

        process_market(self.market.id)

        self.assertEqual(0, Bid.objects.count())
Exemplo n.º 27
0
    def test_model_creation_succeed(self):
        result = any_model(SimpleModel)
        
        self.assertEqual(type(result), SimpleModel)

        for field in result._meta.fields:
            value = getattr(result, field.name)
        self.assertTrue(value is not None, "%s is uninitialized" % field.name)
Exemplo n.º 28
0
 def setUp(self):
     self.client = Client()
     self.user = self.client.login_as()
     self.avatar = any_model(
         Avatar, owner=self.user,
         today=0, hours_spent=0,
         health=50)
     self.avatar_url = reverse('avatar_index', kwargs={'avatar_pk':self.avatar.pk})
Exemplo n.º 29
0
    def test_subject_unicode(self):
        subj = any_model(TestSubject,name=u'Математика')
        self.assertEqual(subj.__unicode__(),u'Математика')


#class AbitRequestTest(TestCase):
#    def setUp(self):
#        self.abitreq = any_model()
Exemplo n.º 30
0
    def test_created_model_with_custom_field(self):
        model = any_model(ModelWithCustomField)

        self.assertEqual(type(model), ModelWithCustomField)
        self.assertEqual(len(model._meta.fields), len(ModelWithCustomField._meta.local_fields))

        self.assertTrue(model.slug)
        self.assertTrue(isinstance(model.slug, basestring))
Exemplo n.º 31
0
 def test_unconfirmed_listeners(self):
     self.setup_unit_and_followers(confirmed=False)
     dispatch = any_model(models.Dispatch)
     dispatch.units.add(self.unit)
     self.mox.ReplayAll()
     dispatch.notify_listeners()
     self.mox.VerifyAll()
     self.assertEqual(len(mail.outbox), 0)
Exemplo n.º 32
0
    def test_get_context_data(self):
        self.request.POST = {}
        
        self.request.POST['json'] = None
        self.assertEquals(
            self.msp.get_context_data(), 
            dict(result=unicode(ERR_NO_FORM_DATA)))
        
        self.request.POST['json'] = "wcale, nie, json"
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=unicode(ERR_PARSING_DATA)))
        
        self.request.POST['json'] = '[{"field": "foo", "bad": "field"}]'
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=unicode(ERR_LOADING_DATA)))
        
        self.request.POST['json'] = \
            '{"form_data": [{"field": "foo", "operation": "' \
            + unicode(EQUAL) \
            + '", "value": "foo"}]}'
        self.request.POST['name'] = ''
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=unicode(ERR_FORM_NAME)))

        sf = any_model(SearchForm, name='foo')
        self.request.POST['name'] = 'foo'
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=OVERWRITE_PROMPT))

        self.request.POST['overwrite'] = 'true'
        self.request.user = any_model(User)
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=SAVED, pk=1))

        self.assertEquals(SearchForm.objects.all().count(), 1)
        self.assertEquals(SearchForm.objects.all()[0].public, False)

        self.request.POST['public'] = 'true'
        self.msp.get_context_data()
        self.assertEquals(SearchForm.objects.all()[0].public, True)
    def test_created_model_with_custom_field(self):
        model = any_model(ModelWithCustomField)

        self.assertEqual(type(model), ModelWithCustomField)
        self.assertEqual(len(model._meta.fields),
                         len(ModelWithCustomField._meta.local_fields))

        self.assertTrue(model.slug)
        self.assertTrue(isinstance(model.slug, basestring))
Exemplo n.º 34
0
 def test_create(self):
     obj = any_model(Account)
     count = ActionNote.objects.filter(
         app='account.models',
         model='Account',
         object_id=obj.id,
         note='created',
     ).count()
     self.assertTrue(count)
Exemplo n.º 35
0
    def test_list(self):
        album = any_model(Album, user__is_active=True)
        Photo.objects.create(user=album.user, album=album)
        Photo.objects.create(user=album.user, album=album)
        response = self.client.get(reverse('photos-photo-list', args=[album.id]))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context['album'], album)
        self.assertEqual(len(response.context['photo_list']), 2)
Exemplo n.º 36
0
 def test_dispatch_msg(self):
     dispatch = any_model(
         models.Dispatch, location='test_location',
         call_type_desc='test_call_type_desc')
     dispatch.tf = 'test_tf'  # not valid at db, but possible for instance
     dispatch.units.create(id='test_unit')
     self.assertEqual(
         utils.dispatch_msg(dispatch),
         'test_call_type_desc\ntest_location\nUnit: test_unit\n'
         'http://tfdd.co/gm/test_tf/')
Exemplo n.º 37
0
    def setUp(self):
        """
        Crating a test environment with logged in
        client and at least one timesheet model
        and one Expense and Job models.
        """
        self.client = Client()
        self.client, self.response = client_login(self.client, callback=reverse('tms_timesheets'))
        self.datetime = datetime.datetime.now
        self.user = new_test_user()
        self.job_model = any_model(Job, is_active=True)
        try:
            self.employee = any_model(Employee, user = self.user)
        except:
            #employee with this user already exists
            self.employee = Employee.objects.get(user=self.user)
        self.timesheet1 = any_model(Timesheet,
                                    employee=self.employee,
                                    is_submitted=False,
                                    is_billed=False,
                                    start_time='2011-08-29 20:57:34.848614',
                                    end_time='2011-08-29 22:57:34.848614',
                                    comment='Django_tests comment for timesheet model1')
        self.expense1 = any_model(Expense,
                                  expense_date='2011-09-10',
                                  claim_date='2011-09-10',
                                  is_receipted=True,
                                  is_submitted=False,
                                  is_billed=False,
                                  is_taxable=True,
                                  comment='Django_tests comment for expense model1')
        self.reports_list = reporting.all_reports()

        self.reporting_post_data = { 'consultant': '',
                      'date_end_datepicker' : '',
                      'date_end_day': '13',
                      'date_end_yearmonth': '2011-9',
                      'date_start_datepicker': '',
                      'date_start_day': '16',
                      'date_start_yearmonth': '2011-8',
                      'generate': 'Generate',
                      }
    def test_model_creation_succeed(self):
        result = any_model(SimpleModel)

        self.assertEqual(type(result), SimpleModel)
        self.assertEqual(len(result._meta.fields),
                         len(SimpleModel._meta.local_fields))

        for field, original_field in zip(result._meta.fields,
                                         SimpleModel._meta.local_fields):
            value = getattr(result, field.name)
            if field.name != 'null_boolead_field':
                self.assertTrue(value is not None,
                                "%s is uninitialized" % field.name)
            self.assertTrue(isinstance(field, original_field.__class__),
                            "%s has correct field type" % field.name)
Exemplo n.º 39
0
 def test_notify_listeners(self):
     self.setup_unit_and_followers()
     dispatch = any_model(models.Dispatch)
     dispatch.units.add(self.unit)
     models.send_msg('phone_follower #', None, dispatch=dispatch)
     models.send_msg('both_follower #', None, dispatch=dispatch)
     self.mox.ReplayAll()
     dispatch.notify_listeners()
     self.mox.VerifyAll()
     self.assertEqual(len(mail.outbox), 2)
     m0, m1 = mail.outbox
     # can't guarantee order due to use of set
     self.assertTrue(
         m0.to == ['*****@*****.**'] and m1.to == ['*****@*****.**'] or
         m1.to == ['*****@*****.**'] and m0.to == ['*****@*****.**'])
 def _test_reverse_relation_spec_succeed(self):
     related = any_model(OneToOneRelated,
                         modelwithonetoonefield__name='test')
     self.assertEqual(related.modelwithonetoonefield.name, 'test')
Exemplo n.º 41
0
 def test_qobject_specification(self):
     result = any_model(RelatedToQObject, related=Q(pk=self.related.pk))
     self.assertEqual(self.related, result.related)
Exemplo n.º 42
0
 def _prepare_models(self):
     for x in range(0, 10):
         r = any_model(Related)
         m = any_model(M2M)
         any_model(Search, related=r, m2m=m)
Exemplo n.º 43
0
 def test_del(self):
     todo = any_model(ToDo)
     id = todo.id
     todo.delete()
     self.assertEquals(0, ToDo.objects.filter(pk=id).count())
 def _test_partial_specification(self):
     result = any_model(SimpleModel, char_field='test')
     self.assertEqual(result.char_field, 'test')
Exemplo n.º 45
0
 def setUp(self):
     self.modlog = ModelLog.objects.filter().delete()
     self.my_info = any_model(MyInfo, my_photo='')
Exemplo n.º 46
0
 def test_created_model_with_filefield_string_upload_to(self):
     model = any_model(ModelUploadToString)
     self.assertEqual(model.file_field, 'sample_file.txt')
Exemplo n.º 47
0
    def test_do_done(self):
        todo = any_model(ToDo)
        todo.do_done()

        self.assertEquals(True, ToDo.objects.get(pk=todo.id).done)
Exemplo n.º 48
0
 def setUp(self):
     self.related = any_model(QObjectRelated, flag=False)
 def test_partial_specification_succeed(self):
     result = any_model(ModelWithOneToOneField, related__name='test')
     self.assertEqual(result.related.name, 'test')
Exemplo n.º 50
0
 def test_created_model_with_filefield_callable_upload_to(self):
     model = any_model(ModelWithFileFieldUploadToCallable)
     self.assertEqual(model.file_field, 'sample_file.txt')
 def test_related_onetoone_not_created_by_default(self):
     simple_model = any_model(OneToOneRelated)
     self.assertRaises(ModelWithOneToOneField.DoesNotExist,
                       lambda: simple_model.modelwithonetoonefield)
Exemplo n.º 52
0
 def setUp(self):
     self.related = any_model(QObjectRelated)
Exemplo n.º 53
0
 def test_created_value_pass_validation(self):
     result = any_model(ModelWithValidatedField)
     validate_even(result.even_field)
 def test_related_specification_succeed(self):
     related = any_model(OneToOneRelated)
     result = any_model(ModelWithOneToOneField, related=related)
     self.assertEqual(related, result.related)
Exemplo n.º 55
0
 def test_raw_user_creation(self):
     result = any_model(User)
     self.assertEqual(type(result), User)
Exemplo n.º 56
0
 def test_nested_models_specification(self):
     result = any_model(BaseModel, related__name='test')
     self.assertEqual(result.related.name, 'test')