Example #1
0
    def test_period_invalid_return_invalid_request(self):
        request = APIRequestFactory().post('', data={'subscriber': '5512345678', 'period': 'INVALID.PERIOD'})
        response = self.view(request)

        self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
Example #2
0
 def setUp(self):
     self.request = APIRequestFactory()
Example #3
0
import io
import json
import zipfile

from django.core.management import CommandError
from django.utils.translation import ngettext, ugettext_lazy as _

from dateutil.relativedelta import relativedelta
from rest_framework.test import APIRequestFactory
from rest_framework.versioning import URLPathVersioning

from ..api import serializers
from ..models import BesluitType, Catalogus, InformatieObjectType

factory = APIRequestFactory()
REQUEST = factory.get("/")
setattr(REQUEST, "versioning_scheme", URLPathVersioning())
setattr(REQUEST, "version", "1")


def retrieve_iotypen(catalogus_pk, import_file_content):
    catalogus = Catalogus.objects.get(pk=catalogus_pk)
    catalogus_uuid = str(catalogus.uuid)

    import_file = io.BytesIO(import_file_content)

    iotypen = []
    with zipfile.ZipFile(import_file, "r") as zip_file:
        if f"InformatieObjectType.json" in zip_file.namelist():
            data = zip_file.read(f"InformatieObjectType.json").decode()
 def setUp(self):
     self.factory = APIRequestFactory()
     self.client = APIClient()
     self.user = UserFactory()
Example #5
0
 def setUp(self):
     self.request = APIRequestFactory().get('')
     force_authenticate(self.request, user=self.user)
     Experiment.objects.all().delete()
Example #6
0
    def setUp(self):

        self.view = PropertyList.as_view()
        self.factory = APIRequestFactory()

        self.user = User.objects.create_user(email='*****@*****.**',
                                             password='******')

        self.condo_path = '/v1/properties/?ptype=condo'
        self.house_path = '/v1/properties/?ptype=house'
        self.condo_data = {
            "location": {
                "address": "60 Brian Harrison",
                "city": "Toronto",
                "country": "Canada",
                "latitude": "43.773313",
                "longitude": "-79.258729",
                "postal_code": "M1P0B2",
                "province": "Ontario"
            },
            "n_bathrooms": 1,
            "n_bedrooms": 2,
            "price": 250000.0,
            "sqr_ftg": 3000.0,
            "unit_num": 11,
            "parking_spaces": 1,
            "parking_spaces": 0,
            "corporation_name": "Superstar Condos",
            "tax_records": [],
            "history": {
                "last_sold_price": 20000,
                "last_sold_date": "2011-08-14",
                "year_built": 2010
            },
            "features": [{
                "feature": "Oven"
            }, {
                "feature": "Pool"
            }],
            "images": []
        }

        self.house_data = {
            "location": {
                "address": "18 Bay Street",
                "city": "Toronto",
                "country": "Canada",
                "latitude": "43.773313",
                "longitude": "-79.258729",
                "postal_code": "M230B3",
                "province": "Ontario"
            },
            "n_bathrooms": 3,
            "n_bedrooms": 3,
            "price": 4500000.0,
            "sqr_ftg": 4200.0,
            "tax_records": [{
                "assessment": 4250000,
                "assessment_year": 2016
            }],
            "history": {
                "last_sold_price": 3200500,
                "last_sold_date": "2012-11-03",
                "year_built": 2007
            },
            "features": [],
            "images": []
        }
