def setUp_createAccount(self): country = Country(slug='BE', name='Belgium') country.save() member_organisation = MemberOrganisation(name='GS1', slug='gs1', is_active=1, country=country) member_organisation.save() data = { 'uuid': '53900011', 'email': '*****@*****.**', 'company_prefix': '53900011,53900012', 'company_name': 'GS1 Ireland', 'credits': '39:20,43:100,44:100', 'txn_ref': 'Test_1,Test_3,Test_2', 'member_organisation': 'gs1' } url = '/API/v0/AccountCreateOrUpdate/' response = self.client.post(url, data=data) assert response.status_code == 302 self.client.get(response.url) user = User.objects.get(email='*****@*****.**') user.profile.agreed = True user.profile.save() prefix = prefix_service.find_item(user=user, prefix='53900011') assert prefix.prefix == '53900011' prefix_service.make_active(user=user, prefix=prefix.prefix) self.user = user return user
def setUp(self): country, is_created = Country.objects.get_or_create(slug='BE', name='Belgium') member_organisation = MemberOrganisation(name='GS1', slug='gs1', is_active=1, country=country) member_organisation.save()
def setUp(self): country = Country(slug='BE', name='Belgium') country.save() member_organisation = MemberOrganisation(name='GS1IE', slug='gs1ie', is_active=1, country=country) member_organisation.save()
def setUp(self): country = Country(slug='BE', name='Belgium') country.save() member_organisation = MemberOrganisation(name='GS1SE', slug='gs1se', is_active=1, country=country, pk=7) member_organisation.save() PackageLevel.objects.create(id=70, unit_descriptor='test')
def setUp(self): country = Country(slug='BE', name='Belgium') country.save() member_organisation = MemberOrganisation(name='GS1', slug='gs1', is_active=1, country=country) member_organisation.save() response = self.client.post('/API/v1/AccountCreateOrUpdate/', self.post_data) response = self.client.get(response.url) pass
def setUp(self): country = Country(slug='BE', name='Belgium') country.save() member_organisation = MemberOrganisation( name='GS1 Belgium', slug='gs1-belgium', is_active=1, gs1_enable_advanced_dashboard=True, country=country) member_organisation.save() self.user1 = self.setUp_create_user1() self.user2 = self.setUp_create_user2()
class LoginAPITestCase(APITestCase): def setUp(self): country = Country(slug='BE', name='Belgium') country.save() self.member_organisation = MemberOrganisation( name='GS1', slug='gs1', is_active=1, country=country, gs1_prefix_regex='^539|^501|^509|^0\\d\\d') self.member_organisation.save() self.company_orgnisation = CompanyOrganisation.objects.create( **{ 'uuid': '53900011', 'company': 'GS1 Ireland', 'name': 'GS1 Ireland', 'member_organisation': self.member_organisation, 'country': country, }) self.user = User.objects.create_user(username='******', password='******') mo_admin_group = Group.objects.create(name='MO Admins') self.user.groups.add(mo_admin_group) self.member_organisation.add_user(self.user) self.company_orgnisation.add_user(self.user) self.user.profile.company_organisation = self.company_orgnisation self.user.profile.member_organisation = self.member_organisation self.user.profile.save() def test_product_active_prefix(self): generic_data = { 'prefix': '723372372', 'is_suspended': False, 'is_special': '', 'starting_from': '7233723720006', 'company_organisation': self.company_orgnisation, 'member_organisation': self.member_organisation, 'description': 'Some description prefix' } Prefix.objects.create(**generic_data) login_data = {'username': '******', 'password': '******'} client = APIClient() response = client.post(reverse('api:login'), data=login_data) token = response.data['token'] self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) response = self.client.get(reverse('api:packaging-list')) assert response.status_code == 200 assert response.wsgi_request.user.profile.product_active_prefix.prefix == '723372372'
def setUp(self): country = Country(slug='BE', name='Belgium') country.save() member_organisation = MemberOrganisation(name='GS1', slug='gs1', is_active=1, country=country) member_organisation.save() response = self.client.post('/API/v0/AccountCreateOrUpdate/', self.post_data) self.client.get(response.url) self.user = User.objects.get(email='*****@*****.**') assert self.user is not None self.user.profile.agreed = True self.user.profile.save()
def setUp(self): country = Country(slug='BE', name='Belgium', pk=7) country.save() member_organisation = MemberOrganisation(name='GS1SE', slug='gs1se', is_active=1, country=country, pk=7) member_organisation.save() sv = Language.objects.create(slug='sv', name='Swedish') en = Language.objects.create(slug='en', name='English') LanguageByCountry.objects.create(country=country, language=en, default=True) LanguageByCountry.objects.create(country=country, language=sv, default=False) PackageLevel.objects.create(id=70, unit_descriptor='test')
def test_load_templates_gs1ie_command(self): country = Country(slug='IE', name='Ireland') country.save() member_organisation = MemberOrganisation(name='GS1IE', slug='gs1ie', is_active=1, country=country) member_organisation.save() PackageLevel.objects.create(id=60, unit_descriptor='gs1ie-inner-pack') PackageLevel.objects.create(id=50, unit_descriptor='gs1ie-inner-case') PackageLevel.objects.create(id=40, unit_descriptor='gs1ie-display_unit') PackageLevel.objects.create(id=30, unit_descriptor='gs1ie-inner-pallet') PackageType.objects.create(code='AA', type_i18n=json.dumps({'en': 'Type AA'})) PackageType.objects.create(code='AE', type_i18n=json.dumps({'en': 'Type AE'})) PackageType.objects.create(code='AM', type_i18n=json.dumps({'en': 'Type AM'})) self.assertEquals(ProductAttribute.objects.count(), 0) self.assertEquals(ProductTemplate.objects.count(), 0) call_command( 'load_templates_i18n', xlsx_path_mask= 'deployment/test_files/UI_presets_v2_templates_gs1ie_test.xlsx') # count test self.assertEquals(ProductTemplate.objects.count(), 5) self.assertEquals( ProductTemplate.objects.get( name='gs1ie-inner-pack').attributes.all().count(), 41) self.assertEquals( ProductTemplate.objects.get( name='gs1ie-inner-case').attributes.all().count(), 41) self.assertEquals( ProductTemplate.objects.get( name='gs1ie-display-unit').attributes.all().count(), 41) self.assertEquals( ProductTemplate.objects.get( name='gs1ie-inner-pallet').attributes.all().count(), 41) self.assertEquals(ProductPackaging.objects.count(), 3)
class UserTestCase(APITestCase): def setUp(self): country = Country(slug='BE', name='Belgium') country.save() self.member_organisation = MemberOrganisation(name='GS1', slug='gs1', is_active=1, country=country) self.member_organisation.save() self.company_orgnisation = CompanyOrganisation.objects.create( **{ 'uuid': '53900011', 'company': 'GS1 Ireland', 'name': 'GS1 Ireland', 'member_organisation': self.member_organisation, 'country': country, }) self.user = User.objects.create_user(username='******', password='******') self.mo_user = MemberOrganisationUser.objects.create( user=self.user, organization=self.member_organisation, is_admin=True, ) self.company_orgnisation.add_user(self.user) self.profile = self.user.profile self.profile.member_organisation_id = 1 self.profile.save() response = self.client.post(reverse('api:login'), data={ 'username': '******', 'password': '******' }) self.token = response.data['token'] self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token) def test_create_user(self): url = reverse('api:user-create', args=('53900011', )) data = { 'uid': 'abba-123', 'email': '*****@*****.**', 'first_name': 'test_first_name', 'last_name': 'test_last_name' } response = self.client.post(url, data) assert response.status_code == 201, response.data assert response.data['email'] == data['email'] assert response.data['first_name'] == data['first_name'] assert response.data['last_name'] == data['last_name'] def test_create_user_without_uid(self): url = reverse('api:user-create', args=('53900011', )) data = { 'email': '*****@*****.**', 'first_name': 'test_first_name', 'last_name': 'test_last_name' } response = self.client.post(url, data) assert response.status_code == 400 assert response.data['uid'][0] == 'This field is required.' def test_create_user_with_existing_uid(self): url = reverse('api:user-create', args=('53900011', )) # Create user data = { 'uid': 'abba-123', 'email': '*****@*****.**', 'first_name': 'test_first_name', 'last_name': 'test_last_name' } response = self.client.post(url, data) assert response.status_code == 201 # Create User with existing UID data = { 'uid': 'abba-123', 'email': '*****@*****.**', 'first_name': 'duplicate_first_name', 'last_name': 'duplicate_last_name' } response = self.client.post(url, data) assert response.status_code == 400 assert response.data['uid'][ 0] == 'User with this uid already exists', response.data['uid'][0] def test_update_user_with_same_uid_and_email(self): url = reverse('api:user-create', args=('53900011', )) # Create user data = { 'uid': 'abba-123', 'email': '*****@*****.**', 'first_name': 'test_first_name', 'last_name': 'test_last_name' } response = self.client.post(url, data) assert response.status_code == 201 group, created = Group.objects.get_or_create(name='GO Admins') self.user.groups.add(group) data = { 'uid': 'abba-123', 'email': '*****@*****.**', 'first_name': 'duplicate_first_name', 'last_name': 'duplicate_last_name' } url = reverse('api:user-detail', kwargs={'profile__uid': 'abba-123'}) response = self.client.put(url, data) assert response.status_code == 200, response.data def test_create_product_defaults(self): CountryOfOrigin.service.create(code='21', name='BELGIUM') TargetMarket.service.create(code='21', market='BELGIUM') Language.service.create(slug='en', name='English') url = reverse('api:defaults-list') response = self.client.get(url) assert response.status_code == 200 assert response.data['country_of_origin'] == None assert response.data['target_market'] == None assert response.data['language'] == 1