Skip to content
Permalink
Browse files

bk

  • Loading branch information...
Krocodial
Krocodial committed Sep 11, 2019
1 parent 71b47da commit ff98f70e1fe0a59b64836d8f4bcc8ff265855b7e
@@ -6,6 +6,7 @@


class Migration(migrations.Migration):
atomic = False

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
@@ -568,7 +568,6 @@ def search(request):
advanced = AdvancedSearch(request.GET)
basic = BasicSearch(request.GET)
if advanced.is_valid() and basic.is_valid():
print('valid')
classification = advanced.cleaned_data['classification']
protected_type = advanced.cleaned_data['protected_type']
owner = advanced.cleaned_data['owner']
@@ -586,9 +585,8 @@ def search(request):
if len(owner) == 0:
own = Classification.objects.all()
else:
print(owner)
own = Classification.objects.filter(owner__acronym__in=owner)

if len(state) == 0:
state = ['A', 'P']
queryset = Classification.objects.filter(
@@ -31,6 +31,7 @@ class Meta:

creator,created = User.objects.get_or_create(
username='testoo',
email='testoo@email.com'
)

owner,created = Application.objects.get_or_create(
@@ -48,12 +49,18 @@ class Meta:
class renderTest(TestCase):
def setUp(self):
self.factory = RequestFactory()
self.basic = User.objects.create(username='basic', password='password', is_staff=False)
self.staff = User.objects.create(username='staff', password='password', is_staff=True)
self.supa = User.objects.create_superuser('super', 'xx@xx.com', 'password')
self.basic = User.objects.create(username='basic', email='basic@basic.com', password='password', is_staff=False)
self.staff = User.objects.create(username='staff', email='staff@staff.com', password='password', is_staff=True)
self.supa = User.objects.create_superuser('super', 'supa@supa.com', 'password')
self.anon = AnonymousUser()
self.users = [self.anon, self.basic, self.staff, self.supa]


self.owner = Application.objects.create(
acronym='CLS',
name='CLASSY'
)


self.data = {
'datasource': 'testo',
'schema': 'testo',
@@ -66,9 +73,12 @@ def setUp(self):
'notes': ''
}

for i in range(20):
classy = ClassyFactory.build(creator=self.basic, owner=self.owner)
classy.save(self.basic.pk, self.basic.pk)
self.classy_creator = classy.owner.pk


classy = ClassyFactory.build()
classy.save(1, 1)

def test_index_view(self):
index_request = self.factory.get(reverse('classy:index'))
@@ -90,15 +100,17 @@ def test_index_view(self):
#self.assertRedirects(response, pages[tran[user]], fetch_redirect_response=False)

def test_login_complete_view(self):
for user in self.users:
users = self.users
for user in users:
request = self.factory.get(reverse('classy:login_complete'))
request.user = user
response = login_complete(request)
self.assertEquals(response.status_code, 403)

def test_home_view(self):
response_codes = {self.anon: 302, self.basic: 200, self.staff: 200, self.supa: 200}
for user in self.users:
users = self.users
for user in users:
request = self.factory.get(reverse('classy:home'))
request.user = user
response = home(request)
@@ -107,8 +119,8 @@ def test_home_view(self):
def test_download_view(self):
response_codes_get = {self.anon: 302, self.basic: 302, self.staff: 302, self.supa: 302}
response_codes_post = {self.anon: 302, self.basic: 200, self.staff: 200, self.supa: 200}

for user in self.users:
users = self.users
for user in users:
request = self.factory.get(reverse('classy:download'))
request.user = user
response = download(request)
@@ -156,7 +168,8 @@ def test_review_view(self):

def test_exceptions_view(self):
response_codes = {self.anon: 302, self.basic: 302, self.staff: 200, self.supa: 200}
for user in self.users:
users = self.users
for user in users:
request = self.factory.get(reverse('classy:exceptions'))
request.user = user
response = exceptions(request)
@@ -169,7 +182,8 @@ def test_exceptions_view(self):

def test_log_list_view(self):
response_codes = {self.anon: 302, self.basic: 200, self.staff: 200, self.supa: 200}
for user in self.users:
users = self.users
for user in users:
request = self.factory.get(reverse('classy:log_list'))
request.user = user
response = log_list(request)
@@ -192,10 +206,11 @@ def test_log_detail_view(self):
state='A'
)
rev.save(user=1, approver=1)
d1 = DataAuthorization.objects.create(
d1,created = DataAuthorization.objects.get_or_create(
name='All',
)
for user in self.users:
users = self.users
for user in users:
request = self.factory.get(reverse('classy:log_detail', args=[rev.pk]))
request.user = user
response = log_detail(request, rev.pk)
@@ -216,11 +231,12 @@ def test_modi_view(self):
response_codes_get = {self.anon: 302, self.basic: 302, self.staff: 302, self.supa: 302}
response_codes_post = {self.anon: 302, self.basic: 200, self.staff: 200, self.supa: 200}

d1 = DataAuthorization.objects.create(
d1,created = DataAuthorization.objects.get_or_create(
name='All',
)
data = self.data
for user in self.users:
users = self.users
for user in users:
data['column'] = data['column'] + 'c'
form = ClassificationForm(data)
if form.is_valid():
@@ -274,7 +290,7 @@ def test_modi_view(self):
self.assertEquals(rev.state, 'A')

#Anon does not have profile
if user == self.anon:
if not user.is_active:
continue

user.profile.data_authorizations.add(d1)
@@ -314,19 +330,40 @@ def test_search_view(self):

#classy = ClassyFactory.stub()
#print(vars(classy))

users = self.users

for user in self.users:
for i in range(1):
for user in users:
for i in range(10):
classy = ClassyFactory.stub()
request = self.factory.get(reverse('classy:search'), data=vars(classy))
print(request)
request.user = user
response = search(request)
self.assertEquals(response.status_code, response_codes_get[user])
#print(len(response.content))

for user in users[1:]:
d1,created = DataAuthorization.objects.get_or_create(
name="All",
)
user.profile.data_authorizations.add(d1)
user.save()
user.profile.refresh_from_db()
user.refresh_from_db()

for i in range(10):
classy = ClassyFactory.stub()
request = self.factory.get(reverse('classy:search'), data=vars(classy))
request.user = user
response = search(request)
self.assertEquals(response.status_code, response_codes_get[user])
#print(len(response.content))
classy = ClassyFactory.stub(datasource='', schema='', table='', column='')

def test_uploader_view(self):
response_codes_get = {self.anon: 302, self.basic: 302, self.staff: 200, self.supa: 200}
for user in self.users:
users = self.users
for user in users:
request = self.factory.get(reverse('classy:uploader'))
request.user = user
response = uploader(request)

0 comments on commit ff98f70

Please sign in to comment.
You can’t perform that action at this time.