Example #7
0
    def setUp(self):

        self.view = OpenHouseDetail.as_view()
        self.factory = APIRequestFactory()

        # Test user.
        self.user = User.objects.create_user(email='*****@*****.**',
                                             password='******')
        self.user_a = User.objects.create(email='*****@*****.**',
                                          password='******')

        # Condo model owned by user 1.
        self.condo = Condo.objects.create(owner=self.user,
                                          n_bathrooms=1,
                                          n_bedrooms=2,
                                          price=250000,
                                          sqr_ftg=3000,
                                          unit_num=11,
                                          parking_spaces=1)
        Location.objects.create(kproperty=self.condo,
                                address='60 Brian Harrison',
                                city="Toronto",
                                country="Canada",
                                province='Ontario',
                                postal_code='M1P0B2',
                                latitude=43.773313,
                                longitude=-79.258729)
        TaxRecords.objects.create(kproperty=self.condo)
        Historical.objects.create(kproperty=self.condo,
                                  last_sold_price=2000000,
                                  last_sold_date='2011-08-14',
                                  year_built=2010)
        Features.objects.create(kproperty=self.condo, feature='Oven')
        Features.objects.create(kproperty=self.condo, feature='Pool')

        # House model owned by alt user.
        self.house = House.objects.create(owner=self.user_a,
                                          n_bathrooms=3,
                                          n_bedrooms=3,
                                          price=4500000,
                                          sqr_ftg=4200)
        Location.objects.create(kproperty=self.house,
                                address='18 Bay Street',
                                city='Toronto',
                                country='Canada',
                                province='Ontario',
                                postal_code='M230B3',
                                latitude=43.773313,
                                longitude=-79.258729)
        TaxRecords.objects.create(kproperty=self.house,
                                  assessment=4250000,
                                  assessment_year=2016)
        Historical.objects.create(kproperty=self.house,
                                  last_sold_price=3200500,
                                  last_sold_date='2012-11-03',
                                  year_built=2007)
        Features.objects.create(kproperty=self.house, feature='House Oven')
        Features.objects.create(kproperty=self.house, feature='Spa')

        # Open house data.
        self.oh_data = {
            "start": "2017-08-06T18:38:39.069638Z",
            "end": "2017-08-06T20:38:39.069638Z"
        }
        self.oh_a = OpenHouse.objects.create(owner=self.user,
                                             kproperty=self.condo,
                                             **self.oh_data)
        self.oh_b = OpenHouse.objects.create(owner=self.user_a,
                                             kproperty=self.house,
                                             **self.oh_data)

        self.condo_oh_path = '/v1/properties/{}/openhouse/{}/'.\
                             format(self.condo.pk, self.oh_a.pk)
        self.house_oh_path = '/v1/properties/{}/openhouses/{}/'.\
                             format(self.house.pk, self.oh_b.pk)
Example #8
0
 def test_transfer_empty_data(self):
     request = APIRequestFactory().post(self.url, self.empty_data)
     object_view = self.object_view.as_view()
     force_authenticate(request, self.sender)
     response = object_view(request)
     self.assertEqual(response.status_code, 400)
Example #9
0
 def test_login_unauthorized(self):
     request = APIRequestFactory().post(self.url, self.invalid_data)
     object_view = self.object_view.as_view()
     response = object_view(request)
     self.assertEqual(response.status_code, 401)
Example #10
0
class ValuesTests(APITestCase):
    redis_instance = redis.Redis(
        host=settings.REDIS_HOST,
        port=settings.REDIS_PORT,
    )
    factory = APIRequestFactory()

    def test_get_all_values(self):
        """
        Check if get data works properly
        """
        self.redis_instance.flushdb()
        self.redis_instance.flushall()

        self.redis_instance.set('name1', 'mumin')

        url = reverse('values')
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.redis_instance.flushdb()
        self.redis_instance.flushall()

    def test_get_specific_values(self):
        """
        Check if get with parameter data works properly
        """
        self.redis_instance.flushdb()
        self.redis_instance.flushall()
        self.redis_instance.set('name1', 'mumin')
        self.redis_instance.set('name2', 'rahman')

        response = self.client.get('/values?keys=name1,name2',
                                   content_type='application/json')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.content_type, "application/json")

        self.redis_instance.flushdb()
        self.redis_instance.flushall()

    def test_get_specific_values_partial(self):
        """
        Check if get with extra parameter works properly
        """
        self.redis_instance.flushdb()
        self.redis_instance.flushall()
        self.redis_instance.set('name1', 'mumin')

        response = self.client.get('/values?keys=name1,name2')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual("application/json", response.content_type)

        self.redis_instance.flushdb()
        self.redis_instance.flushall()

    def test_post_values(self):
        """
        Check if post data works properly
        """
        url = reverse('values')
        data = {'name': 'bristi', 'name3': 'mishu'}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.redis_instance.flushdb()
        self.redis_instance.flushall()

    def test_patch_values(self):
        """
        Check if patch data works properly
        """
        self.redis_instance.flushdb()
        self.redis_instance.flushall()
        self.redis_instance.set('name1', 'mumin')
        url = reverse('values')
        response = self.client.patch(url,
                                     data={"name1": "rinu"},
                                     format="json")

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        self.redis_instance.flushdb()
        self.redis_instance.flushall()
Example #11
0
 def setUp(self):
     self.client = Client()
     self.factory = APIRequestFactory()
 def setUp(self):
     self.factory = APIRequestFactory()
     self.perm_class = CommentPermission()
Example #13
0
def django_request():
    request_factory = APIRequestFactory()
    return request_factory.get("/")
Example #14
0
 def setUp(self):
     self.factory = APIRequestFactory()
     self.new_car = Car.objects.create(make="Opel", model="Vectra")
Example #15
0
 def setUp(self):
     self.factory = APIRequestFactory()
     self.user, _ = get_user_model()._default_manager.get_or_create()
Example #16
0
 def test_user_profile_authorized(self):
     request = APIRequestFactory().get(self.url)
     object_view = self.object_view.as_view()
     force_authenticate(request, self.user)
     response = object_view(request)
     self.assertEqual(response.status_code, 200)
Example #17
0
    def setUp(self):

        self.view = PropertyDetail.as_view()
        self.factory = APIRequestFactory()

        # Condo model owned by user 1.
        self.user = User.objects.create_user(email='*****@*****.**',
                                             password='******')
        condo = Condo.objects.create(owner=self.user,
                                     n_bathrooms=1,
                                     n_bedrooms=2,
                                     price=250000,
                                     sqr_ftg=3000,
                                     unit_num=11,
                                     parking_spaces=1,
                                     corporation_name='Superstar Condos')
        Location.objects.create(kproperty=condo,
                                address='60 Brian Harrison',
                                city="Toronto",
                                country="Canada",
                                province='Ontario',
                                postal_code='M1P0B2',
                                latitude=43.773313,
                                longitude=-79.258729)
        TaxRecords.objects.create(kproperty=condo)
        Historical.objects.create(kproperty=condo,
                                  last_sold_price=2000000,
                                  last_sold_date='2011-08-14',
                                  year_built=2010)
        Features.objects.create(kproperty=condo, feature='Oven')
        Features.objects.create(kproperty=condo, feature='Pool')

        # House model owned by alt user.
        self.user_a = User.objects.create(email='*****@*****.**',
                                          password='******')
        house = House.objects.create(owner=self.user_a,
                                     n_bathrooms=3,
                                     n_bedrooms=3,
                                     price=4500000,
                                     sqr_ftg=4200)
        Location.objects.create(kproperty=house,
                                address='18 Bay Street',
                                city='Toronto',
                                country='Canada',
                                province='Ontario',
                                postal_code='M230B3',
                                latitude=43.773313,
                                longitude=-79.258729)
        TaxRecords.objects.create(kproperty=house,
                                  assessment=4250000,
                                  assessment_year=2016)
        Historical.objects.create(kproperty=house,
                                  last_sold_price=3200500,
                                  last_sold_date='2012-11-03',
                                  year_built=2007)
        Features.objects.create(kproperty=house, feature='House Oven')
        Features.objects.create(kproperty=house, feature='Spa')

        self.condo_id = Condo.objects.all()[0].id
        self.house_id = House.objects.all()[0].id

        self.condo_path = '/v1/properties/' + str(self.condo_id)
        self.house_path = '/v1/properties/' + str(self.house_id)

        self.feature_data = {'feature': 'Test Feature'}
        self.taxrecord_data = {'assessment': 1000, 'assessment_year': 2017}

        self.features_path = self.condo_path + '/features/'
        self.taxrecords_path = self.condo_path + '/taxrecords/'
        self.images_path = self.condo_path + '/images/'
Example #18
0
 def test_user_profile_creation_invalid(self):
     self.user = None
     request = APIRequestFactory().post(self.url, self.invalid_data)
     object_view = self.object_view.as_view()
     response = object_view(request)
     self.assertEqual(response.status_code, 400)
Example #19
0
    def setUp(self):

        features_data = {'feature': 'Oven'}
        tr_data = {'assessment': 120, 'assessment_year': 2017}
        self.nested_views = {
            'features': {
                'view': FeaturesList.as_view(),
                'data': features_data
            },
            'taxrecords': {
                'view': TaxRecordsList.as_view(),
                'data': tr_data
            }
            #'images': {'view': ImagesList.as_view(), 'data': images_data
        }
        self.factory = APIRequestFactory()

        # Test user.
        self.user = User.objects.create_user(email='*****@*****.**',
                                             password='******')
        self.user_alt = User.objects.create(email='*****@*****.**',
                                            password='******')

        # Condo model owned by user 1.
        self.condo = Condo.objects.create(owner=self.user,
                                          n_bathrooms=1,
                                          n_bedrooms=2,
                                          price=250000,
                                          sqr_ftg=3000,
                                          unit_num=11,
                                          parking_spaces=1)
        Location.objects.create(kproperty=self.condo,
                                address='60 Brian Harrison',
                                city="Toronto",
                                country="Canada",
                                province='Ontario',
                                postal_code='M1P0B2',
                                latitude=43.773313,
                                longitude=-79.258729)
        Historical.objects.create(kproperty=self.condo,
                                  last_sold_price=2000000,
                                  last_sold_date='2011-08-14',
                                  year_built=2010)

        # House model owned by alt user.
        self.house = House.objects.create(owner=self.user_alt,
                                          n_bathrooms=3,
                                          n_bedrooms=3,
                                          price=4500000,
                                          sqr_ftg=4200)
        Location.objects.create(kproperty=self.house,
                                address='18 Bay Street',
                                city='Toronto',
                                country='Canada',
                                province='Ontario',
                                postal_code='M230B3',
                                latitude=43.773313,
                                longitude=-79.258729)
        Historical.objects.create(kproperty=self.house,
                                  last_sold_price=3200500,
                                  last_sold_date='2012-11-03',
                                  year_built=2007)

        self.condo_path = '/v1/properties/{}/'.format(self.condo.pk)
        self.house_path = '/v1/properties/{}/'.format(self.house.pk)
Example #20
0
 def test_account_unauthorized(self):
     self.user = None
     request = APIRequestFactory().get(self.url)
     object_view = self.object_view.as_view()
     response = object_view(request)
     self.assertEqual(response.status_code, 401)
Example #21
0
 def setUpClass(cls):
     super(BaseReportViewsTestCase, cls).setUpClass()
     cls.factory = APIRequestFactory()
Example #22
0
 def setUp(self):
     self.author1 = setupUser("cry", "password")
     self.author2 = setupUser("user2", "password")
     self.factory = APIRequestFactory()
     
     self.client.login(username="******", password="******")
 def setUp(self):
     self.factory = APIRequestFactory()
    def setUp(self):
        self.factory = APIRequestFactory()
        self.backend = authentication.JWTAuthentication()

        self.fake_token = b"TokenMcTokenface"
        self.fake_header = b"Bearer " + self.fake_token
Example #25
0
 def setUp(self):
     self.factory = APIRequestFactory()
     self.view = UserTypeViewSet.as_view({'get': 'list'})
     self.uri = '/user/user-type/'
    def setUp(self):
        self.factory = APIRequestFactory()
        self.view_roles = ["ROLE_1"]
        self.view = mock.Mock(permission_roles=self.view_roles)

        self.sca_permission = SCARolePermission()
Example #27
0
 def setUp(self):
     self.request = APIRequestFactory().get('/')
     self.user = user_factory()
    def setUpTestData(cls) -> None:
        super().setUpTestData()

        # Create test factory
        cls.factory = APIRequestFactory()
Example #29
0
 def setUp(self):
     self.request_factory = APIRequestFactory()
     self.request = self.request_factory.get('/')
Example #30
0
    def test_period_not_found(self):
        request = APIRequestFactory().post('', data={'subscriber': '5512345678', 'period': '10-2018'})
        response = self.view(request)

        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual(0, len(response.data))